Re: need help with introducing more traffic
Fredrik Lundh, I'm with you and my apologies for not making the scenario more clearer in my previous post [QUOTE]"load testing" other people's sites are known as something else, of course[QUOTE]- yes,that could cause a DoS and its lameI certainly dont intend to do that,was just checking whether the code was running alright on a random webserver and so if you did notice ran it with only '1(or 5) thread/s which cant hurt...I have setup an intranet in my uni and thats where i plan to carry out the actual tests as part of my dissertation'. Yes,i am trying to write a code to stress test webservers,i know there r many free tools out there but looking for opensource codes so that i couls tweak them. Cheers --- On Fri, 7/25/08, Fredrik Lundh <[EMAIL PROTECTED]> wrote: From: Fredrik Lundh <[EMAIL PROTECTED]> Subject: Re: need help with introducing more traffic To: [email protected] Date: Friday, July 25, 2008, 1:46 AM Fredrik Lundh wrote: > "load testing" other people's sites are known as something else, of course. message.replace(" are ", " is ") # do'h! (when do we get the ability to edit our c.l.python messages for, say, 30 minutes after they're posted? ;-) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: import dll instead of pyd
jrh wrote:
Yes it is in the same directory. The problem is it does not seem to
look for dll's at all. So is this by design, or am I missing
something?
looks like that was removed in 2.5; from Misc/NEWS:
- On Windows, .DLL is not an accepted file name extension for
extension modules anymore; extensions are only found if they
end in .PYD.
which is easily confirmed:
Python 2.4.3
>>> import imp
>>> imp.get_suffixes()
[('.pyd', 'rb', 3), ('.dll', 'rb', 3), ('.py', 'U', 1),
('.pyw', 'U', 1), ('.pyc', 'rb', 2)]
Python 2.5
>>> import imp
>>> imp.get_suffixes()
[('.pyd', 'rb', 3), ('.py', 'U', 1), ('.pyw', 'U', 1),
('.pyc', 'rb', 2)]
(the DLL support was a compatibility thing anyway, so I guess removing
it after 10+ years is a reasonable thing to do...)
--
http://mail.python.org/mailman/listinfo/python-list
Re: os.walk question
Lawrence D'Oliveiro wrote: Won't that return any subdirectories as well as files? sure, as was discussed in this very thread two days ago. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Terry Reedy <[EMAIL PROTECTED]> writes: > Torsten Bronger wrote: >> Hallöchen! > > And why does this make the implicit insertion of "self" difficult? >> I could easily write a preprocessor which does it after all. > > class C(): > def f(): > a = 3 > > Inserting self into the arg list is trivial. Mindlessly deciding > correctly whether or not to insert 'self.' before 'a' is impossible > when 'a' could ambiguously be either an attribute of self or a local > variable of f. Or do you and/or Jordan plan to abolish local > variables for methods? Why do you think that 'self' should be inserted anywhere except in the arg list? AFAIU, the idea is to remove the need to write 'self' in the arg list, not to get rid of it entirely. Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: file operations.
aditya shukla wrote:
Guys thanks for your previous help .I have a doubt again
(I'm sure you mean "a question"; in english, "a doubt" is something
slightly different, and quite often more negative.)
Also , because of this i am not able to extract the floating point
values ie 0.50,0.50,0.66 respectively
cause when i use the proposed solution given earlier
data=[]
for line in x:
print repr(line) # added for debugging!
line=line.split("|")
data.append(float(line[-2])) --> i am trying to get the floating
point values from the back
i receive this error message
Traceback (most recent call last):
File "", line 3, in
d.append(float(line[-2]))
IndexError: list index out of range
one or more lines in your file doesn't match the description; try adding
a print statement (see above) to see what they might look like, and make
sure that you filter them out (e.g. by checking the size of the list you
get from the split, as Terry explains).
--
http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and reading value under pointer passed as param of a callback
On Jul 24, 5:01 pm, Thomas Heller <[EMAIL PROTECTED]> wrote:
> waldekschrieb:
>
> > Hi,
>
> > I'm using C dll with py module and wanna read value (buffer of bytes)
> > returned in py callback as parameter passed to dll function.
>
> The callback receives a pointer instance. You can dereference the pointer
> to read individual bytes in this way:
>print data[0], data[5], data[42]
> or use slicing to read a bunch of bytes:
>print data[0:42]
>
> So, you probably want something like this:
>
> > --
> > def mycallback(data, size):
> > # how to read data buffer here ?
>
> print data[:size]
>
> > return 0
>
> > cbfunc = CFUNCTYPE(c_int, POINTER(c_uint8), c_int)
>
> > mydll = cdll.somedll
> > mdll.foo(cbfunct)
> > ---
>
> > Question: How to get bytes from the buffer passed to mycallback ???
> > Let's assume that the buffer consist of 4 bytes 4 bytes 8 bytes.
>
> > I tried unpack("ii8s", data[0]) and nothing. I tried different ctypes
> > passed to callback and nothing.
>
> Thomas
Cool, works fine now.
... and how to convert a list of bytes to py string or int ??
i.e
data[:4] -> py int
data[4:8] -> py int
data[8:] -> py strng
I tried unpack and unpack_from but the buff should be an string or
buffer not a list of bytes as data is.
any suggestions?
--
http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - what module to use?
Use python's default GUI tkinter's drawing functions or you can use wxPython GUI kit or you can use pyopengl. If you are only interested to draw sin waves or math functions that you should give try to matlab at www.mathworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - what module to use?
On 25 Lug, 08:13, Pierre Dagenais <[EMAIL PROTECTED]> wrote: > What is the easiest way to draw to a window? I'd like to draw something > like sine waves from a mathematical equation. > Newbie to python. What you are really asking for is what GUI library you should use; every one allows you to draw freely. What do you need to do besides drawing sine waves? You should look at your full range of options; http://wiki.python.org/moin/GuiProgramming is a good starting point. The "easiest" way to draw might be with those toolkits that offer primarily a canvas to draw on rather than composable widgets. For example, Pyglet (http://pyglet.org/) offers OpenGL contexts with sensible defaults and unobtrusive automation: from pyglet import * from pyglet.gl import * import math win = window.Window(width=700, height=700, caption="sine wave demo", resizable=True) frequency,phase,amplitude=0.1,0.0,0.9 @win.event def on_draw(): half_height=win.height*0.5 glClear(GL_COLOR_BUFFER_BIT) glColor3f(0.9, 1.0, 0.8) glBegin(GL_LINE_STRIP) for x in xrange(0,win.width): y=half_height*(1.0+amplitude*math.sin(x*frequency+phase)) glVertex2f(x,y) glEnd() app.run() Regards, Lorenzo Gatti -- http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - what module to use?
You can try R cran also. Very powerfull and free. And with R you can use Rpy, a library R for python and can access to R function and R graph in a python script. Other mathematic library exist in python : Matplotlib for exemple. Summary : to draw graph easely in python : Rpy lib or Matplotlib. If you don't know R language (vectorial language) use Matplotlib. Adress : R site : http://cran.r-project.org/ Rpy lib for python : http://rpy.sourceforge.net/ Matplotlib for python : http://matplotlib.sourceforge.net/ On 7/25/08, King <[EMAIL PROTECTED]> wrote: > > Use python's default GUI tkinter's drawing functions or you can use > wxPython GUI kit or you can use pyopengl. > If you are only interested to draw sin waves or math functions that > you should give try to matlab at www.mathworks.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Function editing with Vim throws IndentError
Lawrence D'Oliveiro wrote: Specified by whom? The most common setting these days is 4 columns. Where? I've randomly seen code snipplets that indent using spaces or, worse, tabstop != 8, but most code I've come across uses tabstop width 8, which is how it was meant to be from the beginning of time. Unfortunately, for many people it's hard to understand that a tabstop is not the same as indenting with spaces, but I think this is leading too far and will end in a dogmatic discussion like the `ViM vs. Emacs' war. Anyways, if you claim tabstop 4 is most widely used I'd like to see some kind of a reference for that since it contradicts not only my experience. Finally, I'd like to throw in this one from the Linux kernel sources, from `Documentation/CodingStyle: Chapter 1: Indentation Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3. [...] Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
> > By that logic, C++ is not OO. By that logic, Ruby is not OO. By that > logic, I know of only one OO language: Java :) > > The fact that a language doesn't force you to do object-oriented > programming doesn't mean that it's not object-oriented. In other > words, your words are nonsense. > No, what it means is that it might support OO but doesn't have to, it isn't the only way to code. Supporting and Being OO are very different. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 25, 3:38 am, [EMAIL PROTECTED] wrote: > > By that logic, C++ is not OO. By that logic, Ruby is not OO. By that > > logic, I know of only one OO language: Java :) > > > The fact that a language doesn't force you to do object-oriented > > programming doesn't mean that it's not object-oriented. In other > > words, your words are nonsense. > > No, what it means is that it might support OO but doesn't have to, it > isn't the only way to code. > "Support OO but it doesn't have to"? That sounds like saying that in some Python implementations you'll be able to use OO, but that you just might bump into a Python distribution where you would type class MClass: pass at the interpreter and it would give you an syntax error. Is that what you mean? > Supporting and Being OO are very different. I guess at this point it's rather pointless to discuss this because of the different and deep level of interpretation that we might have on the words "support" and "be." IMO, the obvious thing to say is that a language that *supports* OO can also be said to *be* OO. However, it would seem just ridiculous to me to say the same thing about a language like, e.g., Perl, where OO is so pathetic. But maybe this is just a game of words... I consider Python to *be* OO, anyway. Sebastian -- http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - what module to use?
On Fri, Jul 25, 2008 at 2:13 AM, Pierre Dagenais <[EMAIL PROTECTED]> wrote: > What is the easiest way to draw to a window? I'd like to draw something > like sine waves from a mathematical equation. > Newbie to python. > -- > http://mail.python.org/mailman/listinfo/python-list > I'd recommend matplotlib: http://matplotlib.sourceforge.net/ Also see the "GUI" and "Plotting" sections on this page: http://wiki.python.org/moin/UsefulModules -- http://mail.python.org/mailman/listinfo/python-list
Re: interpreter vs. compiled
in 75186 20080725 050433 Tim Roberts <[EMAIL PROTECTED]> wrote: >castironpi <[EMAIL PROTECTED]> wrote: >> >>Compiling a program is different than running it. A JIT compiler is a >>kind of compiler and it makes a compilation step. I am saying that >>Python is not a compiler and in order to implement JIT, it would have >>to change that fact. > >And I'm saying you are wrong. There is NOTHING inherent in Python that >dictates that it be either compiled or interpreted. That is simply an >implementation decision. The CPython implementation happens to interpret. >The IronPython implementation compiles the intermediate language to native >machine language. > >>> of Python that uses .NET. In that case, the code *IS* JIT compiled to >>> assembly when the program starts. >> >>But still not the user's code, only the interpreter, which is running >>in assembly already anyway in CPython. > >In CPython, yes. In IronPython, no; the user's code is compiled into >machine language. Both of them are "Python". >-- >Tim Roberts, [EMAIL PROTECTED] >Providenza & Boekelheide, Inc. It's amazing how many people cannot differentiate between language and implementation. How many times have I read "x is an interpreted language"? I know many languages are designed for either compilation or interpretation, but I have used C and Pascal interpreters as well as Java and Rexx compilers. -- http://mail.python.org/mailman/listinfo/python-list
Execution speed question
I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I ask applies more generally than my specific case. I would greatly appreciate general feedback in terms of computing and of course considerations specific to implementation in Python. The nodes in my network may be ON or OFF. The network starts off with all nodes in the OFF state. I loop through the nodes. For each node that is OFF, I consider some probability of it turning ON based on the states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING WHICH ONES TO TURN ON. So my question is whether it is faster to 1. loop through a list of ALL nodes and check for OFF nodes using ifs or to 2. loop through a container of OFF nodes and remove from this when they turn ON The second would result in looping through less nodes, especially as the simulation progresses, but how does the cost of removal compare with cheap ifs and would the extra memory usage affect performance. I an appreciate that the cost of the if check, the number of nodes, and the type of container I use will come into the answer. In my case, the ifs are cheap boolean queries (whether the node is ON or OFF). The number of nodes is very large: millions for sure, maybe tens of millions. If considering (2), take note of my BOLD text above, which means I can't remove nodes as I iterate through them in the main loop. I naturally started coding with (2), but couldn't decide on the best data structure for python. A set seemed ideal for speedy removal, but then I can't iterate through them with out popping. An ordered list? Some creative solution with numpy arrays? There is also the complication that since we are in interpreted python, what is theoretically the best data structure may not in reality be optimal unless it is a default system object or coded externally in a compiled module. Of course, I will start experimenting to see what the execution difference is, but I would appreciate some suggestions from others re which is best and also on best data structure for (2). I'm not a newbie, so you can get technical with me python-wise and algorithm wise. I realise it is a 'basic' question, but it is something that I have always wondered about (cheap ifs versus extra structure) and with the number of nodes I am considering, it actually becomes an issue. Many Thanks, Suresh -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml, comparing nodes
> If document order doesn't matter, try sorting the elements of each level in
> the two documents by some arbitrary deterministic key, such as (tag name,
> text, attr count, whatever), and then compare them in order, instead of trying
> to find matches in multiple passes. itertools.groupby() might be your friend
> here.
I think that sorting multiple times by each attribute will cost more
than I've managed to do:
from lxml import etree
from collections import deque
import string, re, time
def xmlEqual(xmlStr1, xmlStr2):
et1 = etree.XML(xmlStr1)
et2 = etree.XML(xmlStr2)
let1 = [x for x in et1.iter()]
let2 = [x for x in et2.iter()]
if len(let1) != len(let2):
return False
while let1:
el = let1.pop(0)
foundEl = findMatchingElem(el, let2)
if foundEl is None:
return False
let2.remove(foundEl)
return True
def findMatchingElem(el, eList):
for elem in eList:
if elemsEqual(el, elem):
return elem
return None
def elemsEqual(el1, el2):
if el1.tag != el2.tag or el1.attrib != el2.attrib:
return False
# no requirement for text checking for now
#if el1.text != el2.text or el1.tail != el2.tail:
#return False
path1 = el1.getroottree().getpath(el1)
path2 = el2.getroottree().getpath(el2)
idxRE = re.compile(r"(\[\d*\])")
path1 = idxRE.sub("", path1)
path2 = idxRE.sub("", path2)
if path1 != path2:
return False
return True
Notice that if documents are in exact same order, each element is
compared only once!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Questions on 64 bit versions of Python
On 2008-07-25 08:13, [EMAIL PROTECTED] wrote: Background: I'm going to be processing some raw transaction logs that are 30G in size. As part of this processing I may need to create some very large dictionary structures. I will be running my scripts on a version of Windows 2003 Server Enterprise Edition that supports 16G of RAM. Yes, I could use a database in place of dictionaries, but I'm looking for maximum performance. The following page lists two 64 bit versions of Python for Windows: http://www.python.org/download/releases/2.5.2/ For Win64-Itanium users: python-2.5.2.ia64.msi For Win64-AMD64 users: python-2.5.2.amd64.msi 1. It looks like the 64 bit versions of Python for Windows are CPU vendor specific, eg. it doesn't look like there's a single, universal executable for Windows 64 bit platforms. Is this true? Yes. But then Intel Itanium is being phased out anyway and the AMD64 build works on both Intel and AMD processors. 2. Are there limitations to the using the 64 bit versions of Python? I seem to remember reading that many 3rd party modules (especially Windows OS specific modules) may not be compatible with the 64 bit versions of Python for Windows. True. The extensions usually need to be recompiled and possibly also updated to support 64-bit architectures. The win32 tools are available on 64-bit Windows - if that's what you mean with "Windows OS specific modules". 3. If I wanted to run a 64 bit version of Python under Linux, would I need to recompile from source on 64 bit version of Linux or do 64 bit versions of Linux automatically ship with 64 bit versions of Python? (Any recommendations on a flavor of 64 bit of Linux for the Intel architecture would be appreciated) Yes, 64-bit Linux versions ship with 64-bit builds of Python. Any recent Linux distro should work just fine. 4. Is there a stable version of IronPython compiled under a 64 bit version of .NET? Anyone have experience with such a beast? Can't comment on that one. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jul 25 2008) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 -- http://mail.python.org/mailman/listinfo/python-list
Re: scanf in python
In message <[EMAIL PROTECTED]>, AMD wrote: Actually it is quite common, it is used for processing of files not for reading parameters. You can use it whenever you need to read a simple csv file or fixed format file which contains many lines with several fields per line. I do that all the time, in Python and C++, but I've never felt the need for a scanf-type function. I agree scanf is not a must have function but rather a nice to have function. For reading delimited fields in Python, you can use .split string method. Yes, that is what I use right now, but I still have to do the conversion to integers, floats, dates as several separate steps. What is nice about the scanf function is that it is all done on the same step. Exactly like when you use % to format a string and you pass it a dictionary, it does all the conversions to string for you. Cheers, André -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on 64 bit versions of Python
M.-A. Lemburg wrote: 4. Is there a stable version of IronPython compiled under a 64 bit version of .NET? Anyone have experience with such a beast? Can't comment on that one. Should that matter? Isn't IronPython pure CLR? -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 7:57 pm, Suresh Pillai <[EMAIL PROTECTED]> wrote: > The nodes in my network may be ON or OFF. The network starts off with > all nodes in the OFF state. I loop through the nodes. For each node > that is OFF, I consider some probability of it turning ON based on the > states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING > WHICH ONES TO TURN ON. > > So my question is whether it is faster to > > 1. loop through a list of ALL nodes and check for OFF nodes using ifs I'd recommend using 'filter' and list comprehensions. >>> import random >>> class Node: ... def __init__(self): ... self.on = False ... def toggle(self): ... self.on = random.choice([True, False]) ... >>> nodes = [Node() for i in range(0, 1)] >>> for node in nodes: ... node.toggle() ... >>> off_nodes = filter(lambda x: not x.on, nodes) >>> len(off_nodes) 5050 -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml, comparing nodes
code_berzerker wrote: >> If document order doesn't matter, try sorting the elements of each level in >> the two documents by some arbitrary deterministic key, such as (tag name, >> text, attr count, whatever), and then compare them in order, instead of >> trying >> to find matches in multiple passes. itertools.groupby() might be your friend >> here. > > I think that sorting multiple times by each attribute will cost more > than I've managed to do: [...] > let1 = [x for x in et1.iter()] > let2 = [x for x in et2.iter()] > [...] > while let1: > el = let1.pop(0) > foundEl = findMatchingElem(el, let2) > if foundEl is None: > return False > let2.remove(foundEl) > return True > > def findMatchingElem(el, eList): > for elem in eList: > if elemsEqual(el, elem): > return elem > return None [...] > Notice that if documents are in exact same order, each element is > compared only once! Not in your code. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: scanf in python
AMD wrote:
For reading delimited fields in Python, you can use .split string method.
Yes, that is what I use right now, but I still have to do the conversion
to integers, floats, dates as several separate steps. What is nice about
the scanf function is that it is all done on the same step. Exactly like
when you use % to format a string and you pass it a dictionary, it does
all the conversions to string for you.
You're confusing surface syntax with processing steps. If you want to
do things on one line, just add a suitable helper to take care of the
processing. E.g. for whitespace-separated data:
>>> def scan(s, *types):
... return tuple(f(v) for (f, v) in zip(types, s.split()))
...
>>> scan("1 2 3", int, int, float)
(1, 2, 3.0)
This has the additional advantage that it works with any data type that
provides a way to convert from string to that type, not just a small
number of built-in types. And you can even pass in your own local
helper, of course:
>>> def myfactory(n):
... return int(n) * "!"
...
>>> scan("1 2 3", int, float, myfactory)
(1, 2.0, '!!!')
If you're reading multiple columns of the same type, you might as well
inline the whole thing:
data = map(int, line.split())
For other formats, replace the split with slicing or a regexp. Or use a
ready-made module; there's hardly every any reason to read standard CSV
files by hand when you can just do "import csv", for example.
Also note that function *creation* is relatively cheap in Python, and
since "def" is an executable statement, you can create them pretty much
anywhere; if you find that need a helper somewhere in your code, just
put it there. The following is a perfectly valid pattern:
def myfunc(...):
def myhelper(...):
...
myhelper(...)
myhelper(...)
for line in open(file):
myhelper(...)
(I'd say knowing when and how to abstract things away into a local
helper is an important step towards full Python fluency -- that is, the
point where you're able to pack "a lot of action in a small amount of
clear code" most of the time.)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Undefined calling conventions in Python.h
On Jul 23, 1:19 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Ben Sizer wrote: > > You should put the extern block around the #include call > > rather than individual functions, as surely the C calling convention > > should apply to everything within. > > Hello? Python's include files are C++ safe. I even posted a complete > compiler session to show that I'm not making that up. > > In theory, yeah. In practice, if his compiler was somehow not respecting that, then a quicker fix is to enclose the #include than to do individual prototypes. Admittedly that might obscure the problem rather than solve it. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml, comparing nodes
> Not in your code. > > Stefan Not sure what you mean, but I tested and so far every document with the same order of elements had number of comparisons equal to number of nodes. -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml, comparing nodes
code_berzerker wrote: >> Not in your code. >> >> Stefan > > Not sure what you mean, but I tested and so far every document with > the same order of elements had number of comparisons equal to number > of nodes. Sorry, missed the "let2.remove(foundEl)" line. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Undefined calling conventions in Python.h
Ben Sizer wrote: In theory, yeah. In practice, if his compiler was somehow not respecting that, then a quicker fix is to enclose the #include than to do individual prototypes. Admittedly that might obscure the problem rather than solve it. Well, I'd say that the should in You should put the extern block around the #include call rather than individual functions, as surely the C calling convention should apply to everything within. makes it look way too much like "this is how you should use python.h" to be appropriate, given the earlier discussions in the thread, and that a casual inspection of the include files reveals that the included files contain exactly that thing. C compilers can be pretty stupid, indeed, but it's usually better to look for a solution that makes some sense (e.g. the wrong project settings) before blaming it all on deeper magic (it will look at this code if I put it here, but not if I put it there. hmm. must be a ley line over there. what if I add a comment?). -- http://mail.python.org/mailman/listinfo/python-list
Re: PyOpenGL Tutorial?
arsyed wrote: ... Also, see: http://www.siafoo.net/browse?keyword_id=245 But note regarding the second tutorial there that the PyOpenGL 3.x *does* supply wrappers for most publicly known extensions, so you shouldn't have to create your own wrappers for them any more. There's also tutorials that are not wxPython specific on the PyOpenGL documentation page. HTH, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Automatically loading and initialising objects from a plugins directory
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Fredrik Lundh wrote: > so now you're no longer supporting mixins and multiple-level > inheritance? why not just tweak Diez' example a little: > > for name in dir(plugin): > > thing = getattr(plugin, name) > > # make sure this is a plugin > try: >if thing is Plugin: >continue >if not issubclass(thing, Plugin): >continue > except ValueError: # issubclass sucks >continue # not a class > > thing() # probably needs error handling around this > > (I also moved the thing call out of the thing validation part, to allow > you to distinguish between ValueErrors caused by issubclass and errors > caused by things) > > (btw, another approach would be to use a metaclass to make Plugin > classes register themselves on import) > > Thanks, that works much better. I've only been using python a couple of months, so still getting to grips with how it treats classes/subclasses. I'll have a look into metaclasses too, haven't stumbled upon those yet at all. Cheers, Dave - -- ~~ )<>< <>< ( Dave Challis) [EMAIL PROTECTED](___ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFIibiHv26GZvAVVFERAgcmAJ4tmC7jp6TTb3Dx2Lw+rKSmJkcSLQCfYFsA e0ZLOf8lQXhqHcz/Me8ok0E= =Qcg7 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: object persistency, store instances relationship externally
King wrote:
This is a new test for object persistency. I am trying to store the
relationship between instances externally.
It's not working as expected. May be I am doing it in wrong way. Any
suggestions?
import shelve
class attrib(object):
pass
class node(object):
def __init__(self):
self.a = attrib()
self.b = attrib()
self.c = attrib()
self.d = attrib()
a = node()
#store pair relationship. This relationship is created at run time.
lst = [[a.a, a.b], [a.c, a.d]]
#Write objects into file
shelf = shelve.open('shelve_test_01.txt', writeback=True)
shelf['node'] = a
shelf['lst'] = lst
shelf.sync()
shelf.close()
#Read objects from file
shelf = shelve.open('shelve_test_01.txt', 'r')
a = shelf['node']
lst = shelf['lst']
print a.a, a.b, a.c, a.d
#lst does not contains the relationship of object 'a''s attributes,
instead it's creating new instances
#of 'attrib' class
print lst
You may want to take a look at Zope's ZODB.
-Larry
--
http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 9:26 pm, Jordan <[EMAIL PROTECTED]> wrote:
> In reality? I'll just keep writing Python (hopefully enough so that
> explicit self become burned into muscle memory), and use other
> languages when necessary (no more C than I have to, looking forward to
> dabbling in Erlang soon, and one day overcoming the parentheses phobia
> enough to really tackle Lisp properly). When I'm old enough and wise
> enough, and have the time, energy and inclination, maybe I'll sit down
> and put a proper effort into designing and implementing a new language
> that bests suits my own particular style and needs.
> Just maybe it'll
> be good enough that smart people will rally to defend its design
> principles from people attacking them on the internet :-)
Forgive me in advance, but that is just a day dream, however good a
language design is, there WILL be other people who disagree with the
corner cases. Python is one example, even with Guido that is great at
designing language, there are many edges in python that many people
disagree and attack from time to time, but not every one of those
edges got fixed, why? Because it is impossible to appeal everyone, if
the language is changed according to your (or other's) idea, there
will be some other people who don't like it (with your examples, it
might be the people who are used to functional programming and people
who want to implement a very complex behavior in __eq__ and __ne__).
What seemed to be the obviously correct behavior for you would be
unexpected for some other people (this is also in python's Zen
although in a slightly twisted kind of way[1]: "There should be one--
and preferably only one --obvious way to do it; Although that way may
not be obvious at first unless you're Dutch.").
[1] Basically, the Zen is saying that whether and idea is the
obviously correct way to do something is measured by Guido's measuring
tape. Basically it's also saying that python is designed according to
what HE thinks is obviously correct.
The Zen you're attacking: "Explicit is better than implicit," is a
generally good advice, although as you mentioned, it doesn't fit every
single cases in the world, which leads us to the other Zen[2]:
"Special cases aren't special enough to break the rules; Although
practicality beats purity."
[2] In our case, "Explicit is better than implicit" is the "rules",
the corner cases where implicit is a generally better choice is the
"special cases". The first verse ("Special cases ... break rules")
implies that everything should be explicit, no exceptions, while the
second verse ("practicality beats purity") means that if something
breaking the rule makes it more practical, then you don't have to
follow the rules[3]. These two statements contradicts each other,
implying an implicit Zen: "Foolish consistency is the hobgoblin's
little minds", it is OK to break the rules sometimes.
[3] Despite saying this, I also have to emphasize that what is
practical or not is measured by Guido's tape.
With this explained, I hope you understand the point I'm making:
"There is no The Perfect Language, that is liked by everyone in the
world." The moral is, if you like a language, try to resist its warts
and know that each wart have its own story. You don't have to like the
warts, but you just need to stand to it.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Automatically loading and initialising objects from a plugins directory
Dave Challis wrote:
I'll have a look into metaclasses too, haven't stumbled upon those yet
at all.
It's a potentially brain-exploding topic, though, so if the above
solution works for you, you might want to leave it at that ;-)
But very briefly, a metaclass is a something that's responsible for
creating a class, much like an ordinary class is responsible for
creating an object. When Python executes the following statement,
class Spam:
attrib = 1
def func(self):
pass
# <-- end of class statement
it will create a new scope for the class content, execute the class
body, and then, when it reaches the end, call the "metaclass" to create
the actual class object. The metaclass is given the requested name
("Spam" in this case), any base classes, and a dictionary containing
everything from the class scope ("attrib" and "func", in this case).
The thing that's returned is assigned to the "Spam" variable.
The default metaclass ("type") just creates an ordinary class object,
but if you replace that with your own metaclas, you can completely
override that behaviour, or just extend it (e.g. by registering the
subclasses in a common registry). Like, say, this:
registry = [] # list of subclasses
class Plugin(object):
class __metaclass__(type):
def __init__(cls, name, bases, dict):
type.__init__(name, bases, dict)
registry.append((name, cls))
class SpamPlugin(Plugin):
pass
class BaconPlugin(Plugin):
pass
for name, cls in registry:
if cls is not Plugin:
print name, cls
Here, the presence of an inner __metaclass__ class (which is a subclass
of "type") causes Python's class machinery to use that class instead of
"type" when creating class objects for Plugin or any subclass thereof.
The extra code in the __init__ method just all plugins to a list.
For more on this, see e.g.
http://www.python.org/download/releases/2.2/descrintro/#metaclasses
--
http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
> I'd recommend using 'filter' and list comprehensions. Look at using reduce(). You can collect information about all of the nodes without necessarily building a large, intermediate list in the process. You might get some ideas from here [http://en.wikipedia.org/wiki/ Antiobjects]. -- http://mail.python.org/mailman/listinfo/python-list
Re: object persistency, store instances relationship externally
King wrote: This is a new test for object persistency. I am trying to store the relationship between instances externally. It's not working as expected. May be I am doing it in wrong way. Any suggestions? The shelve module pickles each stored item individually. To preserve inter-object relations, try putting all related things in a tuple, and store that instead. E.g. shelf['data'] = (a, lst) a, lst = shelf['data'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
Anthony wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily For Windows users, PyScripter provides a) and b). I don't understand what you are seeking with c). Colin W. -- http://mail.python.org/mailman/listinfo/python-list
POP3 - Using poplib only shows the first few hundred messages in the mailbox
Hello,
I am trying to use POP3_SSL class of the poplib module to read email
from my gmail account. I can connect just fine using the example here
http://www.python.org/doc/lib/pop3-example.html
import getpass, poplib
M = poplib.POP3('localhost')
M.user(getpass.getuser())
M.pass_(getpass.getpass())
numMessages = len(M.list()[1])
for i in range(numMessages):
for j in M.retr(i+1)[1]:
print j
That is the above sample code from the python doc. While everything
works fine, the problem is that when I use the list() function it only
returns about 400 messages starting from the beginning of my inbox. I
have probably 10,000 emails in my gmail account. I don't see any pop3
object functions to "move" around the inbox or anything of the like.
Could someone point me in the right direction? I'm sure there must be
something simple I am missing.
Thanks,
Steve
--
http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 10:57 am, Suresh Pillai <[EMAIL PROTECTED]> wrote: > I am performing simulations on networks (graphs). I have a question on > speed of execution (assuming very ample memory for now). I simplify the > details of my simulation below, as the question I ask applies more > generally than my specific case. I would greatly appreciate general > feedback in terms of computing and of course considerations specific to > implementation in Python. > > The nodes in my network may be ON or OFF. The network starts off with > all nodes in the OFF state. I loop through the nodes. For each node > that is OFF, I consider some probability of it turning ON based on the > states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING > WHICH ONES TO TURN ON. > > So my question is whether it is faster to > > 1. loop through a list of ALL nodes and check for OFF nodes using ifs > > or to > > 2. loop through a container of OFF nodes and remove from this when they > turn ON or 3. build a new list every iteration intead of deleting from the old one: while processing: new_off_list = [] for x in off_list: if goes_on(x): on_list.append(x) else: new_off_list.append(x) off_list = new_off_list generation += 1 Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on 64 bit versions of Python
On Jul 25, 5:52 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > M.-A. Lemburg wrote: > >> 4. Is there a stable version of IronPython compiled under a 64 bit > >> version of .NET? Anyone have experience with such a beast? > > > Can't comment on that one. > > Should that matter? Isn't IronPython pure CLR? > > IronPython is written in C# and runs in/with the CLR, if that's what you mean. Well, IronPython one works with the CLR and is equivalent to Python 2.4, whereas IronPython 2 works with the DLR and is equivalent to Python 2.5 Mike -- http://mail.python.org/mailman/listinfo/python-list
Calling external program from within python
Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolis -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with ctypes and char** data type
On Jul 24, 4:03 pm, Thomas Heller <[EMAIL PROTECTED]> wrote:
> Philluminati schrieb:
>
>
>
> > I'm a bit of a python newbie and I need to wrap a C library.
>
> > I can initialise the library using CDLL('mcclient.so')
>
> > and I can call functions correctly inside the library but I need to
> > invoke one function which has this function definition:
>
> > char ** CAPAPI McSearch(HMCLINK Handle,
> > short nSearchType,
> > short nNoSelect,
> > char **pSelect,
> > short nNoWhere,
> > char **pWhere,
> > char **pData,
> > int iTimeout);
>
> > For **pSelect I want to pass in an array of char points, which in C
> > would be declared as
>
> > char *pData[] = { "ADDR", "POSTCODE" };
>
> > Can someone tell me how use pointers + char pointers together in
> > python with ctypes please?
>
> # create an array that holds two pointers to 'char *', and fill it with data:
> pData = (c_char_p * 2)()
> pData[0] = "ADDR"
> pData[1] = "POSTCODE"
>
> # Another way:
> pData = (c_char_p * 2)("ADDR", "POSTCODE")
>
> Thomas
Thank you Thomas for your reply. I also got it working in a slightly
less sophisticated manor like this:
SelectType = c_char_p * 2
select = SelectType("ADDR", "POSTCODE")
ptr = pointer(select)
Anyway, thanks for taking the time to reply!
Phill
--
http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On Jul 25, 7:56 am, Emmanouil Angelakis <[EMAIL PROTECTED]> wrote: > Hi, > > I am tryiong to do something obviously trivial such as: > I have a c program called "tsys2list" that when it is ran it asks the user to > give the value of "tcal" which is a variable. I want to call the "tsys2list" > from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass > the value of "tcal" to th eprogram automatically and not by interacting with > the keyboard. > > How do I do that? > > thanks i advance! > manolis There are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want. Or you could learn a little Tkinter or wxPython and use that to get the user's variable. Or you could even do it via the command line using the "raw_input" command. http://docs.python.org/lib/module-subprocess.html Mike -- http://mail.python.org/mailman/listinfo/python-list
Python base distribution come with a validating XML parser?
Hi, Basic XML questions, I have a .xml file I want to validate against a .xsd file... Does the Python base distribution come with a validating XML parser? I want to make sure the elements in my xml file vs. the elements defined in my xsd are a match. I could parse both XML and xsd elements to lists and compare the lists, but I imagine the validation process can do this too... Some of this is basic stuff - just a link to a site or doc is sufficient. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 1:46 pm, Iain King <[EMAIL PROTECTED]> wrote:
> On Jul 25, 10:57 am, Suresh Pillai <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am performing simulations on networks (graphs). I have a question on
> > speed of execution (assuming very ample memory for now). I simplify the
> > details of my simulation below, as the question I ask applies more
> > generally than my specific case. I would greatly appreciate general
> > feedback in terms of computing and of course considerations specific to
> > implementation in Python.
>
> > The nodes in my network may be ON or OFF. The network starts off with
> > all nodes in the OFF state. I loop through the nodes. For each node
> > that is OFF, I consider some probability of it turning ON based on the
> > states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING
> > WHICH ONES TO TURN ON.
>
> > So my question is whether it is faster to
>
> > 1. loop through a list of ALL nodes and check for OFF nodes using ifs
>
> > or to
>
> > 2. loop through a container of OFF nodes and remove from this when they
> > turn ON
>
> or 3. build a new list every iteration intead of deleting from the old
> one:
>
> while processing:
> new_off_list = []
> for x in off_list:
> if goes_on(x):
> on_list.append(x)
> else:
> new_off_list.append(x)
> off_list = new_off_list
> generation += 1
>
> Iain
I was curious to what extent the different methods varied in time, so
I checked it out. Here there are three procedures: test_every which
matches your (1), destructive which matches your (2), and constructive
which is (3) as I've outlined above.
On varying the size of the dataset I get this (probability a node goes
on = 50%):
Length of initial list: 10
Test every: 1.16085492357
Destructive: 2.592310272
Constructive: 0.850312458886
Length of initial list: 20
Test every: 2.48013843287
Destructive: 9.20894689718
Constructive: 1.73562198439
Length of initial list: 40
Test every: 5.00652267447
Destructive: 44.9696004134
Constructive: 3.51687329373
Length of initial list: 80
Test every: 9.67657648655
Destructive: 220.57583941
Constructive: 7.06614485537
and changing the probability that a nodes goes on (dataset size =
20):
Probability goes on: 1/2
Test every: 2.24765364513
Destructive: 9.28801971614
Constructive: 1.62770773816
Probability goes on: 1/4
Test every: 4.77387350904
Destructive: 13.4432467571
Constructive: 3.45467140006
Probability goes on: 1/8
Test every: 11.0514899721
Destructive: 18.4026878278
Constructive: 6.86778036177
Probability goes on: 1/16
Test every: 22.5896021593
Destructive: 25.7784044083
Constructive: 13.8631404605
Probability goes on: 1/32
Test every: 49.7667941179
Destructive: 39.3652502735
Constructive: 27.2527219598
Probability goes on: 1/64
Test every: 91.0523955153
Destructive: 65.7747103963
Constructive: 54.4087322936
Code:
import random
from timeit import Timer
SIZE = 10
MAX = 2
def goes_on(x):
global MAX
return random.randint(1,MAX) == 1
def test_every():
global SIZE
print "Test every:",
nodes = range(SIZE)
is_on = [False for x in xrange(SIZE)]
count = SIZE
while count:
for i,x in enumerate(nodes):
if not is_on[i] and goes_on(x):
is_on[i] = True
count -= 1
def destructive():
global SIZE
print "Destructive:",
off_list = range(SIZE)
on_list = []
count = SIZE
while count:
for i in xrange(len(off_list)-1, -1, -1):
x = off_list[i]
if goes_on(x):
on_list.append(x)
del(off_list[i])
count -= 1
def constructive():
global SIZE
print "Constructive:",
off_list = range(SIZE)
on_list = []
count = SIZE
while count:
new_off_list = []
for x in off_list:
if goes_on(x):
on_list.append(x)
count -= 1
else:
new_off_list.append(x)
off_list = new_off_list
#SIZE = 20
while True:
print "Length of initial list:", SIZE
#print "Probability goes on: 1/%d" % MAX
print Timer("test_every()", "from __main__ import
test_every").timeit(1)
print Timer("destructive()", "from __main__ import
destructive").timeit(1)
print Timer("constructive()", "from __main__ import
constructive").timeit(1)
print
SIZE *= 2
#MAX *= 2
Conclusions:
On size, (2) really doesn't like bigger datasets, taking exponentially
longer as it increases, while (1) and (3) happily increase linearly.
(3) is faster.
On probability it's (1) who's the loser, while (2) and (3) are happy.
(3) is once again faster.
I think (2)'s poor performance is being amplified by how python
handles lists and list deletions; the effect may be stymied in other
languages, or by using other data constructs in python (like a
dictionary or a user made list class). If you were short on memory
then (2) wou
Re: 2d graphics - what module to use?
Pierre Dagenais wrote: What is the easiest way to draw to a window? I'd like to draw something like sine waves from a mathematical equation. Newbie to python. -- http://mail.python.org/mailman/listinfo/python-list For very simple things, the standard module turtle might be your best bet. BB -- http://mail.python.org/mailman/listinfo/python-list
Re: PyOpenGL Tutorial?
On Jul 23, 10:07 pm, Clay Hobbs <[EMAIL PROTECTED]> wrote:
> I need a tutorial for PyOpenGL (specifically, to be used with wxPython).
> I searched with Google and didn't find one. Does anybody know where one
> is?
PyOpenGL is just a wrapper for OpenGL. The API is identical. Do you
need an OpenGL tutorial?
As for wxPython, you just subclass wxGLCanvas. Call the method
SetCurrent() before you call OpenGL (e.g. through PyOpenGL) and
SwapBuffers() when you are done. See the wxWidgets reference.
Personally I think PyOpenGL is a slow beast. It is not just a thin
wrapper over OpenGL, but bloated with sanity checks, exception
handling, etc (look at the code, it is pure Python and easy to read).
I prefer to put all calls to OpenGL in a C DLL, and call that with
ctypes. If I make repeated calls to functions like glVertex3f, I want
them to to be fast, thus C is indicated over Python. And if all I do
in C is to make calls into OpenGL, there is no real advantage to using
Python here - the Python code would look almost exactly the same, but
would be slower by several orders of magnitude. By the way, I still
use wxGLCanvas from wxPython to set things up. The ctypes call into my
C DLL is called between SetCurrent() and SwapBuffers().
If you want a pure Python solution, you will need to use display
lists, vertex arrays (with NumPy) or vertex buffers (if your graphics
card supports it) to get acceptable performance.
Here is a short tutorial:
import wx
import wx.glcanvas
import ctypes
glrender = ctypes.pydll.glrender.render # use ctypes.cdll to call with
GIL released
glrender.argtypes = (ctypes.c_int, ctypes.c_int,)
glrender.restype = None
class MyCanvas(wx.glcanvas.GLCanvas):
def __init__(self, parent):
attribList = (wx.glcanvas.WX_GL_DOUBLEBUFFER,
wx.glcanvas.WX_GL_RGBA, 0)
wx.glcanvas.GLCanvas.__init__(self, parent, -1, attribList =
attribList)
self.context = wx.glcanvas.GLContext(self)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnSize(self, evt):
w,h = self.GetClientSize()
self.w = w
self.h = h
dc = wx.ClientDC(self)
self.Render(dc)
def OnPaint(self, evt):
dc = wx.PaintDC(self)
self.Render(dc)
def Render(self, dc):
self.SetCurrent()
glrender(self.w, self.h)
self.SwapBuffers()
And then in glrender.c, put the following:
#include
#include
#include
__declspec(dllexport)
void render(int w, int h)
{
/* calls to OpenGL goes here */
return;
}
And for Python 2.5.x on Windows, compile with:
gcc -O2 -o glrender.dll -shared -lopengl -lmsvcr71 glrender.c
--
http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
Mike Driscoll schrieb: On Jul 25, 7:56 am, Emmanouil Angelakis <[EMAIL PROTECTED]> wrote: Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolis There are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want. This will only work if the program can be fully controlled by commandline arguments. If interaction is required, the OP might consider using pexpect. Or you could learn a little Tkinter or wxPython and use that to get the user's variable. Or you could even do it via the command line using the "raw_input" command. I fail to see how *gathering* input (regardless of the method) solves the problem of *passing* input to a subprocess. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On 2008-07-25, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> There are probably many ways to do this. I would recommend >> checking out the subprocess module and see if it does what you >> want. > > This will only work if the program can be fully controlled by > commandline arguments. Why do you say that? You can interact with programs via stdin/stdout using the subprocess module. > If interaction is required, the OP might consider using > pexpect. Pexpect is a good option, but it's just an automation layer on top of the same facilities that subprocess provides. -- Grant Edwards grante Yow! I'm having a BIG BANG at THEORY!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 9:54 pm, Jeff <[EMAIL PROTECTED]> wrote: > Look at using reduce(). You can collect information about all of the > nodes without necessarily building a large, intermediate list in the > process. >From the OP's description, I assumed there'd be a list of all nodes, from which he wishes to derive a 2nd list of specific nodes. reduce() applies "a function of two arguments cumulatively to the items of a sequence, from left to right, so as to reduce the sequence to a single value", which doesn't seem to me to be what the OP was asking for. I could understand using map() across the filter'd list, or embedding the conditional check within the map'd function and ignoring filter(), but at no point does the OP ask to perform any kind of function based on two nodes... I may have misunderstand your point, though :) Could you provide a quick code sample to clarify? -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
That's a good comparison for the general question I posed. Thanks. Although I do believe lists are less than ideal here and a different data structure should be used. To be more specific to my case: As mentioned in my original post, I also have the specific condition that one does not know which nodes to turn ON until after all the probabilities are calculated (lets say we take the top m for example). In this case, the second and third will perform worse as the second one will require a remove from the list after the fact and the third will require another loop through the nodes to build the new list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 25, 9:49 pm, Lie <[EMAIL PROTECTED]> wrote: > These two statements contradicts each other, > implying an implicit Zen: "Foolish consistency is the hobgoblin's > little minds", it is OK to break the rules sometimes. "A foolish consistency is _the_ hobgoblin of little minds." (Ralph Waldo Emerson, although the emphasis is mine) I do like your version, though :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
Grant Edwards schrieb: On 2008-07-25, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: There are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want. This will only work if the program can be fully controlled by commandline arguments. Why do you say that? You can interact with programs via stdin/stdout using the subprocess module. Because usually if a program *prompts* the user to enter input (and that was what I read from the OP's post), one has to deal with pseudo terminals, not with stdin/out. If interaction is required, the OP might consider using pexpect. Pexpect is a good option, but it's just an automation layer on top of the same facilities that subprocess provides. AFAIK it's more than that. I'm not an expert on pseudo terminals, but AFAIK setting using module pty isn't possible using subprocess. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Iain King wrote: I think (2)'s poor performance is being amplified by how python handles lists and list deletions; the effect may be stymied in other languages Delete is O(n) (or "O(n/2) on average", if you prefer), while append is amortized O(1). Unless I'm missing something, your example keeps going until it's flagged *all* nodes as "on", which, obviously, kills performance for the first version as the probability goes down. The OP's question was about a single pass (but he did mention "as the simulation progresses", so I guess it's fair to test a complete simulation.) Btw, if the nodes can be enumerated, I'd probably do something like: node_list = ... get list of nodes ... random.shuffle(node_list) start = 0 end = len(node_list) step = end / MAX while start < end: for i in xrange(start, start + step): ... switch on node_list[i] ... ... do whatever you want to do after a step ... # prepare for next simulation step start += step step = max((len(node_list) - start) / MAX, 1) which is near O(n) overall, and mostly constant wrt. the probability for each pass (where the probability is 1:MAX). Might need some tuning; tweak as necessary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Fri, 25 Jul 2008 16:51:42 +0200, Fredrik Lundh wrote: > Unless I'm missing something, your example keeps going until it's > flagged *all* nodes as "on", which, obviously, kills performance for the > first version as the probability goes down. The OP's question was about > a single pass (but he did mention "as the simulation progresses", so I > guess it's fair to test a complete simulation.) I was referring to multiple passes as in Iain' test cases. Although not necessarily till all nodes are ON, let's say to to a large proportion at least. -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and reading value under pointer passed as param of a callback
"waldek" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On Jul 24, 5:01 pm, Thomas Heller <[EMAIL PROTECTED]> wrote:
waldekschrieb:
> Hi,
> I'm using C dll with py module and wanna read value (buffer of bytes)
> returned in py callback as parameter passed to dll function.
The callback receives a pointer instance. You can dereference the
pointer
to read individual bytes in this way:
print data[0], data[5], data[42]
or use slicing to read a bunch of bytes:
print data[0:42]
So, you probably want something like this:
> --
> def mycallback(data, size):
> # how to read data buffer here ?
print data[:size]
> return 0
> cbfunc = CFUNCTYPE(c_int, POINTER(c_uint8), c_int)
> mydll = cdll.somedll
> mdll.foo(cbfunct)
> ---
> Question: How to get bytes from the buffer passed to mycallback ???
> Let's assume that the buffer consist of 4 bytes 4 bytes 8 bytes.
> I tried unpack("ii8s", data[0]) and nothing. I tried different ctypes
> passed to callback and nothing.
Thomas
Cool, works fine now.
... and how to convert a list of bytes to py string or int ??
i.e
data[:4] -> py int
data[4:8] -> py int
data[8:] -> py strng
I tried unpack and unpack_from but the buff should be an string or
buffer not a list of bytes as data is.
any suggestions?
Try:
cbfunc = CFUNCTYPE(c_int, c_char_p, c_int)
ctypes understands c_char_p as a null-terminated character string and will
pass a string to your callback instead of a list of ints.
--Mark
--
http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 3:39 pm, Suresh Pillai <[EMAIL PROTECTED]> wrote: > That's a good comparison for the general question I posed. Thanks. > Although I do believe lists are less than ideal here and a different data > structure should be used. > > To be more specific to my case: > As mentioned in my original post, I also have the specific condition that > one does not know which nodes to turn ON until after all the > probabilities are calculated (lets say we take the top m for example). > In this case, the second and third will perform worse as the second one > will require a remove from the list after the fact and the third will > require another loop through the nodes to build the new list. So you need to loops through twice regardless? i.e. loop once to gather data on off nodes, do some calculation to work out what to turn on, then loop again to turn on the relevant nodes? If so, then I think the functions above remain the same, becoming the 2nd loop. Every iteration you do a first loop over the off_nodes (or them all for (1)) to gather the data on them, perform your calculation, and then perform one of the above functions (minus the setup code at the begining; basically starting at the 'for') as a second loop, with the goes_on function now returning a value based on the calculation (rather than the calculation itself as I had it). Performance should be similar. Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On Jul 25, 3:44 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Because usually if a program *prompts* the user to enter input (and that > was what I read from the OP's post), one has to deal with pseudo > terminals, not with stdin/out. How does the program writing some text before taking input change how it takes input? If it runs in a terminal and takes input from the user via keyboard, as in the user types a response and presses enter, it's most likely using stdin, in which case subprocess would be perfect. Perhaps that OP can clarify how the tcal program takes input? -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Suresh Pillai wrote: That's a good comparison for the general question I posed. Thanks. Although I do believe lists are less than ideal here and a different data structure should be used. To be more specific to my case: As mentioned in my original post, I also have the specific condition that one does not know which nodes to turn ON until after all the probabilities are calculated (lets say we take the top m for example). In this case, the second and third will perform worse as the second one will require a remove from the list after the fact and the third will require another loop through the nodes to build the new list. -- http://mail.python.org/mailman/listinfo/python-list It seems like the probability calculation applies to all three equally, and can therefore be ignored for the simulations. You said that your algorithm must be a two-stage process: (A) calculate the probabilities then (B) turn on some nodes. Iain's simulations assume (A) is already done. He just addressed the performance of (B). Part (A) is invariant for all his simulations, because your requirement forces it to be. As for different data structures, it largely depends on how you need to access the data. If you don't need to index the data, just loop through it, you might try a linked list. The performance hit in (2) is coming from the list del; using a linked list would make the removal constant rather than O(n), and may even execute faster than (3) as well. -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
oj schrieb: On Jul 25, 3:44 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: Because usually if a program *prompts* the user to enter input (and that was what I read from the OP's post), one has to deal with pseudo terminals, not with stdin/out. How does the program writing some text before taking input change how it takes input? If it runs in a terminal and takes input from the user via keyboard, as in the user types a response and presses enter, it's most likely using stdin, in which case subprocess would be perfect. Try using SSH with subprocess and prepare to be disappointed when it asks for a password. See this for a discussion: http://mail.python.org/pipermail/distutils-sig/2007-May/007553.html Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On Fri, 25 Jul 2008 08:13:55 -0700, oj wrote: > On Jul 25, 3:44 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Because usually if a program *prompts* the user to enter input (and that >> was what I read from the OP's post), one has to deal with pseudo >> terminals, not with stdin/out. > > How does the program writing some text before taking input change how > it takes input? It might not write the text before taking input because it is buffered. But if the controlling program waits for some text before sending input to the other program all hangs. > If it runs in a terminal and takes input from the user via keyboard, > as in the user types a response and presses enter, it's most likely > using stdin, in which case subprocess would be perfect. But buffering messes with the order of inputs and outputs. Buffering is different if you "talk" to a real (or pseudo) terminal or to a file or pipe and the calling program can't influence the called programs buffering except if it pretends to be a terminal, which pexpect does. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
RE: Questions on 64 bit versions of Python
The end result of that is on a 32-bit machine IronPython runs in a 32-bit process and on a 64-bit machine it runs in a 64-bit process. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Driscoll Sent: Friday, July 25, 2008 5:58 AM To: [email protected] Subject: Re: Questions on 64 bit versions of Python On Jul 25, 5:52 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > M.-A. Lemburg wrote: > >> 4. Is there a stable version of IronPython compiled under a 64 bit > >> version of .NET? Anyone have experience with such a beast? > > > Can't comment on that one. > > Should that matter? Isn't IronPython pure CLR? > > IronPython is written in C# and runs in/with the CLR, if that's what you mean. Well, IronPython one works with the CLR and is equivalent to Python 2.4, whereas IronPython 2 works with the DLR and is equivalent to Python 2.5 Mike -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Jul 25, 4:22 pm, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote: > It seems like the probability calculation applies to all three equally, > and can therefore be ignored for the simulations. The probability affects (1) more. My reasoning for this being: as probability gets lower the number of times you have to loop over the list increases. (1) always loops over the full list, but with each successive iteration (2) and (3) are looping over smaller and smaller lists. In the end this adds up, with (1) becoming slower than (2), even though it starts out quicker. Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: repr(string)
In article
<[EMAIL PROTECTED]>,
MRAB <[EMAIL PROTECTED]> wrote:
> On Jul 23, 4:04 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote:
> > I've been saving data in a file with one line per field.
> > Now some of the fields may become multi-line strings...
> >
> > I was about to start escaping and unescaping linefeeds
> > by hand, when I realized that repr() and eval() should
> > do. Hence the question: If s is a string, is repr(s)
> > guaranteed not to contain line breaks?
> >
> Might I suggest you use encode and decode instead?
Ah, you certainly might! Seems exactly right, thanks.
Many years ago I thought I had some idea of what was available
in Python - these days it's full of all this neat stuff I never
heard of...
> >>> 'first line\nsecond line'.encode('string-escape')
> 'first line\\nsecond line'
> >>> _.decode('string-escape')
> 'first line\nsecond line'
> >>> u'first line\nsecond line'.encode('unicode-escape')
> 'first line\\nsecond line'
> >>> _.decode('unicode-escape')
> u'first line\nsecond line'
--
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list
Question Regarding XML
Dear Group, I have some queries regarding XML conversion of some .txt/.doc files. I am thinking to use Satine. Is it OK? But it seems to support Python2.3 but does it support 2.5, too? If any one can kindly let me know. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On Jul 25, 9:28 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Mike Driscoll schrieb: > > > On Jul 25, 7:56 am, Emmanouil Angelakis <[EMAIL PROTECTED]> > > wrote: > >> Hi, > > >> I am tryiong to do something obviously trivial such as: > >> I have a c program called "tsys2list" that when it is ran it asks the user > >> to give the value of "tcal" which is a variable. I want to call the > >> "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< > >> I want to pass the value of "tcal" to th eprogram automatically and not by > >> interacting with the keyboard. > > >> How do I do that? > > >> thanks i advance! > >> manolis > > > There are probably many ways to do this. I would recommend checking > > out the subprocess module and see if it does what you want. > > This will only work if the program can be fully controlled by > commandline arguments. If interaction is required, the OP might consider > using pexpect. > > > Or you > > could learn a little Tkinter or wxPython and use that to get the > > user's variable. Or you could even do it via the command line using > > the "raw_input" command. > > I fail to see how *gathering* input (regardless of the method) solves > the problem of *passing* input to a subprocess. > > Diez My understanding of the OP's request was that "tsys2list" was a custom script of some sort that gathered info from the user, so I wanted to know why he didn't just skip calling it and write something in Tkinter or wxPython or even via the CLI instead. I'm probably just not understanding something. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Python base distribution come with a validating XML parser?
> Hi, > > Basic XML questions, > > I have a .xml file I want to validate against a .xsd file... > > Does the Python base distribution come with a validating XML parser? > > I want to make sure the elements in my xml file vs. the elements > defined in my xsd are a match. > > I could parse both XML and xsd elements to lists and compare the > lists, but I imagine the validation process can do this too... > > Some of this is basic stuff - just a link to a site or doc is > sufficient. > > Thanks. I think you are looking for lxmlhttp://codespeak.net/lxml/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
2008/7/25 Suresh Pillai <[EMAIL PROTECTED]>: > ... > I naturally started coding with (2), but couldn't decide on the best data > structure for python. A set seemed ideal for speedy removal, but then I > can't iterate through them with out popping. An ordered list? Some > creative solution with numpy arrays? > > ... Maybe I am missing something, but I'm not sure, where is the problem with non-destructive iterating over a set, e.g.: >>> my_set = set([1,2,3,4,5]) >>> my_set set([1, 2, 3, 4, 5]) >>> for item in my_set: print item, ... 1 2 3 4 5 >>> my_set set([1, 2, 3, 4, 5]) >>> my_set -= set([2,4]) >>> my_set set([1, 3, 5]) >>> Of course, the suitability for your application would depend on other factors too. vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Iain King wrote: On Jul 25, 4:22 pm, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote: It seems like the probability calculation applies to all three equally, and can therefore be ignored for the simulations. The probability affects (1) more. My reasoning for this being: as probability gets lower the number of times you have to loop over the list increases. (1) always loops over the full list, but with each successive iteration (2) and (3) are looping over smaller and smaller lists. In the end this adds up, with (1) becoming slower than (2), even though it starts out quicker. Iain -- http://mail.python.org/mailman/listinfo/python-list I meant the _calculation_ of the probability affects all three equally, not the value itself. As your simulations show, different probabilities affect the algorithms differently; I'm talking about the algorithm to arrive at the probability value. -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
Mike Driscoll schrieb: On Jul 25, 9:28 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: Mike Driscoll schrieb: On Jul 25, 7:56 am, Emmanouil Angelakis <[EMAIL PROTECTED]> wrote: Hi, I am tryiong to do something obviously trivial such as: I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. How do I do that? thanks i advance! manolis There are probably many ways to do this. I would recommend checking out the subprocess module and see if it does what you want. This will only work if the program can be fully controlled by commandline arguments. If interaction is required, the OP might consider using pexpect. Or you could learn a little Tkinter or wxPython and use that to get the user's variable. Or you could even do it via the command line using the "raw_input" command. I fail to see how *gathering* input (regardless of the method) solves the problem of *passing* input to a subprocess. Diez My understanding of the OP's request was that "tsys2list" was a custom script of some sort that gathered info from the user, so I wanted to know why he didn't just skip calling it and write something in Tkinter or wxPython or even via the CLI instead. I'm probably just not understanding something. The program is doing some work, and needs to be told what actually to do. It does so by asking the user, sure. But then it *works*. I think that's pretty clear from """ I have a c program called "tsys2list" that when it is ran it asks the user to give the value of "tcal" which is a variable. I want to call the "tsys2list" from within a pyrthon script lets call it "gamma.py" >>>but<<< I want to pass the value of "tcal" to th eprogram automatically and not by interacting with the keyboard. """ So replacing it with something that asks the same questions leaves us with the work undone... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Question Regarding XML
SUBHABRATA schrieb: Dear Group, I have some queries regarding XML conversion of some .txt/.doc files. I am thinking to use Satine. Is it OK? But it seems to support Python2.3 but does it support 2.5, too? If any one can kindly let me know. I think it's pretty dead, given the project news dating back to 2003. I suggest you use lxml or element-tree. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
These answers are too elaborate and abstract for the question.
Emmanouil,
Here is a program "myprog" which takes input and writes output to a
file. It happens to be python but it could be anything.
#
#!/usr/bin/env python
a = int(raw_input("enter thing 1 "))
b = int(raw_input("enter thing 2 "))
c = raw_input("enter output file name ")
f = open(c,"w")
f.write("answer is %s\n" % str(a + b))
f.close()
#
Here is python code which runs that program
#
import os
f = os.popen("/path/to/myprog","w")
f.write("3\n4\noutputname\n") #can also do three separate writes if
that is more convenient
f.close()
#
For some reason os.popen is deprecated in favor of the more verbose
subprocess.Popen, but this will work for a while.
Here is an even simpler approach that will take you a long way. This
should be very easy to understand.
#
import os
params = open("temp","w")
params.write("3\n")
params.write("4\n")
params.write("outputname2\n")
params.close()
os.system("/path/to/myprog < temp")
#
If you want python to pick up the stdout of your program as well look
into popen2.
Try basing your solution on those and if you have any problems let us
know what they are. In most cases such as you describe these will
work.
mt
--
http://mail.python.org/mailman/listinfo/python-list
Re: POP3 - Using poplib only shows the first few hundred messages in the mailbox
On Fri, Jul 25, 2008 at 5:18 AM, SteveC <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to use POP3_SSL class of the poplib module to read email
> from my gmail account. I can connect just fine using the example here
> http://www.python.org/doc/lib/pop3-example.html
>
> import getpass, poplib
>
> M = poplib.POP3('localhost')
> M.user(getpass.getuser())
> M.pass_(getpass.getpass())
> numMessages = len(M.list()[1])
> for i in range(numMessages):
>for j in M.retr(i+1)[1]:
>print j
>
>
> That is the above sample code from the python doc. While everything
> works fine, the problem is that when I use the list() function it only
> returns about 400 messages starting from the beginning of my inbox. I
> have probably 10,000 emails in my gmail account. I don't see any pop3
> object functions to "move" around the inbox or anything of the like.
>
> Could someone point me in the right direction? I'm sure there must be
> something simple I am missing.
>
> Thanks,
> Steve
> --
> http://mail.python.org/mailman/listinfo/python-list
>
The GroupWise popper where I work only allows access to the first 100
messages. To access the next 100 you have to retrieve the first 100.
My guess is that gmail is doing something similar.
If you retrieve the first 400, do you get a new list the next time?
--
Stand Fast,
tjg. [Timothy Grant]
--
http://mail.python.org/mailman/listinfo/python-list
Trouble with rpdb2 and winpdb debuggers in embedded Python script
Having some trouble getting rpdb2 and winpdb running properly with Python embedded in a C++ project. Our implementation has a number of C++ classes associated with Python classes. I am able to attach to the embedded script with the debugger and the program freezes and waits. However, when I step, next or go with the debugger, it instantly gives control back to C++ and doesn't step nicely through the python. Similarly, if I set a breakpoint, the program pauses momentarily but then doesn't break properly in the debugger. Just wondering if anyone had encountered anything similar, or had an idea what we are doing wrong. Thanks, Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
On 2008-07-25, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > Because usually if a program *prompts* the user to enter input (and that > was what I read from the OP's post), one has to deal with pseudo > terminals, not with stdin/out. > >>> If interaction is required, the OP might consider using >>> pexpect. >> >> Pexpect is a good option, but it's just an automation layer on >> top of the same facilities that subprocess provides. > > AFAIK it's more than that. I'm not an expert on pseudo terminals, but > AFAIK setting using module pty isn't possible using subprocess. You're right. I forgot that pexect uses a pty. You could use a pty with the subprocess module, but it's a hassle to set up. -- Grant Edwards grante Yow! The PINK SOCKS were at ORIGINALLY from 1952!! visi.comBut they went to MARS around 1953!! -- http://mail.python.org/mailman/listinfo/python-list
Re: object persistency, store instances relationship externally
Thanks Fredrik, It helped a lot and this is really an amazing this I have discovered today. :-)) -- http://mail.python.org/mailman/listinfo/python-list
Re: POP3 - Using poplib only shows the first few hundred messages in the mailbox
On Jul 25, 1:18 pm, SteveC <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to use POP3_SSL class of the poplib module to read email
> from my gmail account. I can connect just fine using the example
> herehttp://www.python.org/doc/lib/pop3-example.html
>
> import getpass, poplib
>
> M = poplib.POP3('localhost')
> M.user(getpass.getuser())
> M.pass_(getpass.getpass())
> numMessages = len(M.list()[1])
> for i in range(numMessages):
> for j in M.retr(i+1)[1]:
> print j
>
> That is the above sample code from the python doc. While everything
> works fine, the problem is that when I use the list() function it only
> returns about 400 messages starting from the beginning of my inbox. I
> have probably 10,000 emails in my gmail account. I don't see any pop3
> object functions to "move" around the inbox or anything of the like.
>
> Could someone point me in the right direction? I'm sure there must be
> something simple I am missing.
>
That's a lot of emails! :-)
I had a quick look at poplib.py and I couldn't see any limit in the
code itself. Perhaps it's the gmail server that's doing it. Can you
retrieve the later messages, eg have you tried M.retr(500)? If you can
then you could just try retrieving messages beyond what M.list() says
until it says there's no such message.
--
http://mail.python.org/mailman/listinfo/python-list
Re: calling source command within python
Jie <[EMAIL PROTECTED]> writes:
> i'm having trouble executing os.system('source .bashrc') command
> within python, it always says that source not found and stuff. Any
> clue?
There's no 'source' program; it's a shell builtin. Even if there was, it
almost certainly wouldn't do what you want. The .bashrc file is supposed
to contain settings applying to the current shell, and os.system() runs in
a subshell, so the settings will only affect that shell.
If you're doing this to set environment variables, try modifying os.environ
instead.
Glenn
--
http://mail.python.org/mailman/listinfo/python-list
Re: interpreter vs. compiled
Tim Roberts wrote: And I'm saying you are wrong. There is NOTHING inherent in Python that dictates that it be either compiled or interpreted. That is simply an implementation decision. The CPython implementation happens to interpret. The IronPython implementation compiles the intermediate language to native machine language. Well, actually there are some Python language features which make static compilation to machine code difficult. PyPy and Shed Skin have to impose some restrictions on dynamism to make efficient compilation feasible. The big problem is "hidden dynamism", where the code looks static, but at run time, some external piece of code replaces a function or adds an unexpected attribute to what looked like a simple object or function in the defining module. In CPython, everything is a general object internally, and all the names are resolved over and over again at run time by dictionary lookup. This is simple, but there's a sizable speed penalty. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
How to find processes from Python
Is there a way how to find out running processes?E.g. how many Appache's processes are running? Thanks for help. BB. -- http://mail.python.org/mailman/listinfo/python-list
Python program as daemon?
Is it possible to run a Python program as daemon? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Histogram and \lambda parameter of the laplacian curve.
Thanks everyone for your earlier help. I have to plot a histogram of values lets say [0.5,0.6,0.8,0.9].I guess the histogram would show an exponential decay ie, the laplacian curve. I need to find the \lambda parameter of this curve . So please tell me if it be done through http://matplotlib.sourceforge.net/and are there any other libraries which can be used. Thanks in advance. Aditya -- http://mail.python.org/mailman/listinfo/python-list
Re: Python program as daemon?
Johny <[EMAIL PROTECTED]>: > Is it possible to run a Python program as daemon? You can write daemons in basically any language out there. -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Quesion on class.attributes assignment
Hi, I am reading a python program now but I just cannot understand how the values of class attributes are assigned and changed. Here is the original code url: http://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html Here I am concerned is how attribute matrix.rows is changed. Through pdb debugging, I can see in line 97, once "self.solutions = set((val,))" is executed, cell.row and matrix.rows will be updated. But I did not see any assignment codes here. How could this change happen then? Thanks a lot! John # http://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html #!/usr/bin/env python # # sudoku-solver version 3 # # Some ideas ripped-off from: # http://www.linuxjournal.com/article/8729 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440542 # Pavol solver in # http://groups.google.com/group/comp.lang.python/browse_thread/thread/5087890f4c5e770d # # Copyright 2005 Ago, # But you are free to copy, reuse, modify and distribute the code as you see fit from copy import deepcopy class DeadEnd(Exception): pass class Matrix: def __init__(self, input): self.rows = [[] for i in range(9)] self.cols = [[] for i in range(9)] self.submatrices = [[] for i in range(9)] self.cells = [Cell(i,self) for i in range(81)] self.subdiagonals = [self.rows[i][j+i%3] for i in range(9) for j in [0,3,6]] input = [s not in '-*' and int(s) or 0 for s in input if s in '0123456789-*'] for cell,val in zip(self.cells, input): if val: cell.setSolution(val) def solve(self): #Brute-force solver self.solveByReduction() lensols=[(len(c.solutions),c.index) for c in self.cells if not c.solved] if not lensols: return True unsolved = min(lensols)[1] solutions = list(self.cells[unsolved].solutions) for s in solutions: tmpmatrix = deepcopy(self) try: tmpmatrix.cells[unsolved].setSolution(s) if tmpmatrix.solve(): self.update(tmpmatrix) return True except DeadEnd: pass def solveByReduction(self): while True: self.changed = False for c in self.cells: c.solve() for c in self.subdiagonals: c.skim() if not self.changed: break def update(self, m): self.rows, self.cols, self.submatrices, self.cells, self.subdiagonals=\ m.rows, m.cols, m.submatrices, m.cells, m.subdiagonals def __str__(self): return "\n".join(str([c for c in row ])[1:-1] for row in self.rows) class Cell: def __init__(self, index, matrix): self.solved = False self.matrix = matrix self.index = index self.row = matrix.rows[index/9] self.col = matrix.cols[index%9] self.submatrix = matrix.submatrices[((index/9)/3)*3+(index%9)/3] self.row.append(self) self.col.append(self) self.submatrix.append(self) self.solutions = set(range(1,10)) def solve(self): if self.solved: return if len(self.solutions) == 1: self.setSolution(self.solutions.pop()) else: sol = set() for cells in [self.row, self.col, self.submatrix]: otherSolutions = self.cells2sols(cells, self) sol |= (self.solutions - otherSolutions) if len(sol) > 1: raise DeadEnd() if sol: self.setSolution(sol.pop()) def skim(self): submatrix = set(self.submatrix) for r in (set(self.row), set(self.col)): subset1 = submatrix - r subset2 = r - submatrix solsNotIn1 = set(range(1,10)) - self.cells2sols(subset2) solsNotIn2 = set(range(1,10)) - self.cells2sols(subset1) for c in subset1: c.delSolutions(solsNotIn1) for c in subset2: c.delSolutions(solsNotIn2) def setSolution(self, val): self.solved = True self.solutions = set((val,)) self.matrix.changed = True for other in self.row+self.col+self.submatrix: if other is self: continue if other.solutions == self.solutions: raise DeadEnd() other.delSolutions(self.solutions) def delSolutions(self, val): if not self.solved and val & self.solutions: self.solutions -= val self.matrix.changed = True if not self.solutions: raise DeadEnd() def __repr__(self): return str(self.solved and list(self.solutions)[0] or list(self.solutions)) @staticmethod def cells2sols(cells, exclude=None): return set(s for c in cells for s in c.solutions if c is not exclude) if __name__ == "__main__": input =''' 1,0,0,0,0,0,0,0,2 0,9,0,4,0,0,0,5,0 0,0,6,0,0,0,7,0,0 0,5,0,9,0,3,0,0,0 0,0,0,0,7,0,0,0,0 0,0,0,8,5,0,0,4,0 7,0,0,0,0,0,6,0,0 0,3,0,0,0,9,0,8,0 0,0,2,0,0,0,0,0,1 ''' matrix = Matrix(input) matrix.solve() print matrix # http:
Re: Python program as daemon?
Johny wrote: Is it possible to run a Python program as daemon? Sure -- see http://code.activestate.com/recipes/66012/ for an example (and some useful stuff in the comments.) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to figure out if the platform is 32bit or 64bit?
norseman wrote: > > I need to know if I'm running on 32bit or 64bit ... so far I haven't > > come up with how to get this info via python. sys.platform returns > > what python was built on ... but not what the current system is. > > > > I thought platform.uname() or just platform.processor() would have > > done it, but python returns an empty string on windows. Any ideas? If just for Windows I believe you can use the "PROCESSOR_ARCHITECTURE" environment variable -- at least on NT-based Windows versions. Values are x86 (32-bit), IA64 (64-bit) and AMD64 (64-bit). Here is a "platinfo.py" module that might help if you need to do this for other platforms: http://svn.openkomodo.com/openkomodo/view/openkomodo/trunk/util/platinfo.py Cheers, Trent -- Trent Mick trentm at activestate.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python program as daemon?
On Jul 25, 8:37 pm, Johny <[EMAIL PROTECTED]> wrote: > Is it possible to run a Python program as daemon? > Thanks Here is an example on how to run a Python script as a Unix daemon: http://svn.plone.org/svn/collective/bda.daemon/trunk/bda/daemon/daemon.py Basically it forks twice and redirects open file descriptors to /dev/ null. On Windows, 'daemons' are called services. You can write Windows services in Python using the Pywin32 extension. See Mark Hammond's book for an explanation. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - what module to use?
On Jul 25, 8:13 am, Pierre Dagenais <[EMAIL PROTECTED]> wrote: > What is the easiest way to draw to a window? I'd like to draw something > like sine waves from a mathematical equation. > Newbie to python. For mathematica equations, NumPy and matplotlib is probably the best option. I prefer to embed matplotlib in wxPython. wxAgg is an excellent backend. For more general 2D graphics, there are several options, including: - pygame (uses SDL) - aggdraw module - pycairo - pyopengl - wxPython's device context (ditto for other GUI libraries) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Kay Schluehr wrote: On 25 Jul., 03:01, Terry Reedy <[EMAIL PROTECTED]> wrote: Inserting self into the arg list is trivial. Mindlessly deciding correctly whether or not to insert 'self.' before 'a' is impossible when 'a' could ambiguously be either an attribute of self or a local variable of f. Or do you and/or Jordan plan to abolish local variables for methods? tjr This isn't the problem Jordan tries to address. It's really just about `self` in the argument signature of f, not about its omission in the body. That is not at all how I read him, so I will let him respond if he wishes. The main problem moving a function from module scope to class scope is prefixing the proper variables. Adding a param name, whether 'self', 's', 'this', or whatever, is trivial and hardly worth the ink. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Nikolaus Rath wrote: Terry Reedy <[EMAIL PROTECTED]> writes: Torsten Bronger wrote: Hallöchen! > And why does this make the implicit insertion of "self" difficult? I could easily write a preprocessor which does it after all. class C(): def f(): a = 3 Inserting self into the arg list is trivial. Mindlessly deciding correctly whether or not to insert 'self.' before 'a' is impossible when 'a' could ambiguously be either an attribute of self or a local variable of f. Or do you and/or Jordan plan to abolish local variables for methods? Why do you think that 'self' should be inserted anywhere except in the arg list? AFAIU, the idea is to remove the need to write 'self' in the arg list, not to get rid of it entirely. Because you must prefix self attributes with 'self.'. If you do not use any attributes of the instance of the class you are making the function an instance method of, then it is not really an instance method and need not and I would say should not be masqueraded as one. If the function is a static method, then it should be labeled as one and no 'self' is not needed and auto insertion would be a mistake. In brief, I assume the OP wants 'self' inserted in the body because inserting it only in the parameter list and never using it in the body is either silly or wrong. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Suresh Pillai wrote: I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I ask applies more generally than my specific case. I would greatly appreciate general feedback in terms of computing and of course considerations specific to implementation in Python. The nodes in my network may be ON or OFF. The network starts off with all nodes in the OFF state. I loop through the nodes. For each node that is OFF, I consider some probability of it turning ON based on the states of its neighbours. I MUST GO THROUGH ALL NODES BEFORE DECIDING WHICH ONES TO TURN ON. If the nodes do not have to be processed in any particular order, then you could keep them either in a dict, with the value being either On or Off (True,False)(plus connection data) or a pair of sets, one for On and one for Off. The advantage of the dict is that the items would be fixed and only their values would change, but you needlessly scan through On items. The advantage of the set pair is that you only scan through Off items but have to move some from Off to On. I will not guess which would be faster over a complete run, or how this will compare with using lists. tjr -- http://mail.python.org/mailman/listinfo/python-list
Easier way to get the "here" path?
I have to go into these convulsions to get the directory that the
script is in whenever I need to use relative paths. I was wondering if
you guys have a better way:
from os.path import dirname, realpath, abspath
here = dirname(realpath(abspath(__file__.rstrip("c"
In particular, this takes care of the case of symlinked, compiled
scripts, which is fairly common at my workplace, and I imagine in many
*nix evironments.
An illustration:
$echo "print __file__" > symlinks/path.py
$ln -s symlinks/path.py
$python
>>> import path
path.py
>>> reload(path)
path.pyc
>>> path.__file__
'path.pyc'
>>> path.__file__.rstrip("c")
'path.py'
>>> from os.path import abspath, realpath
>>> realpath(path.__file__.rstrip("c"))
'/home/bgolemon/python/symlinks/path.py'
>>> realpath(abspath(path.__file__.rstrip("c")))
'/home/bgolemon/python/symlinks/symlinks/path.py'
--
http://mail.python.org/mailman/listinfo/python-list
SimpleJson is slow .... is there any C Compiled version ?
Hello All, I have created an API which fetches some data from the database. I am using simplejson to encode it and return it back. Now the problem is that, this API is being called for millions of times in a sequence. I ran a profiler and saw that most of the time is consumed in encoding my database results in to json. So I was just wondering is there any C compiled version of simplejson is available? or any help regarding this issue would be appreciated. Thank you, Sanket -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling external program from within python
Michael Tobis wrote: For some reason os.popen is deprecated in favor of the more verbose subprocess.Popen, but this will work for a while. As explained in http://www.python.org/dev/peps/pep-0324/ subprocess consolidated replaced several modules and functions (popen*, system, spawn*, ???)with better security, exception handling, and flexibility. The deprecated modules are gone in 3.0, so the OP might want to start with subprocess now. -- http://mail.python.org/mailman/listinfo/python-list
Histogram of floating point values.
Hello folks, I have a list say data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50] i am trying to plot histogram of these values i have installed numpy and matplotlib and this is what i am doing* import numpy import pylab from numpy import * from pylab import * input_hist=array(data) pylab.hist(input_hist,bins=0.1) and this is the error that i am getting *(array([], dtype=int32), array([ 0.5]), )* does this mean that i cannot plot a histogram of floating point values ? or is there a way around Thanks in advance Aditya -- http://mail.python.org/mailman/listinfo/python-list
Re: Quesion on class.attributes assignment
John Hanks wrote: Hi, I am reading a python program now but I just cannot understand how the values of class attributes are assigned and changed. Here is the original code url: http://agolb.blogspot.com/2006/01/sudoku-solver-in-python.html Here I am concerned is how attribute matrix.rows is changed. Through pdb debugging, I can see in line 97, once "self.solutions = set((val,))" is executed, cell.row and matrix.rows will be updated. But I did not see any assignment codes here. How could this change happen then? Thanks a lot! Newsreaders do not typically have line counters. I presume you are referring to def setSolution(self, val): self.solved = True self.solutions = set((val,)) self.matrix.changed = True for other in self.row+self.col+self.submatrix: if other is self: continue if other.solutions == self.solutions: raise DeadEnd() other.delSolutions(self.solutions) First, self is an instance of the class, so these are all instance attributes, not class attributes. The difference is important. As to your question, the last line mutates (modifies, updates) each member of self.row, self.col, and self.submatrix that is not self itself. The method delSolutions has the actual target rebindings. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 6:41 am, Jordan <[EMAIL PROTECTED]> wrote: > Hi everyone, > > I'm a big Python fan who used to be involved semi regularly in > comp.lang.python (lots of lurking, occasional posting) but kind of > trailed off a bit. I just wrote a frustration inspired rant on my > blog, and I thought it was relevant enough as a wider issue to the > Python community to post here for your discussion and consideration. > > This is not flamebait. I love Python, and I'm not out to antagonise > the community. I also realise that one of the issues I raise is way > too ingrained to be changed now. I'd just like to share my thinking on > a misstep in Python's guiding principles that has done more harm than > good IMO. So anyway, here's the post. > > I've become utterly convinced that at least one criticism leveled at > my favourite overall programming language, Python, is utterly true and > fair. After quite a while away from writing Python code, I started > last night on a whim to knock up some code for a prototype of an idea > I once had. It's going swimmingly; the Python Image Library, which I'd > never used before, seems quick, intuitive, and with the all the > features I need for this project. As for Python itself, well, my heart > still belongs to whitespace delimitation. All the basics of Python > coding are there in my mind like I never stopped using them, or like > I've been programming in this language for 10 years. > > Except when it comes to Classes. I added some classes to code that had > previously just been functions, and you know what I did - or rather, > forgot to do? Put in the 'self'. In front of some of the variable > accesses, but more noticably, at the start of *every single method > argument list.* This cannot be any longer blamed as a hangover from > Java - I've written a ton more code, more recently in Python than in > Java or any other OO language. What's more, every time I go back to > Python after a break of more than about a week or so, I start making > this 'mistake' again. The perennial justification for this 'feature' > of the language? That old Python favourite, "Explicit is better than > implicit." > It's damn useful for scoping. You can look in the body of your method and tell whether you are accessing local variables or instance variables. I'm a great fan of self and I'm afraid you're flogging a dead horse on that one. Your point about rich comparison (at least the == != problem) is fair. This one is fixed in Python 3 though I believe. Michael Foord -- http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Histogram of floating point values.
aditya shukla wrote: Hello folks, I have a list say data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50] i am trying to plot histogram of these values i have installed numpy and matplotlib and this is what i am doing* import numpy import pylab from numpy import * from pylab import * input_hist=array(data) pylab.hist(input_hist,bins=0.1) and this is the error that i am getting _*(array([], dtype=int32), array([ 0.5]), )*_ does this mean that i cannot plot a histogram of floating point values ? or is there a way around Ask the pylab (matplotlib?) people what their error message means. -- http://mail.python.org/mailman/listinfo/python-list
Re: Histogram of floating point values.
On Fri, Jul 25, 2008 at 5:02 PM, aditya shukla <[EMAIL PROTECTED]> wrote: > Hello folks, > > I have a list say > > data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50] > > i am trying to plot histogram of these values > > i have installed numpy and matplotlib and this is what i am doing* > import numpy > import pylab > from numpy import * > from pylab import * > > input_hist=array(data) > pylab.hist(input_hist,bins=0.1) > and this is the error that i am getting > > (array([], dtype=int32), array([ 0.5]), ) > > > does this mean that i cannot plot a histogram of floating point values ? or > is there a way around the 'bins' argument to pylab.hist() is supposed to be an integer or a list of the bins' lower edges. The default value is 10, more than that gives smaller bins, as one would expect. Take a look at the pylab.hist documentation (you can do 'print pylab.hist.__doc__' from the command interpreter). You should have no problem plotting a hist of floats. Try this: import numpy import pylab from numpy import * from pylab import * data=[0.99,0.98,0.98,0.98,0.97,0.93,0.92,0.92,0.83,0.66,0.50,0.50] input_hist=array(data) pylab.hist(input_hist) pylab.show() The last line will display the actual histogram. See the difference pylab.show and pylab.ion functions. In the future, it is advisable to post these questions to the matplotlib or the numpy/scipy users mailing lists. Kurt > > Thanks in advance > > Aditya > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On 25 Jul, 22:37, Terry Reedy <[EMAIL PROTECTED]> wrote: > Kay Schluehr wrote: > > > > This isn't the problem Jordan tries to address. It's really just about > > `self` in the argument signature of f, not about its omission in the > > body. > > That is not at all how I read him, so I will let him respond if he > wishes. The main problem moving a function from module scope to class > scope is prefixing the proper variables. Adding a param name, whether > 'self', 's', 'this', or whatever, is trivial and hardly worth the ink. He wrote the following of relevance: "I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.*" And rounding off with this on the subject: "The problem is that the explicit requirement to have self at the start of every method is something that should be shipped off to the implicit category." I guess the desire is to have Java-like behaviour: when defining a method, which must typically be done in the class definition in Java (unless they've enhanced that area in the past few years), you never write a "this" parameter in the method signature, but you are free to qualify instance attribute accesses with "this". Personally, I liked the Modula-3-inspired requirement for "self" in Python, but I can see how a reminder of what it is in every method signature (defined within a class) might be regarded as overly explicit. Paul -- http://mail.python.org/mailman/listinfo/python-list
An Attempt to download and install traits - to a Windows XP
Using >easy_install -v -f http://code.enthought.com/enstaller/eggs/source enthought.traits The result is: ... many lines ... copying enthought\traits\ui\tests\shell_editor_test.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\table_editor_color_test.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\table_editor_focus_bug.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\table_editor_test.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\table_editor_test2.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\table_list_editor_test.py -> build\lib.win32-2.5\enthought\traits\ui\tests copying enthought\traits\ui\tests\tree_editor_test.py -> build\lib.win32-2.5\enthought\traits\ui\tests running build_ext error: Setup script exited with error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing "-c mingw32" to setup.py. C:\Documents and Settings\cjw\Desktop>python Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. I would welcome any guidance. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function editing with Vim throws IndentError
On Jul 24, 9:32 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED] central.gen.new_zealand> wrote: > In message > <[EMAIL PROTECTED]>, Matimus > wrote: > > > On Jul 24, 2:54 am, Lawrence D'Oliveiro <[EMAIL PROTECTED] > > central.gen.new_zealand> wrote: > >> In message > >> <[EMAIL PROTECTED]>, > > >> Matimus wrote: > >> > That isn't the standard. With that setup tabs will show up as 4 > >> > spaces, and still confuse you. > > >> Why should that be confusing? The most common tab-stop setting is 4 > >> columns. > > > A tab character is specified as 8 spaces. > > Specified by whom? The most common setting these days is 4 columns. All argument about specification aside, Python interprets a tab character as equivalent to 8 spaces. If you are treating tabs as equivalent to 4 spaces in your python code it will cause IndentationError exceptions to be raised. If you set 'tabstop' to 4 in Vim all of the blocks of code indented using 4 spaces will be aligned with code indented with tabs. That is obviously problematic. Setting 'et' will fix the problem of inserting tabs, but does nothing to adjust the way tabs are displayed. Vim has a feature 'softtabspace'/'sts' which is used to modify the way tabs are inserted without modifying the way they are displayed. If you are writing python code using Vim and you intend to indent using 4 spaces (as recommended by pep8), the best practice I have found is to `set sw=4 ts=8 sts=4 et`. Matt -- http://mail.python.org/mailman/listinfo/python-list
tcp socket problem
I'm writing a tcp client that grabs data from a server at 32hz. But the connection drops exactly one minute after it's opened. I can get data from the server fine for the first 60s, and then the connection goes dead. What's going on? -- http://mail.python.org/mailman/listinfo/python-list
