ANN: unicode 0.9.4

2010-02-14 Thread garabik-news-2005-05
unicode is a simple python command line utility that displays 
properties for a given unicode character, or searches 
unicode database for a given name. 

It was written with Linux in mind, but should work almost everywhere 
(including MS Windows and MacOSX), UTF-8 console is recommended. 

The package contains also 'paracode' utility, that exploits the full
power of the Unicode standard to convert the text into vіѕuаllу ѕіmіlаr
ѕtrеаm οf glурhѕ, whіlе uѕіng сοmрlеtеlу dіffеrеnt сοdерοіntѕ. It is an
excellent didactic tool demonstrating the principles and advanced use of
the Unicode standard.

Changes since previous versions: 

* works with new (split) Unihan files

Author: 
Radovan Garabík 

URL: 
http://kassiopeia.juls.savba.sk/~garabik/software/unicode/ 

License: 
GPL

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


moin 1.8.7 released - important security and bug fixes

2010-02-14 Thread Reimar Bauer
MoinMoin 1.8.7 is a security bug fix release.
Please update as soon as possible.

See http://moinmo.in/MoinMoinDownload for the release archive and the
change log.

BTW, we still need much more people helping with cleaning up on
master19.moinmo.in.

So, especially if you speak some non-english language, you can help!

See http://moinmo.in/MoinDev/Translation for details.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Modifying Class Object

2010-02-14 Thread Steve Howell
On Feb 10, 6:16 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:

 Alf, although your English in this forum has been excellent so far, I
 understand you are Norwegian, so it is possible that you aren't a native
 English speaker and possibly unaware that quotation marks are sometimes
 ambiguous in English.

 While it is true that quoted text is officially meant to indicate a
 direct quote, it is also commonly used in informal text to indicate a
 paraphrase. (There are other uses as well, but they don't concern us now.)

 Unfortunately, this means that in informal discussions like this it is
 sometimes difficult to distinguish a direct quote from a paraphrase,
 except by context. In context, as a native speaker, I can assure you that
 Stephen Hansen's use of quotation marks is a paraphrase and not meant to
 be read as a direct quote.

As another native speaker of English, I can assure Alf that using
quotation marks in a paraphrase in written English is actually
strictly admonished against in some English speaking countries.  At
least according to my English teachers.  To the extent that many
people on the Internet don't speak English natively, I think the most
conservative and reasonable convention applies--use quotes to quote
directly; if you're not quoting directly, omit quotes and make clear
the fact that you are paraphrasing.

Which isn't to say we don't all make mistakes.

I have no idea about what Stephen Hanson said.  Most misattributions
are actually paraphrases, whether they be in quotes or not.

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


Re: Modifying Class Object

2010-02-14 Thread Stephen Hansen
On Sat, Feb 13, 2010 at 7:59 AM, Michael Sparks spark...@gmail.com wrote:

 Hi Alf,


 On Feb 12, 8:22 pm, Alf P. Steinbach al...@start.no wrote:
  Thanks for the effort at non-flaming discussion, it *is*
  appreciated.

 I would appreciate it if you tried to be non-flaming yourself,
 since you can see I am not flaming you.


I'm currently in a self-imposed exile from commenting on any particular
details of the technical issue in this thread as I believe it futile, but I
have to say: wow, kudos to you for putting SO much into saying what I tried
to say, and doing so better then I was able to.

Kudos. Times two.

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


Re: Modifying Class Object

2010-02-14 Thread Stephen Hansen
On Sun, Feb 14, 2010 at 12:15 AM, Steve Howell showel...@yahoo.com wrote:

 On Feb 10, 6:16 am, Steven D'Aprano st...@remove-this-
 cybersource.com.au wrote:
 
  Alf, although your English in this forum has been excellent so far, I
  understand you are Norwegian, so it is possible that you aren't a native
  English speaker and possibly unaware that quotation marks are sometimes
  ambiguous in English.
 
  While it is true that quoted text is officially meant to indicate a
  direct quote, it is also commonly used in informal text to indicate a
  paraphrase. (There are other uses as well, but they don't concern us
 now.)
 
  Unfortunately, this means that in informal discussions like this it is
  sometimes difficult to distinguish a direct quote from a paraphrase,
  except by context. In context, as a native speaker, I can assure you that
  Stephen Hansen's use of quotation marks is a paraphrase and not meant to
  be read as a direct quote.

 As another native speaker of English, I can assure Alf that using
 quotation marks in a paraphrase in written English is actually
 strictly admonished against in some English speaking countries.  At
 least according to my English teachers.  To the extent that many
 people on the Internet don't speak English natively, I think the most
 conservative and reasonable convention applies--use quotes to quote
 directly; if you're not quoting directly, omit quotes and make clear
 the fact that you are paraphrasing.

 Which isn't to say we don't all make mistakes.

 I have no idea about what Stephen Hanson said.  Most misattributions
 are actually paraphrases, whether they be in quotes or not.



Well, no, I have to stand in my defense at this point. Given the context of
the communication medium, an actual quote  has IMHO a clearly defined
context. It is lines, unchanged and unedited, prepended with a certain
appropriate set of characters, and clearly cited with some variation of
something like On date, Someone said:

A quote, in context, is an attempt to directly reference another
individual's words as they spoke them.

Any alteration of such words, any adjustment of such words to your own end,
is dishonest.

What I did was say something like this paragraph (with no quote characters
before it):

   And then you hand-waved my arguments with a response of, this that blah
bleh

Minus the indention.

There was IMHO, NO misattribution, NO reasonable assumption that I specified
actual or explicit words of Alf or anyone else. There MAY be an argument
someone can make claiming my statement wasn't clear, but to declare it is a
deliberate /lie/ is another thing entirely.

There is a difference between using quote marks and making an actual
quotation-- a quotation requires a citation-- and in informal discourse use
of quote marks to represent clear paraphrasing of the interpretation of
position is valid, imho. In a formal paper or thesis, I'd use a different
format. But this is not formal. In context that statement can not possibly
be reasonable considered an actual quotation, even with quote marks.

And I'm responding because: yes, I'm finding this You are a liar. response
particularly personally offensive. I should get over it. I'm just used to
people disagreeing with me. Dismissing me as a liar is something new.

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


Re: plugin / intra process communication system

2010-02-14 Thread Paul Kölle

Am 13.02.2010 10:50, schrieb Florian Ludwig:

Hi,

I'm looking for a module/plugin/intra-process-communication/hook system
for python. Maybe someone here could point me to some project I missed
or might have some good ideas if I end up implementing it myself.

Most systems I have found are one to many communications but I would
like many to many, to clarify what I mean an *example* use-case:

 Lets say you program a wiki and like to allow different kind of
 authentications. So you create two plugins (for example one for
 OpenID and one for Shibboleth).

 Some time later you feel like reinventing the wheel again and
 you program a blog. Again you like to allow different ways of
 authentication and you already wrote plugins for exactly the
 same for your wiki, right?

With most systems now some trouble begins - the blog software would need
to have the interface/extention-points/however-you-name-it that the wiki
software defined.

The plugins you wrote probably import them from the wiki module directly
which means your blog would depend on the wiki. (?!) So where to put the
interface/[...] definition that is imported by those plugins? Create a
package/module just containing the interface? This really get
troublesome if different people wrote the wiki, the blog and another
third one a plugin.
If you are talking about code sharing you can move the common code out 
of your applications in a seperate namespace. If you follow the model 
trac is using you would install a module/package/egg with the basic 
functionality of the pluginsystem (i.e. what's in core.py and env.py + 
logging and whatever you think is necessary).
All shared code like your auth-plugins would go in a common plugin 
directory to which you can refer via PYTHONPATH.


Another common technique is chaining of WSGI middleware..., check out 
pythonpaste.org.


Then there is SOA where functionality is shared via RPC/webservices and 
wsdl/uddi. But my feeling is this is mostly used in Enterprise 
applications and is best used in Java/.NET where you already have 
libraries doing all the XML stuff.


hth
 Paul




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


Re: Hashing in python

2010-02-14 Thread Martin v. Loewis
 floor(x) returns an integer

Why do you say that? Assuming you are talking about math.floor, it works
differently for me:

py math.floor(10.0/3)
3.0

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


problem with floats and calculations

2010-02-14 Thread Karsten Goen
hey all,
I got a problem with floats and calculations. I made an mini-application
where you get random questions with some science calculations in it
So the user can type in his result with the values given by random creation.
And the user value is compared against the computer value... the problem is
that the user input is only 2 numbers behind the '.' so like 1.42, 1.75

here is the example:
http://dpaste.com/hold/158698/

without decimal it would be very inaccurate. decimal is very accurate when I
have to compare d with users calculations from a,b,c,var.
But when I ask the user what is a the result gets inaccurate when
calculating with the same values given before (b,c,d,var).

Maybe anyone can help me with this problem, I don't want to generate for
every possible user input a single formula. And also it should be possible
for a computer, my calculator at home does the same and is much smaller and
slower.

thx in advance

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


Re: Hashing in python

2010-02-14 Thread Martin v. Loewis
 CELL_SIZE = 4
 
 def key(point):
 
 return (
 int((floor(point[0]/CELL_SIZE))*CELL_SIZE),
 int((floor(point[1]/CELL_SIZE))*CELL_SIZE),
 int((floor(point[2]/CELL_SIZE))*CELL_SIZE)
 )
 
 
 Since python allows keys to be tuples, I think that this should work.
 Is there a better (more efficient) way to do it?

You don't say why you want to do hashing in the first place. If it is to
access elements in a lookup table, and you are now using a dictionary,
I'd suggest to replace that with a list. For 4x4x4 elements, you could
either do

table[int(point[0]/CELL_SIZE)][int(point[1]/CELL_SIZE)][int(point[2]/CELL_SIZE)]

(i.e. have nested lists), or you allocate a list of 64 elements, and use

def key(point):
  return 16*int(point[0]/CELL_SIZE) + 4*int(point[1]/CELL_SIZE) +\
int(point[2]/CELL_SIZE)

table[key(point)]

You could even use that key function as a key to a dictionary, if you
can't use lists for some reason.

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


Re: problem with floats and calculations

2010-02-14 Thread Stefan Krah
Karsten Goen karsten.g...@googlemail.com wrote:
 hey all,
 I got a problem with floats and calculations. I made an mini-application where
 you get random questions with some science calculations in it
 So the user can type in his result with the values given by random creation.
 And the user value is compared against the computer value... the problem is
 that the user input is only 2 numbers behind the '.' so like 1.42, 1.75
 
 here is the example:
 http://dpaste.com/hold/158698/
 
 without decimal it would be very inaccurate. decimal is very accurate when I
 have to compare d with users calculations from a,b,c,var.
 But when I ask the user what is a the result gets inaccurate when 
 calculating
 with the same values given before (b,c,d,var).
 
 Maybe anyone can help me with this problem, I don't want to generate for every
 possible user input a single formula. And also it should be possible for a
 computer, my calculator at home does the same and is much smaller and slower.

d = (a * b)/ (c * var)
d = Decimal(d).quantize(Decimal('0.01'))

By quantizing d, the above equality does not hold any longer. You've got
to drop that line (your calculator doesn't quantize either).


Stefan Krah


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


Re: problem with floats and calculations

2010-02-14 Thread Karsten Goen
also this doesn't help, there are still errors in the accuracy. Isn't there
a perfect way to do such calculations?

Karsten Goen karsten.g...@googlemail.com wrote:
  hey all,
  I got a problem with floats and calculations. I made an mini-application
 where
  you get random questions with some science calculations in it
  So the user can type in his result with the values given by random
 creation.
  And the user value is compared against the computer value... the problem
 is
  that the user input is only 2 numbers behind the '.' so like 1.42, 1.75
 
  here is the example:
  http://dpaste.com/hold/158698/
 
  without decimal it would be very inaccurate. decimal is very accurate
 when I
  have to compare d with users calculations from a,b,c,var.
  But when I ask the user what is a the result gets inaccurate when
 calculating
  with the same values given before (b,c,d,var).
 
  Maybe anyone can help me with this problem, I don't want to generate for
 every
  possible user input a single formula. And also it should be possible for
 a
  computer, my calculator at home does the same and is much smaller and
 slower.

 d = (a * b)/ (c * var)
 d = Decimal(d).quantize(Decimal('0.01'))

 By quantizing d, the above equality does not hold any longer. You've got
 to drop that line (your calculator doesn't quantize either).


 Stefan Krah

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


Re: MemoryError, can I use more?

2010-02-14 Thread Laszlo Nagy

2010.02.13. 17:40 keltezéssel, Diez B. Roggisch írta:

Am 13.02.10 17:18, schrieb Anssi Saari:

Nobodynob...@nowhere.com  writes:

A single process can't use much more than 2GiB of RAM without a 
64-bit CPU

and OS.


That's not really true. Even Windows XP has the /3GB boot option to
allow 3 GiB per process. On PCs, free operating systems and server
Windows can use PAE to give access to full 4 GB per process.


No, PAE can be used to access much more memory than 4GB - albeit 
through paging. AFAIK up to 2^36 Bytes.
PAE is for the kernel. Yes, you can use much more memory with 32 bit 
kernel + PAE. But the ~3G per 32bit process limit still applies. It is 
because the PAE extension allows the kernel to distribute the same 
virtual address ranges between different processes, but map them to 
different physical memory addresses. However, the process that was 
compiled and is running in 32 bit mode, cannot access more than ~3GB 
simply because it is not able to address more memory locations with 32 
bit addresses. (minus ~1G is because it needs virtual addresses for I/O 
devices as well, and those addresses cannot be mapped to physical memory).


So with any Python that is running in 32 bit mode, you cannot use more 
than ~3G memory. But you can start many instances of those programs and 
use 2G for each process.


   L

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


Re: problem with floats and calculations

2010-02-14 Thread Mark Lawrence

[fix top posting]

Karsten Goen karsten.g...@googlemail.com wrote:

hey all,
I got a problem with floats and calculations. I made an mini-application

where

you get random questions with some science calculations in it
So the user can type in his result with the values given by random

creation.

And the user value is compared against the computer value... the problem

is

that the user input is only 2 numbers behind the '.' so like 1.42, 1.75

here is the example:
http://dpaste.com/hold/158698/

without decimal it would be very inaccurate. decimal is very accurate

when I

have to compare d with users calculations from a,b,c,var.
But when I ask the user what is a the result gets inaccurate when

calculating

with the same values given before (b,c,d,var).

Maybe anyone can help me with this problem, I don't want to generate for

every

possible user input a single formula. And also it should be possible for

a

computer, my calculator at home does the same and is much smaller and

slower.

d = (a * b)/ (c * var)
d = Decimal(d).quantize(Decimal('0.01'))

By quantizing d, the above equality does not hold any longer. You've got
to drop that line (your calculator doesn't quantize either).


Stefan Krah





Karsten Goen wrote:
 also this doesn't help, there are still errors in the accuracy. Isn't 
there

 a perfect way to do such calculations?


Please read the following and see if it helps.  Also search the python 
users mailing list for something like floating point accuracy, you'll 
get plenty of hits.


http://docs.python.org/tutorial/floatingpoint.html

Regards.

Mark Lawrence

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


Re: problem with floats and calculations

2010-02-14 Thread Stefan Krah
Karsten Goen karsten.g...@googlemail.com wrote:
 also this doesn't help, there are still errors in the accuracy. Isn't there a
 perfect way to do such calculations?

The hint I gave you removes the most egregious error in your program.
You still have to quantize the result of (c*var*d) / b) if you want
it to match a. If I adapt your program, I don't find any non-matching
numbers.

for i in range(10):
# set random numbers
a = Decimal(str(random.uniform(0.1,123))).quantize(Decimal('0.01'))
b = Decimal(str(random.uniform(20.1,3000))).quantize(Decimal('0.01'))
c = Decimal(str(random.uniform(100, 5000))).quantize(Decimal('0.01'))
var = Decimal('8.314').quantize(Decimal('0.01'))
# calc d
d = (a * b)/ (c * var)
if ((c*var*d) / b).quantize(Decimal('0.01')) != a:
print a, (c*var*d) / b


Note that for perfect accuracy you should use the fraction module.


Stefan Krah


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


How to solve an LCP (linear complementarity problem) in python ?

2010-02-14 Thread abent
Is there a good library to numericly solve an LCP in python ?
(http://en.wikipedia.org/wiki/Linear_complementarity_problem)

An example would be very helpful because most libraries seem to only
solve QP's.
I need this for computing 2d contact forces in a rigid body
simulation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plugin / intra process communication system

2010-02-14 Thread Florian Ludwig
On Sun, 2010-02-14 at 10:16 +0100, Paul Kölle wrote: 
 Am 13.02.2010 10:50, schrieb Florian Ludwig:
  Hi,
 
  I'm looking for a module/plugin/intra-process-communication/hook system
  for python. Maybe someone here could point me to some project I missed
  or might have some good ideas if I end up implementing it myself.
 
  [...]
  
  The plugins you wrote probably import them from the wiki module directly
  which means your blog would depend on the wiki. (?!) So where to put the
  interface/[...] definition that is imported by those plugins? Create a
  package/module just containing the interface? This really get
  troublesome if different people wrote the wiki, the blog and another
  third one a plugin.

 If you are talking about code sharing you can move the common code out 
 of your applications in a seperate namespace. If you follow the model 
 trac is using you would install a module/package/egg with the basic 
 functionality of the pluginsystem (i.e. what's in core.py and env.py + 
 logging and whatever you think is necessary).

 All shared code like your auth-plugins would go in a common plugin 
 directory to which you can refer via PYTHONPATH.

You're right, its about code sharing/reusing - should have said it more
clearly. What I am looking for is the pluginsystem that makes this easy.
Here there problem with the trac (and other plugin systems I've seen)
approach:

You need to define something like:
|
| class IAuthPlugin(Interface): [...]
|
in your blog software.

Now within the open_id_login_plugin:
| from blog import IAuthPlugin
|
| class OpenIdPlugin(object):
| implements(IAuthPlugin)
|

So the OpenIdPlugin is specific for the blog and hardly sharable.
Actually it is but it depends on the blog as it gets imported.

This might be thought of as an implementation detail but its seems
pretty common.


 Another common technique is chaining of WSGI middleware..., check out 
 pythonpaste.org.

WSGI middleware just doesn't do it in some situations. Also it only
works out for web-based applications (my example was one but my question
was more general).


Thanks for your answer,
Florian



-- 
Florian Ludwig d...@phidev.org


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


LaTeX parser and pstricks generator in python

2010-02-14 Thread Laurent Claessens
Hi all.

I just put online a first version of two tools that combine LaTeX and
python.

The first one, phystricks[1], is a python module intended to generate
pstricks code. The main features are
* you don't have to know pstricks (but you need to have some basics in
python)
* you have python instead of LaTeX as backend programming language
* the bounding box is automatically computed
* thanks to Sage[5], you have a direct access to the derivative of
functions (and much more). Thus, for example, tangent and normal
vectors to any (cartesian/polar/parametric) plots are easy to draw.
* eps export is possible in order to be more pdfLaTeX friendly.

The documentation[3] contains many examples of figures created with
phystricks. Download the file phystricks-doc.pdf[4]

In a somewhat near future, I plan to add interaction with LaTeX :
reading the .aux file, I can import the values of LaTeX's counters in
python. You should be able to draw a line whose angular coefficient is
the number of the last equation ;)
That feature should also improve the computation of the bounding box
in taking into account the LaTeX labels that one put in the picture.

That lead me to the second tool I put online ...

The second, LaTeXparser[2], is a simple LaTeXparser in python. Given a
tex file, the features are
* answer to the questions : what are the defined macros ? among of
them, which are actually used ? with what arguments ?
* substitute \input{...} by the content of the file
* read the .aux file and take information about the values \label and
\ref


Every comments (and patches) are much welcome !

Have a good day
Laurent


[1] http://www.gitorious.org/phystricks
[2] http://www.gitorious.org/latexparser
[3] http://www.gitorious.org/phystricks-doc
[4] http://www.gitorious.org/phystricks-doc/phystricks-doc/trees/master
[5] http://sagemath.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with QtSignals object has no attribute 'emit'

2010-02-14 Thread News123
Hi,

I'm having a rather small code snippet, where I create pyQT signals.
I manage creating a signal as class attribute,
but I can't create a list of signals or a signal
as object.member.


 from PyQt4.QtGui import *
 from PyQt4.QtCore import *
 
 class MyWin(QMainWindow):
 clssig = pyqtSignal()
 sigarr   = [ pyqtSignal() ]
 def emit_them(self):
 self.objsig = pyqtSignal()
 self.clssig.emit()# works
 self.sigarr[0].emit()  # fails 
 self.objsig.emit()  # fails
 
 if __name__ == __main__:
 app = QApplication(sys.argv)
 win = MyWin()
 win.show()
 win.emit_them()
 sys.exit(app.exec_())

The two lines marked with fails will fail with following error:
 AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit'

The QT documentation states:
New signals should only be defined in sub-classes of QObject.

I guess, that his is the reason. though I don't know enough about PyQT
to understand the magic behind.


Now my question:

How could I create an array of signals if I wished to?

I can work aroud it, but would be curious.


Thanks for shadng some light on this (for me surprising) issue.


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


Re: How to solve an LCP (linear complementarity problem) in python ?

2010-02-14 Thread Helmut Jarausch
On 02/14/10 12:52, abent wrote:
 Is there a good library to numericly solve an LCP in python ?
 (http://en.wikipedia.org/wiki/Linear_complementarity_problem)
 
 An example would be very helpful because most libraries seem to only
 solve QP's.
 I need this for computing 2d contact forces in a rigid body
 simulation.

Sorry, I can't help you except pointing you to
the Complementarity Problem Net

http://www.cs.wisc.edu/cpnet/

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with QtSignals object has no attribute 'emit'

2010-02-14 Thread Phil Thompson
On Sun, 14 Feb 2010 13:17:40 +0100, News123 news...@free.fr wrote:
 Hi,
 
 I'm having a rather small code snippet, where I create pyQT signals.
 I manage creating a signal as class attribute,
 but I can't create a list of signals or a signal
 as object.member.
 
 
 from PyQt4.QtGui import *
 from PyQt4.QtCore import *
 
 class MyWin(QMainWindow):
 clssig = pyqtSignal()
 sigarr   = [ pyqtSignal() ]
 def emit_them(self):
 self.objsig = pyqtSignal()
 self.clssig.emit()# works
 self.sigarr[0].emit()  # fails 
 self.objsig.emit()  # fails
 
 if __name__ == __main__:
 app = QApplication(sys.argv)
 win = MyWin()
 win.show()
 win.emit_them()
 sys.exit(app.exec_())
 
 The two lines marked with fails will fail with following error:
 AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit'
 
 The QT documentation states:
 New signals should only be defined in sub-classes of QObject.
 
 I guess, that his is the reason. though I don't know enough about PyQT
 to understand the magic behind.
 
 
 Now my question:
 
 How could I create an array of signals if I wished to?
 
 I can work aroud it, but would be curious.
 
 
 Thanks for shadng some light on this (for me surprising) issue.

You can't create an array of signals.

Signals are defined to both Python and C++. This is done when the class is
defined by introspecting the class attributes - but it doesn't look for
signals any deeper than that, i.e. it won't look into your sigarr list.

Even if it did, there is a second issue. Signals have unbound and bound
versions (much like unbound and bound methods). The class attribute is an
unbound signal that is a descriptor that will return the bound signal. It
is the bound signal that implements the emit() method. It would be possible
for an unbound signal's __call__ method to also return a bound signal so
that you could do something like...

self.sigarr[0](self).emit()

...but I can't think of a valid use case.

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


Re: Modifying Class Object

2010-02-14 Thread Steven D'Aprano
On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote:

 The term pointer is very abstract.  Please give me a concrete
 definition of a pointer.

A programming language data type whose value directly specifies (or 
points to) another value which is stored elsewhere in the computer 
memory.

I quote from Wikipedia:

http://en.wikipedia.org/wiki/Pointer_(computing)

[quote]
A pointer is a simple, less abstracted implementation of the 
more abstracted reference data type
[end quote]

And later:

[quote]
While pointer has been used to refer to references in 
general, it more properly applies to data structures whose 
interface explicitly allows the pointer to be manipulated
(arithmetically via pointer arithmetic) as a memory 
address...
[end quote]

And again:

[quote]
A memory pointer (or just pointer) is a primitive, the value 
of which is intended to be used as a memory address; it is said 
that a pointer points to a memory address. It is also said that
a pointer points to a datum [in memory] when the pointer's value
is the datum's memory address.

More generally, a pointer is a kind of reference, and it is said 
that a pointer references a datum stored somewhere in memory; to
obtain that datum is to dereference the pointer. The feature that
separates pointers from other kinds of reference is that a 
pointer's value is meant to be interpreted as a memory address, 
which is a rather 'low-level' concept.
[end quote]


 A curly brace is one of these: { }
 
 Pretty concrete, I hope.

But { and } are glyphs in some typeface. Chances are that what you see, 
and what I see, are quite different, and whatever pixels we see, the 
compiler sees something radically different: two abstract characters 
implemented in some concrete fashion, but that concrete fashion is a mere 
implementation detail. They could be implemented as bytes x7b and x7d, or 
as four-byte sequences x007b and x007d for UTF-32, or who knows 
what in some other system. So the *concrete* representation of the curly 
brace varies according to the system.

From that, it's not a difficult leap to say that Pascal's BEGIN and END 
key words are mere alternate spellings of the abstract open curly brace 
and close curly brace with different concrete representations, and from 
that it's a small step to say that the INDENT and DEDENT tokens seen by 
the Python compiler (but absent from Python source code!) are too.


 But reference also has a concrete meaning: C++ has a type explicitly
 called reference:

 http://en.wikipedia.org/wiki/Reference_(C++)


 Of course, reference has concrete meanings in specific contexts. But I
 can refer you to much more general and abstract uses of the term
 reference.  Do you want references?   I will be happy to refer you to
 appropriate references.

I know that reference can also be used in the abstract. I'm just warning 
that it can also be used in the concrete, and so we need to be wary of 
misunderstandings and confusions.


 And of course call-by-reference (or pass-by-reference) has a specific,
 technical meaning.


 Which is what?

http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference



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


Python Optimization

2010-02-14 Thread mukesh tiwari
Hello everyone. I am new to python and previously i did programming in
c/c++.Could some one please help me to improve the run time for this
python program as i don't have idea how to optimized this code.This
code also seems to be more unpythonic so how to make it look like more
pythonic . I am trying for this problem(https://www.spoj.pl/problems/
FACT1/).
Thank you

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__=Mukesh Tiwari
__date__ =$Feb 10, 2010 1:35:26 AM$


import random
from Queue import Queue


def gcd(a,b):
while b:
a,b=b,a%b
return a

def rabin_miller(p,t=1):
if(p2):
return False
if(p!=2 and p%2==0):
return False
s=p-1
while(s%2==0):
s=1
for i in xrange(t):
a=random.randrange(p-1)+1
temp=s
mod=pow(a,temp,p)
while(temp!=p-1 and mod!=1 and mod!=p-1):
mod=(mod*mod)%p
temp=temp*2
if(mod!=p-1 and temp%2==0):
return False
return True
def brent(n):
if(n%2==0):
return 2;
 
x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n)
y,r,q=x,1,1
g,ys=0,0
while(True):
x=y
for i in range(r):
y,k=(y*y+c)%n,0
while(True):
ys=y
for i in range(min(m,r-k)):
y,q=(y*y+c)%n,q*abs(x-y)%n
g,k=gcd(q,n),k+m
if(k= r or g1):break
r=2*r
if(g1):break
if(g==n):
while(True):
ys,g=(x*x+c)%n,gcd(abs(x-ys),n)
if(g1):break
return g


def factor(n):
Q_1,Q_2=Queue(),[]
Q_1.put(n)
while(not Q_1.empty()):
l=Q_1.get()
if(rabin_miller(l)):
Q_2.append(l)
continue
d=brent(l)
if(d==l):Q_1.put(l)
else:
Q_1.put(d)
Q_1.put(l/d)
return Q_2



if __name__ == __main__:
while(True):
n=int(raw_input())
if(n==0):break
L=factor(n)
L.sort()
#print L
i=0
s=
while(ilen(L)):
cnt=L.count(L[i])
#print %d^%d%(L[i],cnt)
s+=str(L[i])+^+str(cnt)+ 
i+=cnt
print s[:-1]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Optimization

2010-02-14 Thread Mark Lawrence

mukesh tiwari wrote:

Hello everyone. I am new to python and previously i did programming in
c/c++.Could some one please help me to improve the run time for this
python program as i don't have idea how to optimized this code.This
code also seems to be more unpythonic so how to make it look like more
pythonic . I am trying for this problem(https://www.spoj.pl/problems/
FACT1/).
Thank you

# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__=Mukesh Tiwari
__date__ =$Feb 10, 2010 1:35:26 AM$


import random
from Queue import Queue


def gcd(a,b):
while b:
a,b=b,a%b
return a

def rabin_miller(p,t=1):
if(p2):
return False
if(p!=2 and p%2==0):
return False
s=p-1
while(s%2==0):
s=1
for i in xrange(t):
a=random.randrange(p-1)+1
temp=s
mod=pow(a,temp,p)
while(temp!=p-1 and mod!=1 and mod!=p-1):
mod=(mod*mod)%p
temp=temp*2
if(mod!=p-1 and temp%2==0):
return False
return True
def brent(n):
if(n%2==0):
return 2;
 
x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n)

y,r,q=x,1,1
g,ys=0,0
while(True):
x=y
for i in range(r):
y,k=(y*y+c)%n,0
while(True):
ys=y
for i in range(min(m,r-k)):
y,q=(y*y+c)%n,q*abs(x-y)%n
g,k=gcd(q,n),k+m
if(k= r or g1):break
r=2*r
if(g1):break
if(g==n):
while(True):
ys,g=(x*x+c)%n,gcd(abs(x-ys),n)
if(g1):break
return g


def factor(n):
Q_1,Q_2=Queue(),[]
Q_1.put(n)
while(not Q_1.empty()):
l=Q_1.get()
if(rabin_miller(l)):
Q_2.append(l)
continue
d=brent(l)
if(d==l):Q_1.put(l)
else:
Q_1.put(d)
Q_1.put(l/d)
return Q_2



if __name__ == __main__:
while(True):
n=int(raw_input())
if(n==0):break
L=factor(n)
L.sort()
#print L
i=0
s=
while(ilen(L)):
cnt=L.count(L[i])
#print %d^%d%(L[i],cnt)
s+=str(L[i])+^+str(cnt)+ 
i+=cnt
print s[:-1]


A good starting point is 
http://wiki.python.org/moin/PythonSpeed/PerformanceTips


HTH.

Mark Lawrence

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


Re: Hashing in python

2010-02-14 Thread MRAB

Martin v. Loewis wrote:

floor(x) returns an integer


Why do you say that? Assuming you are talking about math.floor, it works
differently for me:

py math.floor(10.0/3)
3.0


I've just double-checked. It returns a float in Python 2.x and an int in
Python 3.x. (I recently switched to Python 3.1.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: plugin / intra process communication system

2010-02-14 Thread Diez B. Roggisch

Am 14.02.10 13:05, schrieb Florian Ludwig:

On Sun, 2010-02-14 at 10:16 +0100, Paul Kölle wrote:

Am 13.02.2010 10:50, schrieb Florian Ludwig:

Hi,

I'm looking for a module/plugin/intra-process-communication/hook system
for python. Maybe someone here could point me to some project I missed
or might have some good ideas if I end up implementing it myself.

[...]

The plugins you wrote probably import them from the wiki module directly
which means your blog would depend on the wiki. (?!) So where to put the
interface/[...] definition that is imported by those plugins? Create a
package/module just containing the interface? This really get
troublesome if different people wrote the wiki, the blog and another
third one a plugin.



If you are talking about code sharing you can move the common code out
of your applications in a seperate namespace. If you follow the model
trac is using you would install a module/package/egg with the basic
functionality of the pluginsystem (i.e. what's in core.py and env.py +
logging and whatever you think is necessary).



All shared code like your auth-plugins would go in a common plugin
directory to which you can refer via PYTHONPATH.


You're right, its about code sharing/reusing - should have said it more
clearly. What I am looking for is the pluginsystem that makes this easy.
Here there problem with the trac (and other plugin systems I've seen)
approach:

You need to define something like:
|
| class IAuthPlugin(Interface): [...]
|
in your blog software.


Why? Any reason you can't define it in a separate package the 
blog-software depends on, as well as your wiki?



And then of course, this is not really needed. In Python, behavior 
counts, not type-information. So you can get away without any explicit 
declared interface. You might chose to not do that, for aestetic 
reasons, or better documentation. But you aren't forced.


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


Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 4:53 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com
wrote:
 Hello everyone. I am new to python and previously i did programming in
 c/c++.Could some one please help me to improve the run time for this
 python program as i don't have idea how to optimized this code.
 [...]

How much of a speedup do you need?  Are we talking about orders of
magnitude (in which case you might want to consider using something
like the Multiple Polynomial Quadratic Sieve method instead, or as
well), or just a few percent?

(1) Have you profiled the code to see where it's spending most of its
time?  This is an essential first step.

(2) Obvious things: use range rather than xrange in your loops.  Make
sure that all heavily used variables/functions are local to the
function you're using them in.  E.g., you use range, min and abs in
the middle of the 'brent' function.  Instead, start the brent function
by setting _abs, _range, _min = abs, range, min, and then use _abs,
_range, etc. instead.  Lookups of local variables are faster than
globals.

(3) In the inner loop:

for i in range(min(m,r-k)):
y,q=(y*y+c)%n,q*abs(x-y)%n

you can get probably rid of the abs call.  It *might* also help to
avoid the tuple packing/unpacking (but see (1)).  You could try doing
a couple of steps at a time instead of one (i.e., unroll the loop a
little bit);  one advantage is that you probably don't need to bother
reducing q modulo n at every step;  every other step would be good
enough.  Depending on the relative speed of multiplication and
reduction, and the sizes of the integers involved, this might save
time.

(4) Have you tried using Montgomery reduction in the Brent method?
The inner loop of that method involves two reductions modulo n, which
may well be where the biggest bottleneck is.  But see (1). The other
obvious bottleneck is the gcd method;  if profiling shows that that's
the case, there might be ways to speed that up, too.  (E.g., use a
binary gcd algorithm, or use Lehmer's method.)

Good luck!
--
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-14 Thread Steve Howell
On Feb 14, 7:11 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote:
  The term pointer is very abstract.  Please give me a concrete
  definition of a pointer.

 A programming language data type whose value directly specifies (or
 points to) another value which is stored elsewhere in the computer
 memory.

 I quote from Wikipedia:

 http://en.wikipedia.org/wiki/Pointer_(computing)

     [quote]
     A pointer is a simple, less abstracted implementation of the
     more abstracted reference data type
     [end quote]

 And later:

     [quote]
     While pointer has been used to refer to references in
     general, it more properly applies to data structures whose
     interface explicitly allows the pointer to be manipulated
     (arithmetically via pointer arithmetic) as a memory
     address...
     [end quote]

 And again:

     [quote]
     A memory pointer (or just pointer) is a primitive, the value
     of which is intended to be used as a memory address; it is said
     that a pointer points to a memory address. It is also said that
     a pointer points to a datum [in memory] when the pointer's value
     is the datum's memory address.

     More generally, a pointer is a kind of reference, and it is said
     that a pointer references a datum stored somewhere in memory; to
     obtain that datum is to dereference the pointer. The feature that
     separates pointers from other kinds of reference is that a
     pointer's value is meant to be interpreted as a memory address,
     which is a rather 'low-level' concept.
     [end quote]

  A curly brace is one of these: { }

  Pretty concrete, I hope.

 But { and } are glyphs in some typeface. Chances are that what you see,
 and what I see, are quite different, and whatever pixels we see, the
 compiler sees something radically different: two abstract characters
 implemented in some concrete fashion, but that concrete fashion is a mere
 implementation detail. They could be implemented as bytes x7b and x7d, or
 as four-byte sequences x007b and x007d for UTF-32, or who knows
 what in some other system. So the *concrete* representation of the curly
 brace varies according to the system.

 From that, it's not a difficult leap to say that Pascal's BEGIN and END
 key words are mere alternate spellings of the abstract open curly brace
 and close curly brace with different concrete representations, and from
 that it's a small step to say that the INDENT and DEDENT tokens seen by
 the Python compiler (but absent from Python source code!) are too.


Thanks.  It's a useful analogy; I think I understand your point
better.  I've been bouncing around between Python and Javascript a lot
lately, so your analogy resonates with me.  There are many times when
I find myself simply respelling things like begin/end, and those
respellings to me almost make me think of Python and Javascript as
different dialects of an underlying language.  Of course, there are
other places where the languages differ more substantively, too.

Going back to pointers vs. references, I think the key distinction
being made is that pointers allow specific memory manipulation,
although I think even there you're really just dealing with
abstractions.  The address 0x78F394D2 is a little bit closer to the
machine than, say, the 42nd element of a Python list, but they are
both just abstractions on top of underlying machines, whether the
machines are virtual, electronic circuits, vacuum tubes, whatever.
You can add 6 to 42 and get the 48th object, but its Python's
convention not to call the 48th object a memory address or expose a
reference to it as a pointer.  If I want to pass along the reference
to the 48th element of a list as the slot to be updated (i.e. with the
intention to actually mutate the list itself), then I need a tuple
like (lst, 48).

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


Comparing file last access date

2010-02-14 Thread kak...@gmail.com
Hi to all,
what i want is to search a folder, and if the last access date of the
files in that folder is greater than, lets say 7 days, those files
deleted. (Somekind of a file cleaner script)
I had problems with converting

now = today = datetime.date.today()
and
stats = os.stat(file)
lastAccessDate = time.localtime(stats[7])

into matching formats so that
 if (now - lastAccessDate)  7:
 delete the file

what i do wrong
Thanks in advance
Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Optimization

2010-02-14 Thread Aahz
In article 363498c7-3575-4f1e-ad53-d9cd10c8d...@q16g2000yqq.googlegroups.com,
Mark Dickinson  dicki...@gmail.com wrote:

(2) Obvious things: use range rather than xrange in your loops.  

Um, what?  You meant the reverse, surely?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparing file last access date

2010-02-14 Thread MRAB

kak...@gmail.com wrote:

Hi to all,
what i want is to search a folder, and if the last access date of the
files in that folder is greater than, lets say 7 days, those files
deleted. (Somekind of a file cleaner script)
I had problems with converting

now = today = datetime.date.today()
and
stats = os.stat(file)
lastAccessDate = time.localtime(stats[7])

into matching formats so that
 if (now - lastAccessDate)  7:
 delete the file

what i do wrong
Thanks in advance
Antonis


I would use:

seven_days = 7 * 24 * 60 * 60 # 7 days in seconds

now = time.time() # in seconds since Epoch

...

last_access = os.path.getatime(path) # in seconds since Epoch
if now - last_access  seven_days:
os.remove(path)
--
http://mail.python.org/mailman/listinfo/python-list


Re: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5

2010-02-14 Thread Aahz
In article 7a9d26a8-0a9f-4bf3-bf50-0ac5e337f...@r24g2000yqd.googlegroups.com,
seth  hkla...@gmail.com wrote:

We have a code that creates a simple Python shelve database. We are
able to serialize objects and store them in the dbm file. This seem to
work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6,
but on Os X 10.5 with Python 2.5 the database filename is changed by
the operating system by attaching the .db extension to it. Does an one
know why is that?

Nope -- any reason you can't change the filename?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with MemoryError

2010-02-14 Thread Steve Holden
rantingrick wrote:
 On Feb 12, 4:10 pm, Steve Holden st...@holdenweb.com wrote:
 Antoine Pitrou wrote:
 Le Fri, 12 Feb 2010 17:14:57 +, Steven D'Aprano a écrit :
 
 On Feb 12, 4:10 pm, Steve Holden st...@holdenweb.com wrote:
 Antoine Pitrou wrote:
 Le Fri, 12 Feb 2010 17:14:57 +, Steven D'Aprano a écrit :
 
 Steve,
 Why do so many of your posts come in as doubles and triples. Is this a
 case of studdering click finger of some fault of your newsreader?
 
 -- concerned fellow pythonista...

I suspect it's because I am being insufficiently disciplined about using
reply instead of reply all. On gmane they only appear once, so I
suspect some other component of the mail/news loop is less assiduous
about de-duping the content.

How do you read the list?

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Python Optimization

2010-02-14 Thread Steve Howell
On Feb 14, 9:48 am, Mark Dickinson dicki...@gmail.com wrote:
 On Feb 14, 4:53 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com
 wrote:

  Hello everyone. I am new to python and previously i did programming in
  c/c++.Could some one please help me to improve the run time for this
  python program as i don't have idea how to optimized this code.
  [...]

 How much of a speedup do you need?  Are we talking about orders of
 magnitude (in which case you might want to consider using something
 like the Multiple Polynomial Quadratic Sieve method instead, or as
 well), or just a few percent?

 (1) Have you profiled the code to see where it's spending most of its
 time?  This is an essential first step.


I ditto the profiling recommendation.

http://docs.python.org/library/profile.html

It might also be useful to time your algorithm for n=10, 100, 1000,
1, etc., to get a better sense of how the overall algorithm
behaves.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with MemoryError

2010-02-14 Thread Steve Howell
On Feb 14, 10:32 am, Steve Holden st...@holdenweb.com wrote:
 rantingrick wrote:
  On Feb 12, 4:10 pm, Steve Holden st...@holdenweb.com wrote:
  Antoine Pitrou wrote:
  Le Fri, 12 Feb 2010 17:14:57 +, Steven D'Aprano a écrit :

  On Feb 12, 4:10 pm, Steve Holden st...@holdenweb.com wrote:
  Antoine Pitrou wrote:
  Le Fri, 12 Feb 2010 17:14:57 +, Steven D'Aprano a écrit :

  Steve,
  Why do so many of your posts come in as doubles and triples. Is this a
  case of studdering click finger of some fault of your newsreader?

  -- concerned fellow pythonista...

 I suspect it's because I am being insufficiently disciplined about using
 reply instead of reply all. On gmane they only appear once, so I
 suspect some other component of the mail/news loop is less assiduous
 about de-duping the content.

 How do you read the list?


Hi Steve, I mostly read the list through Google groups, and I have
seen occasional dups from you.  Of course, the readers themselves
could be a little smarter about recognizing duplication, but that does
not appear to be the case with Google.  On the other hand, I am not
seeing dups from you in a quick skim of this thread, so I wonder if it
just takes Google a little while to weed out the dups.

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


Re: Please help with MemoryError

2010-02-14 Thread Steve Howell
On Feb 11, 5:50 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote:
  My Python program now consumes over 2 GB of memory and then I get a
  MemoryError.  I know I am reading lots of files into memory, but not 2GB
  worth.

  2.    When do I need
  to manually allocate/deallocate memory and when can I trust Python to
  take care of it?

 You never need to manually allocate memory.

 You *may* need to deallocate memory if you make reference loops, where
 one object refers to itself:

 l = []  # make an empty list
 l.append(l)  # add the list l to itself

 Python can break such simple reference loops itself, but for more
 complicated ones, you may need to break them yourself:

 a = []
 b = {2: a}
 c = (None, b)
 d = [1, 'z', c]
 a.append(d)  # a reference loop

 Python will deallocate objects when they are no longer in use. They are
 always considered in use any time you have them assigned to a name, or in
 a list or dict or other structure which is in use.

 You can explicitly remove a name with the del command. For example:

 x = ['my', 'data']
 del x

 After deleting the name x, the list object itself is no longer in use
 anywhere and Python will deallocate it. But consider:

 x = ['my', 'data']
 y = x  # y now refers to THE SAME list object
 del x

 Although you have deleted the name x, the list object is still bound to
 the name y, and so Python will *not* deallocate the list.

 Likewise:

 x = ['my', 'data']
 y = [None, 1, x, 'hello world']
 del x

 Although now the list isn't bound to a name, it is inside another list,
 and so Python will not deallocate it.


Another technique that comes up some time is that you have a list of
objects that you are processing:

x = [obj1, obj2, obj3, obj4]

When you are done processing obj1, you want to remove the reference to
it, but you do not necessarily want to change the list itself.  You
can break the reference by saying x[0] = None when you are done
handling obj1.  Of course, if you can avoid creating the list in the
first place, as some people have suggested, then you really get a
savings.

The setting-to-None technique is also occasionally useful with
objects, where you can say foo.bar = None when you are done with bar
but not with foo.  Of course, the need to use such a technique often
points out a deeper code smell with Foo itself, but I've seen it come
up.

Steven's examples of a reference loop are deliberately simplified, of
course, but the chain of references in a real world program can get
quite long, and there's often great savings to be reaped if you can
break the keystone reference, so to speak.  In other words, breaking
just one reference often allows other references to fall down like
dominos.

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



Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 6:03 pm, a...@pythoncraft.com (Aahz) wrote:
 In article 
 363498c7-3575-4f1e-ad53-d9cd10c8d...@q16g2000yqq.googlegroups.com,
 Mark Dickinson  dicki...@gmail.com wrote:

 (2) Obvious things: use range rather than xrange in your loops.  

 Um, what?  You meant the reverse, surely?

Er, yes I did.  Thanks!

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


Re: Python Optimization

2010-02-14 Thread Mark Dickinson
On Feb 14, 4:53 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com
wrote:
 Hello everyone. I am new to python and previously i did programming in
 c/c++.Could some one please help me to improve the run time for this
 python program as i don't have idea how to optimized this code.This
 code also seems to be more unpythonic so how to make it look like more
 pythonic . I am trying for this problem(https://www.spoj.pl/problems/
 FACT1/).
 Thank you

One other thing:  in the 'brent' function, you're setting m to
randrange(1, n).  What's the purpose of this?  It looks to me as
though m controls the number of Pollard-Rho iterations that are
clumped together at one time (before doing a gcd operation), and using
a random number for this doesn't make a lot of sense to me.

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


Re: Python Optimization

2010-02-14 Thread Steve Howell
On Feb 14, 11:52 am, Mark Dickinson dicki...@gmail.com wrote:
 On Feb 14, 4:53 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com
 wrote:

  Hello everyone. I am new to python and previously i did programming in
  c/c++.Could some one please help me to improve the run time for this
  python program as i don't have idea how to optimized this code.This
  code also seems to be more unpythonic so how to make it look like more
  pythonic . I am trying for this problem(https://www.spoj.pl/problems/
  FACT1/).
  Thank you

 One other thing:  in the 'brent' function, you're setting m to
 randrange(1, n).  What's the purpose of this?  It looks to me as
 though m controls the number of Pollard-Rho iterations that are
 clumped together at one time (before doing a gcd operation), and using
 a random number for this doesn't make a lot of sense to me.


The randomness also makes the algorithm a little buggy.

I tried this input:

37^5 41^5

Usually I get the right answer.  Other times I get this:

37^5 41^3 1681^1

And occasionally it appears to get into an infinite loop, which
definitely could be a cause of slowness. :)


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


Fighting with subprocess.Popen

2010-02-14 Thread Mr.John
I'm using Python 2.6.2 as packaged with Fedora 12. I'm trying to use
subprocess.Popen() to call /usr/bin/pactl, a simple PulseAudio command
parser.

I'm having a hard time, because it only works part of the time. If pactl
gets a blank or invalid command, it says No valid command specified., and
this is what prints to stderr most of the time. I can get the result of
pactl list, but anything else I try returns No valid command specified.
So, pactl is getting called, but my args are disappearing somewhere. But not
every time...

Below is a test case that demonstrates this. Tests 1  2 concatenate the
command and the argument, Tests 3  4 mimic the python docs and use the form
Popen([mycmd, myarg], ...), which never seems to work.

import subprocess

list = 'list'
list_sinks = 'list-sinks'

print(### TEST 1)
a = subprocess.Popen('pactl ' + list, shell=True, stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print(### TEST 2)
a = subprocess.Popen('pactl ' + list_sinks, shell=True,
stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print(### TEST 3)
a = subprocess.Popen(['pactl', list], shell=True, stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))

print(### TEST 4)
a = subprocess.Popen(['pactl', list_sinks], shell=True,
stdout=subprocess.PIPE)
res = a.communicate()
print(repr(res[0]))
### TEST 1
(success... snip)
### TEST 2
No valid command specified.
''
### TEST 3
No valid command specified.
''
### TEST 4
No valid command specified.
''

Does anyone have any idea what I'm doing wrong?
Thanks,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent of Ruby's Pathname?

2010-02-14 Thread Aahz
In article 8fc356e0-f3ed-4a67-9b37-f21561cef...@p13g2000pre.googlegroups.com,
Sean DiZazzo  half.ital...@gmail.com wrote:
On Feb 8, 2:36=A0pm, a...@pythoncraft.com (Aahz) wrote:
 In article dcace5fc-5ae9-4756-942d-6da7da2f6...@s36g2000prh.googlegroups=
.com,
 Sean DiZazzo =A0half.ital...@gmail.com wrote:

Why did Path() get rejected? Is it the idea itself, or just the
approach that was used? What are the complaints?

 You should search for the discussiona around it.

I read the discussion, and there was definitely some going back and
forth on whether it should be sub-classed from string, but the
conversation just seemed to stop abruptly with no decision one way of
the other.  Maybe I missed a thread.

I guess being dropped without a final go-ahead is just as good as a
formal no anyway.

Not quite: because it was not rejected, someone who wants to shepherd the
process forward would likely be welcomed (even if it ends up with formal
rejection).  I suggest starting by writing your own summary of the
previous discussion and see if the people involved agree that your
summary is reasonably accurate.  Also check to see if the original PEP
writer wants to be involved or whether zie is willing to have you take
over.

Another good (and related) starting point would be to create a reasoning
favoring one side or the other that was not brought up in previous
discussion.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fighting with subprocess.Popen

2010-02-14 Thread Christian Heimes
Mr.John wrote:
 Below is a test case that demonstrates this. Tests 1  2 concatenate the
 command and the argument, Tests 3  4 mimic the python docs and use the form
 Popen([mycmd, myarg], ...), which never seems to work.

It doesn't work with shell=True because the shell is not able to
interpret the list form. It's recommended that you don't use shell=True
unless you need a shell.

Christian

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


Re: python crash on windows but not on linux

2010-02-14 Thread Roel Schroeven
Op 2010-02-13 13:14, Alf P. Steinbach schreef:
 * hjebbers:
 I enlarged the windows page file from 750Kb to 1.5Gb .
 The crash still happens.
 btw, the crash does not happen at a peak memory usage.
 According to windows task manager, at the moment of crash mem usage of
 my program is 669kb, peak memory usage is 1.136kb

 henk-jan
 
 Probably you meant to write M, not k or K?
 
 I've never managed to make much sense of the displays in Windows' Task 
 Manager, 
 if that's what you're using, but I think the mem usage it's displaying by 
 default is the process' working set, or something very similar to that 
 measure.
 
 You can display additional columns in Task Manager, and one useful one is how 
 much virtual memory is allocated,.
 
 And perhaps then (if that's not what you're looking it already) it'll be 
 closer 
 to 2 GiB?

Note that the memory measurements in Task Manager are pretty limited
and. Comparing Task Manager and Process Explorer:

Task Manager - Process Explorer
Mem Usage - Working Set
VM Size - Private Bytes
n/a - Virtual Size

I tend to trust Process Explorer a lot more than Task Manager. Note that
what Task Manager calls VM Size is not the size of the virtual memory as
might be expected (if Process Explorer is to be trusted), and that Task
Manager doesn't show the virtual memory size (at least on Windows XP).

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

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


Re: Function attributes [OT]

2010-02-14 Thread Terry Reedy

On 2/13/2010 8:14 AM, Steve Holden wrote:


Gmane is primarily a news (NNTP-based) service, though for reasons best
know to the organizers they choose to rename the standard newsgroups to
fit their own idea of how the universe should be organized, so there the
group becomes gmane.comp.python.general.


As I understand the site, the last I read a year or two ago, gmane is a 
technical mailinglist-to-news gateway. It does not mirror newsgroups, 
standard or not. It only mirrors lists such as python-list, not 
newsgroups, such comp.lang.python. In doing so, it organizes the lists 
into categories like g.comp.python, which has about 200 subgroups 
mirroring 200 python lists.


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


Re: Function attributes [OT]

2010-02-14 Thread Steve Holden
Terry Reedy wrote:
 On 2/13/2010 8:14 AM, Steve Holden wrote:
 
 Gmane is primarily a news (NNTP-based) service, though for reasons best
 know to the organizers they choose to rename the standard newsgroups to
 fit their own idea of how the universe should be organized, so there the
 group becomes gmane.comp.python.general.
 
 As I understand the site, the last I read a year or two ago, gmane is a
 technical mailinglist-to-news gateway. It does not mirror newsgroups,
 standard or not. It only mirrors lists such as python-list, not
 newsgroups, such comp.lang.python. In doing so, it organizes the lists
 into categories like g.comp.python, which has about 200 subgroups
 mirroring 200 python lists.
 
That would make more sense. I know that the python.org infrastructure
acts as a gateway between the mailing list and the newsgroup.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: MemoryError, can I use more?

2010-02-14 Thread Ross Ridge
Diez B. Roggisch de...@nospam.web.de writes:
 No, PAE can be used to access much more memory than 4GB - albeit
 through paging. AFAIK up to 2^36 Bytes.

Anssi Saari  a...@sci.fi wrote:
That too. I admit, after checking, that you can't go above 3 GiB per
process even in server Windows. But for Linux there exists (or
existed, since it seems it hasn't been updated since 2004) a kernel
patch which provides a 4GB/4GB address split. Kernel is in one
segment, userland in another and hence a process can access full 4GB.

Windows has a similar feature that allows 32-bit applications running on
64-bit versions of Windows to have a nearly 4Gb virtual address space.
Windows also allows 32-bit applications to use more than 4GB of physical
memory through a paging mechanism called Address Windowing Extensions.
Also 32-bit applications can effectively use more than 4GB of RAM through
indirect means like multiple processes, the disk cache or video card RAM.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  rri...@csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


new python install

2010-02-14 Thread monkeys paw

Upon invoking python, it hangs
until Ctrl^C is typed, and then the
 interactive shell begins.

Like so:

joemoney% python
Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5
Type help, copyright, credits or license for more information.
# Hangs ^^^ at this point until ^C is typed
^C




I've seen this in other new installs and wondered if there is
a common problem that would cause this? It's on a sun os box
--
http://mail.python.org/mailman/listinfo/python-list


Re: MemoryError, can I use more?

2010-02-14 Thread Diez B. Roggisch

Am 14.02.10 12:28, schrieb Laszlo Nagy:

2010.02.13. 17:40 keltezéssel, Diez B. Roggisch írta:

Am 13.02.10 17:18, schrieb Anssi Saari:

Nobodynob...@nowhere.com writes:


A single process can't use much more than 2GiB of RAM without a
64-bit CPU
and OS.


That's not really true. Even Windows XP has the /3GB boot option to
allow 3 GiB per process. On PCs, free operating systems and server
Windows can use PAE to give access to full 4 GB per process.


No, PAE can be used to access much more memory than 4GB - albeit
through paging. AFAIK up to 2^36 Bytes.

PAE is for the kernel. Yes, you can use much more memory with 32 bit
kernel + PAE. But the ~3G per 32bit process limit still applies. It is
because the PAE extension allows the kernel to distribute the same
virtual address ranges between different processes, but map them to
different physical memory addresses. However, the process that was
compiled and is running in 32 bit mode, cannot access more than ~3GB
simply because it is not able to address more memory locations with 32
bit addresses. (minus ~1G is because it needs virtual addresses for I/O
devices as well, and those addresses cannot be mapped to physical memory).


No. It can access more, through paging, similar like mmap. Specialized 
software like databases do that to keep large data in memory. And this 
has nothing to do with compilation.


Of course this doesn't help for python, at least not for python-objects, 
as these need a flat memory model. But it's not true that only the 
kernels benefit from the PAE.


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


Re: Modifying Class Object

2010-02-14 Thread Ethan Furman

Steve Howell wrote:

On Feb 14, 7:11 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:


On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote:


The term pointer is very abstract.  Please give me a concrete
definition of a pointer.


A programming language data type whose value directly specifies (or
points to) another value which is stored elsewhere in the computer
memory.

I quote from Wikipedia:

http://en.wikipedia.org/wiki/Pointer_(computing)

   [quote]
   A pointer is a simple, less abstracted implementation of the
   more abstracted reference data type
   [end quote]

And later:

   [quote]
   While pointer has been used to refer to references in
   general, it more properly applies to data structures whose
   interface explicitly allows the pointer to be manipulated
   (arithmetically via pointer arithmetic) as a memory
   address...
   [end quote]

And again:

   [quote]
   A memory pointer (or just pointer) is a primitive, the value
   of which is intended to be used as a memory address; it is said
   that a pointer points to a memory address. It is also said that
   a pointer points to a datum [in memory] when the pointer's value
   is the datum's memory address.

   More generally, a pointer is a kind of reference, and it is said
   that a pointer references a datum stored somewhere in memory; to
   obtain that datum is to dereference the pointer. The feature that
   separates pointers from other kinds of reference is that a
   pointer's value is meant to be interpreted as a memory address,
   which is a rather 'low-level' concept.
   [end quote]



A curly brace is one of these: { }



Pretty concrete, I hope.


But { and } are glyphs in some typeface. Chances are that what you see,
and what I see, are quite different, and whatever pixels we see, the
compiler sees something radically different: two abstract characters
implemented in some concrete fashion, but that concrete fashion is a mere
implementation detail. They could be implemented as bytes x7b and x7d, or
as four-byte sequences x007b and x007d for UTF-32, or who knows
what in some other system. So the *concrete* representation of the curly
brace varies according to the system.

From that, it's not a difficult leap to say that Pascal's BEGIN and END
key words are mere alternate spellings of the abstract open curly brace
and close curly brace with different concrete representations, and from
that it's a small step to say that the INDENT and DEDENT tokens seen by
the Python compiler (but absent from Python source code!) are too.




Thanks.  It's a useful analogy; I think I understand your point
better.  I've been bouncing around between Python and Javascript a lot
lately, so your analogy resonates with me.  There are many times when
I find myself simply respelling things like begin/end, and those
respellings to me almost make me think of Python and Javascript as
different dialects of an underlying language.  Of course, there are
other places where the languages differ more substantively, too.

Going back to pointers vs. references, I think the key distinction
being made is that pointers allow specific memory manipulation,
although I think even there you're really just dealing with
abstractions.  The address 0x78F394D2 is a little bit closer to the
machine than, say, the 42nd element of a Python list, but they are
both just abstractions on top of underlying machines, whether the
machines are virtual, electronic circuits, vacuum tubes, whatever.
You can add 6 to 42 and get the 48th object, but its Python's
convention not to call the 48th object a memory address or expose a
reference to it as a pointer.  If I want to pass along the reference
to the 48th element of a list as the slot to be updated (i.e. with the
intention to actually mutate the list itself), then I need a tuple
like (lst, 48).



I think that's the key right there -- if 48 was really a pointer, you 
wouldn't need to pass lst in as 48 would in fact be the memory address 
of the object you wanted to manipulate.


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


FW: MemoryError, can I use more?

2010-02-14 Thread Echavarria Gregory, Maria Angelica

I use the physical and kernel memory boxes in the windows task manager under 
the performance tab... in that way I can see the exact RAM that just OS and 
idle processes occupy before I run my app, and then also the limit at which my 
app pushes the memory...


M. Angelica Echavarria-Gregory, M.Sc., E.I.
Ph.D Candidate
University of Miami
Phone 305 284-3611

From: sstein...@gmail.com [sstein...@gmail.com]
Sent: Friday, February 12, 2010 7:58 PM
To: Echavarria Gregory, Maria Angelica
Cc: python-list@python.org
Subject: Re: MemoryError, can I use more?

On Feb 12, 2010, at 7:21 PM, Echavarria Gregory, Maria Angelica wrote:

 Dear group:

 I am developing a program using Python 2.5.4 in windows 32 OS. The amount of 
 data it works with is huge. I have managed to keep memory footprint low, but 
 have found that, independent of the physical RAM of the machine, python 
 always gives the MemoryError message when it has occupied exactly only 2.2 
 GB. I have tested this in 4 different machines, all with memory of 3 to 4 
 GB... I'm amazed.

 Could any of you please help me to figure out how to change that limit? I 
 typed help(MemoryError) and it is a class itself, but that help told me 
 nothing I can use...

How are you determining that it has occupied exactly only 2.2GB?

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


FW: MemoryError, can I use more?

2010-02-14 Thread Echavarria Gregory, Maria Angelica

Dear Chris,

One of the machines I tested my app in is 64 bit and happened the same. The RAM 
consumed by the OS and other processes is already included in the 2.2 I'm 
telling... my app enters to work when the RAM is already consumed in ~600 MB in 
the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that 
it started a little bit higher because it has windows 7... so should I 
understand that there is nothing I can do for my app to use up more RAM?

Thanks for your time and answer,
Angelica.


M. Angelica Echavarria-Gregory, M.Sc., E.I.
Ph.D Candidate
University of Miami
Phone 305 284-3611


From: Chris Kaynor [ckay...@zindagigames.com]
Sent: Friday, February 12, 2010 7:44 PM
To: Echavarria Gregory, Maria Angelica
Cc: python-list@python.org
Subject: Re: MemoryError, can I use more?

A 32 bit app can only use 4 GB of memory itself (regardless of the amount of 
system ram), the OS claims some of this for the system, dlls occupy some of it, 
etc. As such, the app can only really use a smaller subset (generally between 2 
to 3 GB, depending upon the app and the OS).

Chris


On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica 
m.echavarriagreg...@umiami.edumailto:m.echavarriagreg...@umiami.edu wrote:
Dear group:

I am developing a program using Python 2.5.4 in windows 32 OS. The amount of 
data it works with is huge. I have managed to keep memory footprint low, but 
have found that, independent of the physical RAM of the machine, python always 
gives the MemoryError message when it has occupied exactly only 2.2 GB. I have 
tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed.

Could any of you please help me to figure out how to change that limit? I typed 
help(MemoryError) and it is a class itself, but that help told me nothing I can 
use...

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

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


Re: Modifying Class Object

2010-02-14 Thread Alf P. Steinbach

* Ethan Furman:

Steve Howell wrote:


Going back to pointers vs. references, I think the key distinction
being made is that pointers allow specific memory manipulation,
although I think even there you're really just dealing with
abstractions.  The address 0x78F394D2 is a little bit closer to the
machine than, say, the 42nd element of a Python list, but they are
both just abstractions on top of underlying machines, whether the
machines are virtual, electronic circuits, vacuum tubes, whatever.
You can add 6 to 42 and get the 48th object, but its Python's
convention not to call the 48th object a memory address or expose a
reference to it as a pointer.  If I want to pass along the reference
to the 48th element of a list as the slot to be updated (i.e. with the
intention to actually mutate the list itself), then I need a tuple
like (lst, 48).



I think that's the key right there -- if 48 was really a pointer, you 
wouldn't need to pass lst in as 48 would in fact be the memory address 
of the object you wanted to manipulate.


The generalization is known as a based pointer.

Except where it's a fundamental abstraction in a programming language, where it 
might be called anything.


For example, in C++ some so called member pointers are logically based 
pointers. They have pointer syntax (as do C++ iterators, which are not 
necessarily pointers), but member pointers are not pointers in the C++ 
standard's sense; in particular, dereferencing a C++ member pointer yields a 
typeless entity, which is not the case for a normal pointer, although that 
standard confusingly calls also member pointers pointers in some places, and in 
other places uses the pointer term only about basic pointers.


So, delving into the details of that terminology means traveling into a pretty 
chaotic territory. But on the other hand, going for the more abstract it gets 
cleaner and simpler. The Wikipedia article is about in the middle somewhere.


It is perhaps not confusing that it is confusing to many. :-)


Cheers  hth.,

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


Re: MemoryError, can I use more?

2010-02-14 Thread Tommy Grav

On Feb 14, 2010, at 7:20 PM, Echavarria Gregory, Maria Angelica wrote:

 
 Dear Chris,
 
 One of the machines I tested my app in is 64 bit and happened the same. The 
 RAM consumed by the OS and other processes is already included in the 2.2 I'm 
 telling... my app enters to work when the RAM is already consumed in ~600 MB 
 in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only 
 that it started a little bit higher because it has windows 7... so should I 
 understand that there is nothing I can do for my app to use up more RAM?

It is not just the machine. If your python is compiled as 32bit then it will be 
limited to 2GB.
To use more you have to use a 64 bit python on a 64 bit machine. 

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


Re: new python install

2010-02-14 Thread Tim Chase

monkeys paw wrote:

Upon invoking python, it hangs
until Ctrl^C is typed, and then the
  interactive shell begins.

Like so:

joemoney% python
Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5
Type help, copyright, credits or license for more information.
# Hangs ^^^ at this point until ^C is typed
^C

 

I've seen this in other new installs and wondered if there is
a common problem that would cause this? It's on a sun os box


Though I've never seen such live, perhaps you have some sort of 
site-wide or user-specific config file such as ~/.pythonrc.py or 
a site-wide site.py file.  You can read up a bit at


  http://docs.python.org/library/site.html
  http://docs.python.org/library/user.html

I believe the way to test this is to start Python with either the 
-s or -S option (or both) to disable looking for user or site 
modules.  Also check if you have some crazy value set for 
$PYTHONSTARTUP.


  http://docs.python.org/using/cmdline.html#cmdoption-S

My guess is that something in one of these places is triggering 
the hang until you kill that with a ^C after which you get the 
requested prompt.


Hope this helps,

-tkc


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


Re: MemoryError, can I use more?

2010-02-14 Thread Dave Angel

Echavarria Gregory, Maria Angelica wrote:

Dear Chris,

One of the machines I tested my app in is 64 bit and happened the same. The RAM 
consumed by the OS and other processes is already included in the 2.2 I'm 
telling... my app enters to work when the RAM is already consumed in ~600 MB in 
the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that 
it started a little bit higher because it has windows 7... so should I 
understand that there is nothing I can do for my app to use up more RAM?

Thanks for your time and answer,
Angelica.


M. Angelica Echavarria-Gregory, M.Sc., E.I.
Ph.D Candidate
University of Miami
Phone 305 284-3611


From: Chris Kaynor [ckay...@zindagigames.com]
Sent: Friday, February 12, 2010 7:44 PM
To: Echavarria Gregory, Maria Angelica
Cc: python-list@python.org
Subject: Re: MemoryError, can I use more?

A 32 bit app can only use 4 GB of memory itself (regardless of the amount of 
system ram), the OS claims some of this for the system, dlls occupy some of it, 
etc. As such, the app can only really use a smaller subset (generally between 2 
to 3 GB, depending upon the app and the OS).

Chris


On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica 
m.echavarriagreg...@umiami.edumailto:m.echavarriagreg...@umiami.edu wrote:
Dear group:

I am developing a program using Python 2.5.4 in windows 32 OS. The amount of 
data it works with is huge. I have managed to keep memory footprint low, but 
have found that, independent of the physical RAM of the machine, python always 
gives the MemoryError message when it has occupied exactly only 2.2 GB. I have 
tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed.

Could any of you please help me to figure out how to change that limit? I typed 
help(MemoryError) and it is a class itself, but that help told me nothing I can 
use...

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


  
There are three different limits at play here.  Since you're still not 
saying how you're measuring usage, we've all been guessing just which 
one you're hitting.  There's physical RAM, virtual address space, and 
swappable space (swapfile on disk).  Each reaches some limit in 
different ways.


And there are probably a dozen different ways to measure memory use,  
that get a dozen different answers.  If you say which one you're using, 
that gives exactly 2.2 GB,  maybe someone will be familiar with that 
particular approach, and its meaning.


DaveA

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


Re: MemoryError, can I use more?

2010-02-14 Thread Tommy Grav

On Feb 14, 2010, at 10:16 PM, Dave Angel wrote:

 There are three different limits at play here.  Since you're still not saying 
 how you're measuring usage, we've all been guessing just which one you're 
 hitting.  There's physical RAM, virtual address space, and swappable space 
 (swapfile on disk).  Each reaches some limit in different ways.
 
 And there are probably a dozen different ways to measure memory use,  that 
 get a dozen different answers.  If you say which one you're using, that gives 
 exactly 2.2 GB,  maybe someone will be familiar with that particular 
 approach, and its meaning.

I ran into the same problem on Mac OS X and investigated it. My problem was 
that the program reached a memory error
after using 2.2GB of memory. Now what caused it specifically I am less sure of, 
but switching to a 64bit python on 
a 64bit OS (snow leopard) means that I now frequently move past this boundary 
(when I have enough memory of course :)

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


[issue7926] Stray parentheses() in context manager what's new doc

2010-02-14 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Fixed in r78182.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7926
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7927] SSL socket is not closed properly

2010-02-14 Thread Péter Szabó

New submission from Péter Szabó pts...@gmail.com:

Here is how to reproduce:

import socket
import ssl
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sslsock = ssl.SSLSocket(sock)
assert sslsock._sslobj is None
sslsock.connect(('www.gmail.com', 443))
assert isinstance(sslsock._sslobj, socket._ssl.SSLType)
assert 0 == sslsock._makefile_refs
sslsock.makefile().close()
assert 1 == sslsock._makefile_refs  # Should be 0.
assert sslsock._sslobj is not None  # Should be None.

I think the problem is in SSLSocket.makefile, which initializes the _fileobject 
with close=False by default.

--
components: Library (Lib)
messages: 99339
nosy: Péter.Szabó
severity: normal
status: open
title: SSL socket is not closed properly
type: resource usage
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7927
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7928] String formatting: grammar wrongly limits [index] to integer

2010-02-14 Thread Edward Welbourne

New submission from Edward Welbourne e...@chaos.org.uk:

http://docs.python.org/library/string.html#formatstrings
field_name::=  (identifier | integer) (. attribute_name | [ 
element_index ])*
element_index ::= integer

Subsequent text indicates __getitem__() is used but does not overtly say that a 
string can be used; but
http://docs.python.org/whatsnew/2.6.html#pep-3101-advanced-string-formatting
gives the example
 'Content-type: {0[.mp4]}'.format(mimetypes.types_map)
and clearly '.mp4' is passed to __getitem__(); a string, not an integer.

Clearly one of these is wrong !
Given that the what's new doc goes into some detail about how the content of 
[...] gets parsed, I'm guessing it's right and the grammar is wrong.

--
assignee: georg.brandl
components: Documentation
messages: 99340
nosy: eddy, georg.brandl
severity: normal
status: open
title: String formatting: grammar wrongly limits [index] to integer
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7928
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7926] Stray parentheses() in context manager what's new doc

2010-02-14 Thread Edward Welbourne

Edward Welbourne e...@chaos.org.uk added the comment:

The third change removes the early uses of object from:
quote Finally, the closing(object)() function returns object so that it can 
be bound to a variable, and calls object.close at the end of the block. /quote
leaving the last use (object.close) as a dangling reference.
So either revert this part of the fix and change :func:`closing(object)` to 
just ``closing(object)`` or follow up the present change by changing quote 
and calls :meth `object.close` at the end /quote to q and calls the 
argument's :meth:`close` method at the end /q

--
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7926
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7923] StreamHandler and FileHandler located in logging, not in logging.handlers

2010-02-14 Thread Vinay Sajip

Vinay Sajip vinay_sa...@yahoo.co.uk added the comment:

These changes have already been made in trunk (see r68624, r76869), just not 
backported to release26-maint.

--
resolution:  - wont fix
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7923
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7928] String formatting: grammar wrongly limits [index] to integer

2010-02-14 Thread Georg Brandl

Changes by Georg Brandl ge...@python.org:


--
assignee: georg.brandl - eric.smith
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7928
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7926] Stray parentheses() in context manager what's new doc

2010-02-14 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Thanks, should be fine now in r78188.

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7926
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7788] segfault when deleting from a list using slice with very big `step' value

2010-02-14 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Yes, adding carefully placed (size_t) casts seems like the right way to solve 
the problem.

I've fixed all (I think) the warnings in r78183, r78184, r78189.  I also fixed 
one case (unrelated to this issue) of potential undefined behaviour from signed 
overflow.

--
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7788
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7926] Stray parentheses() in context manager what's new doc

2010-02-14 Thread Edward Welbourne

Edward Welbourne e...@chaos.org.uk added the comment:

Nice :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7926
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5651] OS X Installer: add checks to ensure proper Tcl configuration during build

2010-02-14 Thread Katrine Whiteson

Katrine Whiteson katrinewhite...@gmail.com added the comment:

Hi,

Wow, thank you for noticing this. I tried to install python 2.6.4  
with the mac dmg, but couldn't figure out where it was installed.  I  
hunted around and made a link to a python 2.6 that I found - it must  
have been a previous version.

Now I have a fresh and successful python 2.6.4 install, Tkinter test  
works, and so I should be set.

I am still having trouble building matplotlib. Apparently my  
syslibroot is multiply specified. (I installed Xcode 2.2.1 from the  
mac developer site recently, by the way...). If you understand this,  
I would really appreciate any insight you have (I am attaching the  
output from when I try to build matplotlib).

thank you!!
Katrine

python2.6 setup.py build
 

BUILDING MATPLOTLIB
 matplotlib: 0.99.1.1
 python: 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)   
[GCC
 4.0.1 (Apple Inc. build 5493)]
   platform: darwin

REQUIRED DEPENDENCIES
  numpy: 1.3.0
  freetype2: found, but unknown version (no pkg-config)
 * WARNING: Could not find 'freetype2'  
headers in any
 * of '.', './freetype2'.

OPTIONAL BACKEND DEPENDENCIES
 libpng: found, but unknown version (no pkg-config)
 * Could not find 'libpng' headers in any of '.'
Tkinter: Tkinter: 73770, Tk: 8.4, Tcl: 8.4
   wxPython: no
 * wxPython not found
   Gtk+: no
 * Building for Gtk+ requires pygtk; you must  
be able
 * to import gtk in your build/install  
environment
Mac OS X native: yes
 Qt: no
Qt4: no
  Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES
   datetime: present, version unknown
   dateutil: matplotlib will provide
   pytz: matplotlib will provide
adding pytz

OPTIONAL USETEX DEPENDENCIES
 dvipng: no
ghostscript: /bin/sh: line 1: gs: command not found
  latex: no

[Edit setup.cfg to suppress the above messages]
 

pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends',  
'matplotlib.projections', 'mpl_toolkits', 'mpl_toolkits.mplot3d',  
'mpl_toolkits.axes_grid', 'matplotlib.sphinxext',  
'matplotlib.numerix', 'matplotlib.numerix.mlab',  
'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra',  
'matplotlib.numerix.random_array', 'matplotlib.numerix.fft',  
'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil/zoneinfo']
running build
running build_py
copying lib/matplotlib/mpl-data/matplotlibrc - build/lib.macosx-10.4- 
fat-2.6/matplotlib/mpl-data
copying lib/matplotlib/mpl-data/matplotlib.conf - build/ 
lib.macosx-10.4-fat-2.6/matplotlib/mpl-data
running build_ext
building 'matplotlib.ft2font' extension
c++ -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g  
-bundle -undefined dynamic_lookup -arch i386 -arch ppc -L/usr/local/ 
lib -syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc - 
I/usr/local/include -I/usr/local/include/freetype2 -isysroot / 
Developer/SDKs/MacOSX10.4u.sdk build/temp.macosx-10.4-fat-2.6/src/ 
ft2font.o build/temp.macosx-10.4-fat-2.6/src/mplutils.o build/ 
temp.macosx-10.4-fat-2.6/CXX/cxx_extensions.o build/temp.macosx-10.4- 
fat-2.6/CXX/cxxsupport.o build/temp.macosx-10.4-fat-2.6/CXX/ 
IndirectPythonInterface.o build/temp.macosx-10.4-fat-2.6/CXX/ 
cxxextensions.o -lfreetype -lz -lstdc++ -lm -o build/lib.macosx-10.4- 
fat-2.6/matplotlib/ft2font.so
powerpc-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ 
Developer/SDKs/MacOSX10.4u.sdk'
i686-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ 
Developer/SDKs/MacOSX10.4u.sdk'
//usr/bin/ld: -usr/syslibroot: multiply specified
bincollect2: /ld: -syslibroot: multiply specified
ld returned 1 exit statuscollect2:
ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccym1XU1.out (No such file or  
directory)
error: command 'c++' failed with exit status 1
make: *** [mpl_build] Error 1
katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1  
katrinewhiteson$ gcc -V
gcc: argument to `-V' is missing
katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1  
katrinewhiteson$ which gcc
/usr/bin/gcc
katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1  
katrinewhiteson$   c f yj ny
-bash: c: command not found
katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1  
katrinewhiteson$ k/l
-bash: k/l: No such file or directory

On Feb 12, 2010, at 7:44 PM, Ned Deily wrote:


 Ned Deily n...@acm.org added the comment:

 Ah, earlier you said you installed Python 2.6.4 but, in your most  
 recent 

[issue7930] pydoc.stripid doesn't strip ID in py25, py26, py31

2010-02-14 Thread Michael Newman

New submission from Michael Newman michael.b.new...@gmail.com:

I found that pydoc.stripid doesn't strip the ID in Python 2.5, 2.6, and 3.1. I 
assume the problem is probably present in 2.7 and 3.2/dev.

For a little history, see this older issue back for Python 2.3:
http://bugs.python.org/issue934282

The following example show pydoc.stripid works for Python 2.3 and 2.4, but 
then fails for versions after that.

Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 import pydoc
 pydoc.stripid
function stripid at 0x00AC0BB0
 pydoc.stripid(repr(pydoc.stripid))
'function stripid'

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 import pydoc
 pydoc.stripid
function stripid at 0x00BB7BF0
 pydoc.stripid(repr(pydoc.stripid))
'function stripid'

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pydoc
 pydoc.stripid
function stripid at 0x00BEFCF0
 pydoc.stripid(repr(pydoc.stripid))
'function stripid at 0x00BEFCF0'

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pydoc
 pydoc.stripid
function stripid at 0x00C655B0
 pydoc.stripid(repr(pydoc.stripid))
'function stripid at 0x00C655B0'

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pydoc
 pydoc.stripid
function stripid at 0x00CFB8A0
 pydoc.stripid(repr(pydoc.stripid))
'function stripid at 0x00CFB8A0'

--
components: Library (Lib)
messages: 99349
nosy: mnewman
severity: normal
status: open
title: pydoc.stripid doesn't strip ID in py25, py26, py31
type: behavior
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7930
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7932] print statement delayed IOError when stdout has been closed

2010-02-14 Thread tholzer

New submission from tholzer thol...@wetafx.co.nz:

When printing to a closed stdout file descriptor, the print statement only 
raises an IOError at character 8192. 

The expected behaviour is that IOError gets raised immediately (i.e. on the 
first character). Compare this behaviour to writing to a closed sys.stderr.

To reproduce (using bash):

pre
# python -V
Python 2.6.4

# python -c 'print x * 8191' 1- ; echo $?
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:
0

# python -c 'print x * 8192' 1- ; echo $?
Traceback (most recent call last):
  File string, line 1, in module
IOError: [Errno 9] Bad file descriptor
1
/pre

--
components: Interpreter Core
messages: 99351
nosy: tholzer
severity: normal
status: open
title: print statement delayed IOError when stdout has been closed
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7932
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7932] print statement delayed IOError when stdout has been closed

2010-02-14 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

This is not a bug. The output stream gets buffered, and that it is closed is 
only detected when a flush is attempted. Use the -u option if you want 
unbuffered stdout.

It is, however, a bug that Python 2.6 apparently fails to flush the output at 
all; Python 2.5 did that correctly.

--
nosy: +loewis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7932
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com