Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
Daniel:
> What do you get with:
> import thread
> thread.start_new_thread(int, ('1',2))
>
This results in the same error message:
thread.error: can't start new thread
Aahz:
> You probably want to start by figuring out which threading library is
> being used -- Python normally wants Posix threads, but IIRC, that's not
> the default on HP-UX, and you may need to fix the build process to use
> Posix.
You're probably right, but I'm lost here, since I'm neither a *nix nor
a HP-UX expert in building software from source. I'm used to
"configure; make; make install", which usually works well on other
platforms...
Henning
--
http://mail.python.org/mailman/listinfo/python-list
strip char from list of strings
I have the following list: [ 'test\n', test2\n', 'test3\n' ] I want to remove the '\n' from each string in place, what is the most efficient way to do that ? Regards, Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
On 17 Mai, 04:22, Grant Edwards wrote: > On 2009-05-17, Thomas Vogel wrote: > > > I'm currently have the problem that I try to read UDP messages from > > multiple sockets in parallel. So let's say I get UDP packets from the > > same IP on the ports 2000, 2001, 2002,... > > Is there any reason you can't do it the easy way by using > select? > > http://docs.python.org/library/select.html > > -- > Grant The only honest answer would be that I'm totaly unfamiliar with select and also the documentation I found wasn't able to clear the picture. So are there examples of using select together with sockets available? Kind regards Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
Hi! On Mon, 18 May 2009 06:19:01 -0700 (PDT) [email protected] wrote: [...] > The only honest answer would be that I'm totaly unfamiliar with select > and also the documentation I found wasn't able to clear the picture. > So are there examples of using select together with sockets available? If you want to write something related to networks you should know this book: http://www.kohala.com/start/unpv12e.html Also found at http://www.amazon.de/UNIX-Network-Programming-Sockets-Networking/dp/013490012X MfT Guido -- http://mail.python.org/mailman/listinfo/python-list
Re: Seeking old post on developers who like IDEs vs developers who like simple languages
Thanks. Your observations would make good comments on the original blog message that I'm seeking. Do you have a link to that blog? -- http://mail.python.org/mailman/listinfo/python-list
identifying live hosts on a network
HI I am new to python and am having trouble coming up with a script that idenifies all the live hosts on my network. thanks Hunter -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
On Mon, May 18, 2009 at 3:30 PM, Laurent Luce wrote: > > I have the following list: > > [ 'test\n', test2\n', 'test3\n' ] > > I want to remove the '\n' from each string in place, what is the most > efficient way to do that ? > What have you tried so far? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
Jack Trades wrote: I'm wondering if there's an easy way to do a 'svn commit' on a directory from Python. http://pysvn.tigris.org/ and in particular: http://pysvn.tigris.org/docs/pysvn_prog_guide.html TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
Jack Trades wrote:
> Originally I had the 'data' directory in the same directory as the cgi
> scripts and was using os.system("svn commit"), however I kept running
> into weird bugs with this method. So I moved the data directory out
> of the cgi directory and plan to use a separate repository. So is
> there a prefered way to commit this directory to a subversion
> repository from a Python script?
Subversion has Python bindings, but for a friendlier interface have a look
at http://pysvn.tigris.org/
An example from the docs at
http://pysvn.tigris.org/docs/pysvn_prog_guide.html:
Commit changes to the repository
import pysvn
# edit the file foo.txt
f = open('./examples/pysvn/foo.txt', 'w')
f.write('Sample versioned file via python\n')
f.close()
# checkin the change with a log message
client = pysvn.Client()
client.checkin(['./examples/pysvn'], 'Corrected spelling of python in foo.txt')
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
In message , Jack Trades wrote: > On May 19, 12:26 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: > >> In message <2904e7de-0a8d-4697-9c44- >> >> [email protected]>, Jack Trades wrote: >> > Originally I had the 'data' directory in the same directory as the cgi >> > scripts and was using os.system("svn commit"), however I kept running >> > into weird bugs with this method. >> >> What bugs? > > I'm not 100% sure, but I think it had to do with executable > permissions on the cgi scripts. Possibly your CGI scripts are running as some user like "nobody", which doesn't have the right access to the files/directories. Changing APIs won't help here. -- http://mail.python.org/mailman/listinfo/python-list
Re: issue: Permissions in odfpy
Through the python code, chmod 400 happy hacking. Krishnakant. On Tue, 2009-05-19 at 12:21 +0530, shruti surve wrote: > hey, > i am using odfpy and generating spreadsheet in open office..but > nobody should modify the file..so can anybody tell me how can we give > permissions (read only) to spreadsheet in odfpy??..i have change the > properties of my normal open office spreadsheet file and made it read > only..n also extracted it..but in conteny.xml also i am not finding > any property which can be used in odfpy...so please give me some > solution.. > > > regards > shruti surve -- http://mail.python.org/mailman/listinfo/python-list
Re: Context manager, atexit processing, and PEP 3143 DaemonContext.close
Ben Finney wrote: > MRAB writes: > >> Gunter Henriksen wrote: >> > If there is a function which triggers a one-shot switch, I like to >> > have a way to find out if it has already been triggered, I prefer >> > to have the function tell me if it triggered the switch or not, but >> > I would not want that to be by raising an exception. >> >> The 'file' class also has a 'closed' method, so that's a good model >> to follow. > > Yes, I find that convincing as well. (I might prefer it to instead > answer the question âis it currently open?â, i.e. an âopenedâ > query, but that makes for more awkward English than âclosedâ.) > In the general case you might have an object which you create then open as an explicit step. Later you close it explicitly before it is discarded. In that case methods 'opened' and 'closed' both make sense but mean different things. For a file object, where construction always opens the file, an opened method (if it existed) should always return true so isn't useful. Or in other words, I take the word 'opened' as meaning 'has been opened' which is not the same as 'is currently open'. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
problems with PyML: ImportError: No module named _ckernel
Hello,
I am trying PyML ( http://PyML.sf.net ) with little success.
I tried to do the test: from PyML.demo import pyml_test
but all I got is that backtrace:
Traceback (most recent call last):
File "./test.py", line 2, in
from PyML.demo import pyml_test
File "/usr/src/PyML-0.7.2/PyML/__init__.py", line 4, in
from PyML.containers import *
File "/usr/src/PyML-0.7.2/PyML/containers/__init__.py", line 3, in
VectorDataSet = __import__('PyML.containers.vectorDatasets',
fromlist=['']).VectorDataSet
File "PyML/containers/vectorDatasets.py", line 4, in
from PyML.containers.baseDatasets import WrapperDataSet, BaseVectorDataSet
File "PyML/containers/baseDatasets.py", line 4, in
from PyML.containers import ker
File "PyML/containers/ker.py", line 6, in
from ext import ckernel
File "PyML/containers/ext/ckernel.py", line 7, in
import _ckernel
ImportError: No module named _ckernel
Actually, in the directory
/usr/lib/python2.5/site-packages/PyML/containers/ext/
there is the file _ckernel.so
and, if I do:
import _ckernel
in that directory, no problem happens.
Actually, there is a report for this bug:
http://sourceforge.net/forum/forum.php?thread_id=2167098&forum_id=393034
but nobody answered.
any ideas?
thanks in advance,
Francesco Stablum
--
The generation of random numbers is too important to be left to chance
- Robert R. Coveyou
--
http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
On Mon, May 18, 2009 at 8:30 PM, Laurent Luce wrote: > > I have the following list: > > [ 'test\n', test2\n', 'test3\n' ] > > I want to remove the '\n' from each string in place, what is the most > efficient way to do that ? > > Regards, > > Laurent > -- > http://mail.python.org/mailman/listinfo/python-list > >>> s = [ 'test\n', test2\n', 'test3\n' ] >>> [i.strip() for i in s] ['test', 'test2', 'test3'] >>> map(str.strip, s) ['test', 'test2', 'test3'] I'm not sure which one of these is more efficient, but it probably doesn't really matter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Seeking old post on developers who like IDEs vs developers who like simple languages
Chris Rebert wrote: On the other hand there are developers who much prefer to keep things light-weight and simple. Would it be fair to say the first type tends to congregate in herds, particularly in corporate IT departments, while the latter tends to operate on a more individual basis? That would certainly explain Lisp hackers! *(ducks)* Oh, come on! Corporate environments are usually positive towards Lisp hackers, and Lisp hackers are OTOH very positive towards corporate environments. That's why they repel. -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
> Laurent Luce (LL) wrote: >LL> I have the following list: >LL> [ 'test\n', test2\n', 'test3\n' ] >LL> I want to remove the '\n' from each string in place, what is the >LL> most efficient way to do that ? I suppose you mean you have lists similar to the one given because with a list of 3 elements efficiency is a non-issue unless you do something stupid or repeat the operation thousands of times. Even with a list of 1000 elements efficiency isn't very important. In fact you should worry about efficiency only after there are signs that there might be a problem. Secondly, in Python you cannot remove a character from a string in place if that means modifying the string. Strings are immutable. So let us suppose you mean that the list should stay in place, i.e if L is the list that after the operation L is still the same object but L[i] has become a string that has the value of the old L[i] with the '\n' removed. Let us also suppose that in the original list every element has exactly one '\n' at the end. Then a simple loop should do it. The enumerate comes to mind as you need both the index and the value of each element: for i, value in enumerate(L): L[i] = value[:-1] But it looks a bit silly to me to refer to the same list element as both value and L[i]. So maybe the old-fashioned way is more clear: for i in range(len(L)): L[i] = L[i][:-1] I think the choice is a matter of taste. You can do some timing experiments yourself to see if there are significant differences, but I wouldn't expect so. -- Piet van Oostrum URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Context manager, atexit processing, and PEP 3143 DaemonContext.close
Gunter Henriksen writes: > If there is a function which triggers a one-shot switch, I like to > have a way to find out if it has already been triggered, I prefer to > have the function tell me if it triggered the switch or not, but I > would not want that to be by raising an exception. In this case, though, we're talking about a class intended to implement the context manager API (in addition to other API). So, following your argument above, we might expect a generic context manager object to be able to tell us whether we're currently inside that context or not. Does such a thing exist? -- \ “If consumers even know there's a DRM, what it is, and how it | `\ works, we've already failed.” —Peter Lee, Disney corporation, | _o__) 2005 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On Mon, 18 May 2009 02:27:06 -0700, jeremy wrote:
> Let me clarify what I think par, pmap, pfilter and preduce would mean
> and how they would be implemented.
[...]
Just for fun, I've implemented a parallel-map function, and done a couple
of tests. Comments, criticism and improvements welcome!
import threading
import Queue
import random
import time
def f(arg): # Simulate a slow function.
time.sleep(0.5)
return 3*arg-2
class PMapThread(threading.Thread):
def __init__(self, clients):
super(PMapThread, self).__init__()
self._clients = clients
def start(self):
super(PMapThread, self).start()
def run(self):
while True:
try:
data = self._clients.get_nowait()
except Queue.Empty:
break
target, where, func, arg = data
result = func(arg)
target[where] = result
class VerbosePMapThread(threading.Thread):
def __init__(self, clients):
super(VerbosePMapThread, self).__init__()
print "Thread %s created at %s" % (self.getName(), time.ctime())
def start(self):
super(VerbosePMapThread, self).start()
print "Thread %s starting at %s" % (self.getName(), time.ctime())
def run(self):
super(VerbosePMapThread, self).run()
print "Thread %s finished at %s" % (self.getName(), time.ctime())
def pmap(func, seq, verbose=False, numthreads=4):
size = len(seq)
results = [None]*size
if verbose:
print "Initiating threads"
thread = VerbosePMapThread
else:
thread = PMapThread
datapool = Queue.Queue(size)
for i in xrange(size):
datapool.put( (results, i, f, seq[i]) )
threads = [PMapThread(datapool) for i in xrange(numthreads)]
if verbose:
print "All threads created."
for t in threads:
t.start()
# Block until all threads are done.
while any([t.isAlive() for t in threads]):
if verbose:
time.sleep(0.25)
print results
return results
And here's the timing results:
>>> from timeit import Timer
>>> setup = "from __main__ import pmap, f; data = range(50)"
>>> min(Timer('map(f, data)', setup).repeat(repeat=5, number=3))
74.999755859375
>>> min(Timer('pmap(f, data)', setup).repeat(repeat=5, number=3))
20.490942001342773
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
python3 module for dbus ?
Hello Sorry if this is not the right newsgroup for python modules, I found no other appropriate one. I would like to start a project in python and I think it would be good to start with python3.0, but I need tu use glib, dbus, wxWidgets and postgresql. Do you know if I can get dbus bindings for python3 and glib bindings for python3 ? Or could I use them otherwise (like without the modules) ? Thank you Timothy Madden -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On 2009-05-19, Steven D'Aprano wrote: > On Mon, 18 May 2009 02:27:06 -0700, jeremy wrote: > >> Let me clarify what I think par, pmap, pfilter and preduce would mean >> and how they would be implemented. > [...] > > Just for fun, I've implemented a parallel-map function, and done a couple > of tests. Comments, criticism and improvements welcome! My only comment would be that your "slow function" might not be a very simulation for the general-case, since it uses time.sleep() which releases the GIL: > def f(arg): # Simulate a slow function. > time.sleep(0.5) > return 3*arg-2 Any Python function that isn't calling a library function written in C that releases the GIL won't show any speedup will it? I don't have a multi-core machine to try it on, but what happens when you replace your "slow function" code with something that actually burns CPU using pure-Python code instead of blocking on a timer in the OS? -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On 19 May, 00:32, Steven D'Aprano wrote: > On Mon, 18 May 2009 02:27:06 -0700, jeremy wrote: > > However I *do* actually want to add syntax to the language. I think that > > 'par' makes sense as an official Python construct - we already have had > > this in the Occam programming language for twenty-five years. The reason > > for this is ease of use. I would like to make it easy for amateur > > programmers to exploit natural parallelism in their algorithms. For > > instance somebody who wishes to calculate a property of each member from > > a list of chemical structures using the Python Daylight interface: with > > my suggestion they could potentially get a massive speed up just by > > changing 'for' to 'par' or 'map' to 'pmap'. (Or map with a parallel > > keyword argument set as suggested). At present they would have to > > manually chop up their work and run it as multiple processes in order to > > achieve the same - fine for expert programmers but not reasonable for > > people working in other domains who wish to use Python as a utility > > because of its fantastic productivity and ease of use. > > There seems to be some discrepancy between this, and what you wrote in > your first post: > > "There would be no locking and it would be the programmer's > responsibility to ensure that the loop was truly parallel and correct." > > So on the one hand, you want par to be utterly simple-minded and to do no > locking. On the other hand you want it so simple to use that amateurs can > mechanically replace 'for' with 'par' in their code and everything will > Just Work, no effort or thought required. But those two desires are > inconsistent. > > Concurrency is an inherently complicated problem: deadlocks and race > conditions abound, and are notoriously hard to reproduce, let alone > debug. If par is simple, and does no locking, then the programmer needs > to worry about those complications. If you want programmers to ignore > those complications, either (1) par needs to be very complicated and > smart, to do the Right Thing in every case, or (2) you're satisfied if > par produces buggy code when used in the fashion you recommend. > > The third option is, make par really simple and put responsibility on the > user to write code which is concurrent. I think that's the right > solution, but it means a simplistic "replace `for` with `par` and your > code will run faster" will not work. It might run faster three times out > of five, but the other two times it will hang in a deadlock, or produce > incorrect results, or both. > > -- > Steven Hi Steven, > you want it so simple to use that amateurs can mechanically replace 'for' > with 'par' in their > code and everything will Just Work, no effort or thought required. Yes I do want the par construction to be simple, but of course you can't just replace a for loop with a par loop in the general case. This issue arises when people use OpenMP: you can take a correct piece of code, add a comment to indicate that a loop is 'parallel', and if you get it wrong the code with no longer work correctly. With my 'par' construct the programmer's intention is made explicit in the code, rather than by a compiler directive and so I think that is clearer than OpenMP. As I wrote before, concurrency is one of the hardest things for professional programmers to grasp. For 'amateur' programmers we need to make it as simple as possible, and I think that a parallel loop construction and the dangers that lurk within would be reasonably straightforward to explain: there are no locks to worry about, no message passing. The only advanced concept is the 'sync' keyword, which would be used to rendezvous all the threads. That would only be used to speed up certain codes in order to avoid having to repeatedly shut down and start up gangs of threads. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On 19 May, 03:31, Carl Banks wrote: > On May 18, 1:52 pm, [email protected] wrote: > > > As I understand it the reason for the GIL is to prevent problems with > > garbage collection in multi-threaded applications. > > Not really. It's main purpose to prevent context switches from > happening in the middle of some C code (essentially it makes all C > code a "critical" section, except when the C code explicitly releases > the GIL). This tremendously simplifies the task of writing extension > modules, not to mention the Python core. > > > Without it the > > reference count method is prone to race conditions. However it seems > > like a fairly crude mechanism to solve this problem. Individual > > semaphores could be used for each object reference counter, as in > > Java. > > Java doesn't use reference counting. > > Individual locks on the refcounts would be prohibitively expensive in > Python, a cost that Java doesn't have. > > Even if you decided to accept the penalty and add locking to > refcounts, you still have to be prepared for context switching at any > time when writing C code, which means in practice you have to lock any > object that's being accessed--that's in addition to the refcount lock. > > I am not disagreeing with your assessment in general, it would be > great if Python were better able to take advantage of multiple cores, > but it's not as simple a thing as you're making it out to be. > > Carl Banks Hi Carl, > I am not disagreeing with your assessment in general, it would be > great if Python were better able to take advantage of multiple cores, > but it's not as simple a thing as you're making it out to be. Thanks for explaining a few things to me. So it would seem that replacing the GIL with something which allows better scalability of multi-threaded applications, would be very complicated. The paper by Jesse Nolle which I referenced in my original posting includes the following: "In 1999 Greg Stein created a patch set for the interpreter that removed the GIL, but added granular locking around sensitive interpreter operations. This patch set had the direct effect of speeding up threaded execution, but made single threaded execution two times slower." Source: http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/ That was ten years ago - do you have any idea as to how things have been progressing in this area since then? Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Best library to make XSLT 2.0 transformation
Hi there, I need to make xml transformation using XSLT 2.0 (since i want to use the powerful tag to produce multiple files). In your experience, which kind of library out there is better? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Context manager, atexit processing, and PEP 3143 DaemonContext.close
Duncan Booth wrote: Ben Finney wrote: MRAB writes: Gunter Henriksen wrote: If there is a function which triggers a one-shot switch, I like to have a way to find out if it has already been triggered, I prefer to have the function tell me if it triggered the switch or not, but I would not want that to be by raising an exception. The 'file' class also has a 'closed' method, so that's a good model to follow. Yes, I find that convincing as well. (I might prefer it to instead answer the question “is it currently open?�, i.e. an ‘opened’ query, but that makes for more awkward English than ‘closed’.) In the general case you might have an object which you create then open as an explicit step. Later you close it explicitly before it is discarded. In that case methods 'opened' and 'closed' both make sense but mean different things. For a file object, where construction always opens the file, an opened method (if it existed) should always return true so isn't useful. Or in other words, I take the word 'opened' as meaning 'has been opened' which is not the same as 'is currently open'. Equally you could say that "closed" means "has been closed", which is not the same as "is currently closed". Unusual, but possible! :-) Borrowing from the string class, it would be "isopen" (like "isdigit", probably influenced by C), although these days we would write "is_open". -- http://mail.python.org/mailman/listinfo/python-list
Re: Best library to make XSLT 2.0 transformation
wdveloper wrote: > Hi there, > > I need to make xml transformation using XSLT 2.0 (since i want to use > the powerful tag to produce multiple files). > In your experience, which kind of library out there is better? XSLT is a standard, so if you find a library that implements it, there shouldn't be much differences. Having said that, these days lxml2 is the craze, and it contains xslt-processing. It would be my first (and hopefully last) stop. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
On 2009-05-18, [email protected] wrote: > On 17 Mai, 04:22, Grant Edwards wrote: >> On 2009-05-17, Thomas Vogel wrote: >> >> > I'm currently have the problem that I try to read UDP messages from >> > multiple sockets in parallel. So let's say I get UDP packets from the >> > same IP on the ports 2000, 2001, 2002,... >> >> Is there any reason you can't do it the easy way by using >> select? >> >> http://docs.python.org/library/select.html > > The only honest answer would be that I'm totaly unfamiliar > with select and also the documentation I found wasn't able to > clear the picture. So are there examples of using select > together with sockets available? http://www.google.com/search?q=python+select+example http://www.amk.ca/python/howto/sockets/ http://code.activestate.com/recipes/531824/ http://mail.python.org/pipermail/python-list/2001-February/071302.html http://squirl.nightmare.com/medusa/async_sockets.html -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
On May 18, 3:30 pm, Laurent Luce wrote:
> I have the following list:
>
> [ 'test\n', test2\n', 'test3\n' ]
>
> I want to remove the '\n' from each string in place, what is the most
> efficient way to do that ?
>
> Regards,
>
> Laurent
Do you _really_ need to do this in place? If not, the simplest answer
is probably:
>>> x = ['test\n', test2\n', 'test3\n']
>>> x = [s.rstrip('\n') for s in x]
And if what you really want to do is strip off all trailing whitespace
(tabs, spaces, and newlines), then:
>>> x = [s.rstrip() for s in x]
A quick test of 1,000,000 strings of length 27 took less than 0.2
seconds on my PC. Efficiency isn't really much of an issue for most
data sets.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Package problem
> > It is solved in other languages.. for example perl.. and delphi > I don't know much about perl, and even less about delphi, but I am > pretty sure it does not solve the problem of overwriting files from a > package with an installation outside the control of the package > manager. On a sytem a possible solution would be: /usr/lib/python2.5/site-package/foobar <- The os managed one /usr/lib/python2.5/site-package/foobar-2.0 <- The alternatives /usr/lib/python2.5/site-package/foobar-2.1 and using something (in the python interpreter) import foobar (imports the foobar) import foobar requires >= 2.1 (imports foobar 2.1 or above) > > There is no simple solution to the following situation: >- install setuptools from ubuntu -> files get into /usr > (/usr/lib/python2.5/site-packages, etc...) setuptools is the problem;) It tries to do too many things imho. > > Fight it ??? I didn't even get a python interpreter with my operating > > system... You could try: http://download.opensuse.org/repositories/home:/cavallo71:/python-opt/ This is a python interpreter installed under /opt/opt-python-2.7a0. All you have to do is sourcing /opt/opt-python-2.7a0/opt-python-env.sh from a shell and start using the python 2.7 (it's directly from the svn trunk). If you download a python module to generate the rpm for it all you have to do is: $> . /opt/opt-python-2.7a0/opt-python-env.sh $> python setup.py bdist_rpm It will generate a package rpm installable under /opt/python-2.7a0 and won't interfere with the system. I hope this will help, Regards, Antonio -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i use Spread Sheet as Data Store
On Tue, 19 May 2009 10:51:57 +0530 Kalyan Chakravarthy wrote: > Actually my requirement is > in an web application when user enters User name and Password, > back end i needs to check, is it they entered correct user name with > password ( here i want to read the Spread Sheet Data in Python code ), > for this i will keep all the user names and passwords in Google Spread Sheet I can't answer your question about reading Google spreadsheets but I do wonder why you are trying to solve a database problem with a spreadsheet in the first place, especially with all the support Python has for database access. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Package problem
On Tue, May 19, 2009 at 2:45 AM, David Cournapeau wrote: > On Tue, May 19, 2009 at 2:35 PM, David Lyon > wrote: > > On Tue, 19 May 2009 13:53:18 +0900, David Cournapeau > > > wrote: > >> Given that nobody has managed to solve this problem, I doubt you will > >> find a solution. > > > > It is solved in other languages.. for example perl.. and delphi > > I don't know much about perl, and even less about delphi, but I am > pretty sure it does not solve the problem of overwriting files from a > package with an installation outside the control of the package > manager. > > There is no simple solution to the following situation: > - install setuptools from ubuntu -> files get into /usr > (/usr/lib/python2.5/site-packages, etc...) > - install setuptools from sources into /usr: overwrite files from > the python-setuptools debian package, with an updated version which is > not compatible with the packaged one -> every Ubuntu package depending > on setuptools is now broken. Worse, it may not be possible to rollback > to a working situation. > > To make it work, you would have to somehow notify the package > management system about the updated version. But still, the whole > value of a package manager is to have a whole set of packages which > are tested together. Updating packages 'randomly' from 3rd party > sources is inherently against this. > Actually, the point in the package manager is to handle updates and uninstalls gracefully. As long as you stick with using the package manager, everything should be handled fine regardless of whether you're using an official repository, a third party repository (wxPython has its own), or a downloaded debian package (such as with OpenOffice). > > Fight it ??? I didn't even get a python interpreter with my operating > > system... > > > > So there's no possible way I can be against it... > > By fighting, I meant that because OS don't always have uptodate > packages you want to depend on, trying to implement a system to update > the packages is backward. The problem is depending on those recent > libraries in the first place if you want to run on many > configurations. > I think other-David was talking about Windows here. Which is completely irrelevant to this thread about easy_install vs. a system package manager. Mostly, he was just trying to plug for his own project. > > cheers, > > David > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
In article , wrote: >Aahz: >> >> You probably want to start by figuring out which threading library is >> being used -- Python normally wants Posix threads, but IIRC, that's not >> the default on HP-UX, and you may need to fix the build process to use >> Posix. > >You're probably right, but I'm lost here, since I'm neither a *nix nor >a HP-UX expert in building software from source. I'm used to >"configure; make; make install", which usually works well on other >platforms... Try finding a usergroup/list for HP, you will probably have better luck there. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "In 1968 it took the computing power of 2 C-64's to fly a rocket to the moon. Now, in 1998 it takes the Power of a Pentium 200 to run Microsoft Windows 98. Something must have gone wrong." --/bin/fortune -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
On Mon, 18 May 2009 06:19:01 -0700 (PDT), [email protected] wrote: On 17 Mai, 04:22, Grant Edwards wrote: On 2009-05-17, Thomas Vogel wrote: > I'm currently have the problem that I try to read UDP messages from > multiple sockets in parallel. So let's say I get UDP packets from the > same IP on the ports 2000, 2001, 2002,... Is there any reason you can't do it the easy way by using select? http://docs.python.org/library/select.html -- Grant The only honest answer would be that I'm totaly unfamiliar with select and also the documentation I found wasn't able to clear the picture. So are there examples of using select together with sockets available? You might find Twisted easier to use correctly than the select module. You can find some basic Twisted/UDP documentation here: http://twistedmatrix.com/projects/core/documentation/howto/udp.html You can trivially change the first example to handle multiple sockets - just add more reactor.listenUDP calls. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
PYTHONPATH on Windows XP module load problem
Hi, I have the following problem using python on windows. I crated a binary extension called pymsgque.dll on windows. The same extension works fine on UNIX/Linux. The problem is on Windows. The build is no problem but python is not able to load this extension with import pymsgque and create the following error: Traceback (most recent call last): File "server.py", line 13, in import pymsgque ImportError: No module named pymsgque [31906 refs] the PYTHONPATH variable has the directory of pymsgque.dll location the build of python and the pymsgque extension was done using > Microsoft Visual C++ Express Edition it seems that I missing something mfg Andreas Otto -- http://mail.python.org/mailman/listinfo/python-list
Re: identifying live hosts on a network
In article <[email protected]>, wrote: > >I am new to python and am having trouble coming up with a script that >idenifies all the live hosts on my network. First you need to define what constitutes a "live host". -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "In 1968 it took the computing power of 2 C-64's to fly a rocket to the moon. Now, in 1998 it takes the Power of a Pentium 200 to run Microsoft Windows 98. Something must have gone wrong." --/bin/fortune -- http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
On May 19, 3:46 am, Duncan Booth wrote:
> Jack Trades wrote:
> > Originally I had the 'data' directory in the same directory as the cgi
> > scripts and was using os.system("svn commit"), however I kept running
> > into weird bugs with this method. So I moved the data directory out
> > of the cgi directory and plan to use a separate repository. So is
> > there a prefered way to commit this directory to a subversion
> > repository from a Python script?
>
> Subversion has Python bindings, but for a friendlier interface have a look
> athttp://pysvn.tigris.org/
>
> An example from the docs athttp://pysvn.tigris.org/docs/pysvn_prog_guide.html:
>
> Commit changes to the repository
>
> import pysvn
> # edit the file foo.txt
> f = open('./examples/pysvn/foo.txt', 'w')
> f.write('Sample versioned file via python\n')
> f.close()
> # checkin the change with a log message
> client = pysvn.Client()
> client.checkin(['./examples/pysvn'], 'Corrected spelling of python in
> foo.txt')
>
> --
> Duncan Boothhttp://kupuguy.blogspot.com
Thanks that's what I was looking for.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
On May 19, 3:53 am, Lawrence D'Oliveiro wrote: > In message > [email protected]>, Jack Trades wrote: > > On May 19, 12:26 am, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > > >> In message <2904e7de-0a8d-4697-9c44- > > >> [email protected]>, Jack Trades wrote: > >> > Originally I had the 'data' directory in the same directory as the cgi > >> > scripts and was using os.system("svn commit"), however I kept running > >> > into weird bugs with this method. > > >> What bugs? > > > I'm not 100% sure, but I think it had to do with executable > > permissions on the cgi scripts. > > Possibly your CGI scripts are running as some user like "nobody", which > doesn't have the right access to the files/directories. Changing APIs won't > help here. Thanks for the help, I'll have to look into that further. If that is the case, would setuid be appropriate here? Or is there a better way to give the script the appropriate permissions? The only thing that baffles me is that the script works before a commit and only sometimes after a commit, if it were an access problem wouldn't it fail before the commit as well? -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
[email protected] wrote: "In 1999 Greg Stein created a patch set for the interpreter that removed the GIL, but added granular locking around sensitive interpreter operations. This patch set had the direct effect of speeding up threaded execution, but made single threaded execution two times slower." Source: http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/ That was ten years ago - do you have any idea as to how things have been progressing in this area since then? The slowdown may be less severe, but known attempts to replace, rather than merely remove, GIL slow down single thread execution. Otherwise, GIL wouild be gone. No one has been willing to maintain a multi-thread fork/branch. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i use Spread Sheet as Data Store
D'Arcy J.M. Cain wrote: On Tue, 19 May 2009 10:51:57 +0530 Kalyan Chakravarthy wrote: Actually my requirement is in an web application when user enters User name and Password, back end i needs to check, is it they entered correct user name with password ( here i want to read the Spread Sheet Data in Python code ), for this i will keep all the user names and passwords in Google Spread Sheet I can't answer your question about reading Google spreadsheets but I do wonder why you are trying to solve a database problem with a spreadsheet in the first place, especially with all the support Python has for database access. Hardly even a database problem. OP only needs a dict mapping username to passwd. Of course, that could grow... An issue not touched on is that passwords should *not* be kept in plaintext form. Hence the data store should be written by program and not hand-edited. With a small dict kept in memory, a pickle might work fine. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i use Spread Sheet as Data Store
On Tue, 19 May 2009 09:50:18 -0400 Terry Reedy wrote: > D'Arcy J.M. Cain wrote: > > I can't answer your question about reading Google spreadsheets but I do > > wonder why you are trying to solve a database problem with a > > Hardly even a database problem. OP only needs a dict mapping username > to passwd. Of course, that could grow... s/could/will/ > An issue not touched on is that passwords should *not* be kept in > plaintext form. Hence the data store should be written by program and I hear you but I'm not so sure that that is an absolute. There are many applications that allow you to have your password emailed to you. For something with low risk that's perfectly acceptable. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: PYTHONPATH on Windows XP module load problem
Andreas Otto wrote: Hi, I have the following problem using python on windows. I crated a binary extension called pymsgque.dll on windows. The same extension works fine on UNIX/Linux. The problem is on Windows. The build is no problem but python is not able to load this extension with import pymsgque and create the following error: Traceback (most recent call last): File "server.py", line 13, in import pymsgque ImportError: No module named pymsgque [31906 refs] the PYTHONPATH variable has the directory of pymsgque.dll location the build of python and the pymsgque extension was done using > Microsoft Visual C++ Express Edition it seems that I missing something mfg Andreas Otto Does this help? http://pyfaq.infogami.com/is-a-pyd-file-the-same-as-a-dll -- http://mail.python.org/mailman/listinfo/python-list
Re: Annoying feedparser issues
John Nagle writes: > This really isn't the fault of the "feedparser" module, but it's > worth mentioning. > > I have an application which needs to read each new item from a feed > as it shows up, as efficiently as possible, because it's monitoring multiple > feeds. I want exactly one copy of each item as it comes in. > > In theory, this is easy. Each time the feed is polled, pass in the > timestamp and ID from the previous poll, and if nothing has changed, > a 304 status should come back. > > Results are spotty. It mostly works for Reuters. It doesn't work > for Twitter at all; Twitter updates the timestamp even when nothing changes. > So items are routinely re-read. (That has to be costing Twitter a huge > amount of bandwidth from useless polls.) > > Some sites have changing feed etags because they're using multiple > servers and a load balancer. These can be recognized because the same > etags will show up again after a change. > > Items can supposedly be unduplicated by using the "etag" value. > This almost works, but it's tricker than one might think. On some feeds, > an item might go away, yet come back in a later feed. This happens with > news feeds from major news sources, because they have priorities that > don't show up in RSS. High priority stories might push a low priority story > off the feed, but it may come back later. Also, every night at 00:00, some > feeds like Reuters re-number everything. The only thing that works reliably > is comparing the story text. > > John Nagle I can't really offer much help, but I feel your pain. I had to write something of a similar system for a large company once and it hurt. They mixed different formats with different protocols and man it was something in the end. The law of fuzzy inputs makes this stuff tough. It may help to create a hash from the first x number of bytes of the article text. Then cache all the hashes in a local dbm-style database. We used berkely, but it doesn't really matter. Whatever way you can generate and store a keyed signature will allow you to do a quick look up and see if you've already processed that article. -- http://mail.python.org/mailman/listinfo/python-list
Re: Package problem
On Tue, 19 May 2009 15:45:42 +0900, David Cournapeau wrote: > There is no simple solution to the following situation: >- install setuptools from ubuntu... When I have a ubuntu system I will try it > But still, the whole > value of ..(python).. is to have a whole set of packages which > are tested together. Updating packages 'randomly' from 3rd party > sources is inherently against this. Well I presume pypi goes a long way to offering this... I've used easy_install a few hundred times manually now and I've noticed some incorrect outcomes. For example, downloading a package marked debian into my windows system... and wondering why it didn't work for most packages... it seems to work quite well though.. I think the issue is really that if we can do tests and count test results.. we'll probably get a lot further than we have in the past. We seem to be at the 85% mark... next stop should be 95% or at least some known and measurable number... I'm fully agreeing it can get better... David -- http://mail.python.org/mailman/listinfo/python-list
pyparsing question: single word values with a double quoted string every once in a while
I want to parse a log that has entries like this:
[2009-03-17 07:28:05.545476 -0500] rprt s=d2bpr80d6 m=2 mod=mail
cmd=msg module=access rule=x_dynamic_ip action=discard attachments=0
rcpts=1
routes=DL_UK_ALL,NOT_DL_UK_ALL,default_inbound,firewallsafe,mail01_mail02,spfsafe
size=4363 guid=291f0f108fd3a6e73a11f96f4fb9e4cd hdr_mid=
qid=n2HCS4ks025832 subject="I want to interview you" duration=0.236
elapsed=0.280
the keywords will not always be the same. Also differing log levels
will provide a different mix of keywords.
This is good enough to get the majority of cases where there is a
keyword, a "=" and then a value with no spaces:
Group(Word(alphas + "+_-.").setResultsName("keyword") + Suppress
(Literal ("=")) + Optional(Word(printables)))
Sometimes there is a subject, which is a quoted string. That is easy
enough to get with this:
dblQuotedString(ZeroOrMore(Word(printables) ) )
My problem is combining them into one expression. Either I wind up
with just the subject or I wind up with they keywords and their
values, one of which is:
subject, '"I'
which is clearly not what I want.
Do I scan each line twice, first looking for quotes ?
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
Re: Advanced Python books?
On May 18, 3:04 pm, kj wrote: > I have read a couple of "learn Python"-type books, and now I'm > looking for some more advanced books on Python, something analogous > to "Effective Java" or "High-Order Perl". I've only been able to > find "Advanced Python 3 Programming Techniques", which, as far as > I can tell, is only available as a "Kindle Book". (Since I won't > be buying a Kindle for another few decades, this is not an option > for me.) > > I tried out "Dive into Python", because I was told that it was > written for people with prior programming experience. It's an OK > book, but I don't find that it is much more advanced than pretty > much any other "learn Python" book I've seen. > > Basically I'm looking for a book that assumes that one has the > basics of the language down, and instead focuses on standard problems > of software development, such as application architecture and > design, prototyping, debugging, profiling and performance-tuning, > testing, packaging/distribution, extending/embedding, threading > and IPC, persistence, etc., and on various prototypical cases such > as command-line utilities, GUI-apps, webapps, database-backed apps, > simulations, etc. > > Granted, it is unlikely that a single book will do justice to all > these areas, but these are the topics I'm now interested in, from > the perspective of Python. > > Any suggestions? > > TIA! > -- > NOTE: In my address everything before the first period is backwards; > and the last period, and everything after it, should be discarded. Hetland's book, "Beginning Python" has a bunch of projects at the end. It also has a chapter on testing, network programming, extending python, packaging and more. They're not in depth, but they give you a taste. Lutz's "Programming Python" has some pretty in depth projects using Tkinter. You might find the Python Cookbook helpful or you could just look at ActiveState's cookbook which is what the book was based on: http://code.activestate.com/recipes/langs/python/ - Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Subversion commit from Python?
Jack Trades wrote: > On May 19, 3:53 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message > >> [email protected]>, Jack Trades wrote: >> > On May 19, 12:26 am, Lawrence D'Oliveiro > > central.gen.new_zealand> wrote: >> >> >> In message <2904e7de-0a8d-4697-9c44- >> >> >> [email protected]>, Jack Trades wrote: >> >> > Originally I had the 'data' directory in the same directory as the >> >> > cgi scripts and was using os.system("svn commit"), however I kept >> >> > running into weird bugs with this method. >> >> >> What bugs? >> >> > I'm not 100% sure, but I think it had to do with executable >> > permissions on the cgi scripts. >> >> Possibly your CGI scripts are running as some user like "nobody", which >> doesn't have the right access to the files/directories. Changing APIs >> won't help here. > > Thanks for the help, I'll have to look into that further. If that is > the case, would setuid be appropriate here? Or is there a better way > to give the script the appropriate permissions? > The only thing that baffles me is that the script works before a > commit and only sometimes after a commit, if it were an access problem > wouldn't it fail before the commit as well? I have had many troubles with SVN + permissions. My recipe is the following: - create (or use) a "subversion"-group - make all users (including e.g. www-data) that shall access the SVN members of this group - chown -R the svn-repository so that it belongs to this group - chmod g+s -R to the svn-repository, so that the sticky group bit is set. THis solves the problems for me usually. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: identifying live hosts on a network
[email protected] escribió: HI I am new to python and am having trouble coming up with a script that idenifies all the live hosts on my network. thanks Hunter I've done this in the past with the great help of nmap: # nmap -sP 192.168.0.0/23 this will find hosts "alive" from 192.168.0.1 to 192.168.1.254 From python, you can use it by saving it's output to a file and then reading or with the help of os.popen. In this case, "alive" means that the hosts with the ip being analyzed responds to ARPs. see the manpage for nmap. Matias. -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
I had a simple loop stripping each string but I was looking for
something concise and efficient. I like the following answer:
x = [s.rstrip('\n') for s in x]
David Stanek wrote:
> On Mon, May 18, 2009 at 3:30 PM, Laurent Luce wrote:
>> I have the following list:
>>
>> [ 'test\n', test2\n', 'test3\n' ]
>>
>> I want to remove the '\n' from each string in place, what is the most
>> efficient way to do that ?
>>
>
> What have you tried so far?
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
Thanks Casey. I like your solution.
Casey Webster wrote:
> On May 18, 3:30 pm, Laurent Luce wrote:
>> I have the following list:
>>
>> [ 'test\n', test2\n', 'test3\n' ]
>>
>> I want to remove the '\n' from each string in place, what is the most
>> efficient way to do that ?
>>
>> Regards,
>>
>> Laurent
>
> Do you _really_ need to do this in place? If not, the simplest answer
> is probably:
>
x = ['test\n', test2\n', 'test3\n']
x = [s.rstrip('\n') for s in x]
>
> And if what you really want to do is strip off all trailing whitespace
> (tabs, spaces, and newlines), then:
>
x = [s.rstrip() for s in x]
>
> A quick test of 1,000,000 strings of length 27 took less than 0.2
> seconds on my PC. Efficiency isn't really much of an issue for most
> data sets.
--
http://mail.python.org/mailman/listinfo/python-list
Re: PYTHONPATH on Windows XP module load problem
MRAB wrote: > Andreas Otto wrote: >> Hi, >> >> I have the following problem using python on windows. >> I crated a binary extension called >> >> pymsgque.dll >> >> on windows. The same extension works fine on UNIX/Linux. >> >> The problem is on Windows. The build is no problem >> but python is not able to load this extension with >> >> import pymsgque >> >> and create the following error: >> >> Traceback (most recent call last): >> File "server.py", line 13, in >> import pymsgque >> ImportError: No module named pymsgque >> [31906 refs] >> >> the PYTHONPATH variable has the directory of >> pymsgque.dll location >> >> the build of python and the pymsgque extension was done using >> > Microsoft Visual C++ Express Edition >> >> it seems that I missing something >> >> mfg >> >> Andreas Otto > > Does this help? > > http://pyfaq.infogami.com/is-a-pyd-file-the-same-as-a-dll Hi, this link is nice but I'm still confused ... 1. on LINUX I create a "pymsgque.so" and I can load this library with "import pymsgque" 2. in WINDOWS, I expect to create a "pymsgque.dll" and do the same as on unix "import pymgque" -> is this behaviour is supported or not ??? 3. the hint with "*.pyd" is totally new to me and I don't know is this the "official" way to use dll's on windows or just a hack which works mfg Andreas Otto -- http://mail.python.org/mailman/listinfo/python-list
Re: Conceptual flaw in pxdom?
On May 19, 6:50 am, Stefan Behnel wrote: > It's pretty easy to write unmaintainable code that uses the DOM API, though. I'm finding that at my own expenses... Why would anybody want to use the DOM? I suppose the main reason is that it is one of the most reliable standards around. It might be more complicated, but that's probably because lots of very smart people thought about it very carefully and it couldn't be made any simpler. And hopefully will stand the test of time. Anyway. Any taker on the original (very python-related rather than DOM related) problem at hand? Manu -- http://mail.python.org/mailman/listinfo/python-list
Re: PYTHONPATH on Windows XP module load problem
Andreas Otto wrote: > 1. on LINUX I create a "pymsgque.so" and I can load this library > with "import pymsgque" > > 2. in WINDOWS, I expect to create a "pymsgque.dll" and do the > same as on unix "import pymgque" > > -> is this behaviour is supported or not ??? > > 3. the hint with "*.pyd" is totally new to me and I don't know > is this the "official" way to use dll's on windows or > just a hack which works The suffix of Python extension has changed over time. It used to be .dll but starting with Python 2.5 only .pyd files are imported. A .pyd file is an ordinary, renamed dll file. Christian -- http://mail.python.org/mailman/listinfo/python-list
I was able to use pyInstaller as a python library
Hello, Everyone. I was able to use pyInstaller as a python library http://moco.sakura.ne.jp/pyInstaller.zip and This library test code is available in http://moco.sakura.ne.jp/pyi_test.zip This library implements only a function to output windows binary. and I don't add the change to the contents of the pyinstaller directory. Thanking you in advance. // Noriyoshi Kamado : [email protected] -- http://mail.python.org/mailman/listinfo/python-list
how to get the spesific line of the text in the clipboard
I want to get the eighth line in the text of the text in the clipboad, but when I call GetClipboardData I only get a string, how can I repair it? thanks a lot. My code is here : try: win32clipboard.OpenClipboard(hWnd) #win32api.Sleep(500) text = win32clipboard.GetClipboardData(win32con.CF_TEXT) #win32clipboard.EmptyClipboard() win32clipboard.CloseClipboard() logging.info(len(text)) return text except Exception, exc: logging.info(exc) ... def get_file_title(filename): f = file(filename) #f = open(filename, encoding='gb2312', mode='w+') title = u"" line_count = 0 for line in f: line_count = line_count + 1 if line_count == 8:
Re: PYTHONPATH on Windows XP module load problem
Andreas Otto wrote: Does this help? http://pyfaq.infogami.com/is-a-pyd-file-the-same-as-a-dll this link is nice but I'm still confused ... 1. on LINUX I create a "pymsgque.so" and I can load this library with "import pymsgque" And my bathroom is covered in wallpaper. 2. in WINDOWS, I expect to create a "pymsgque.dll" and do the same as on unix "import pymgque" Surprise, surprise, surprise. Your expectations do not match reality. Why not expect to copy "pymsgque.so" over to Windows, as long as you are busy expecting things? -> is this behaviour is supported or not ??? 3. the hint with "*.pyd" is totally new to me and I don't know is this the "official" way to use dll's on windows or just a hack which works Yes, this is the official way. The .pyd extension is a way of stating a claim that the code follows the Python C module conventions. Windows has certain conventions about the behavior of .dll files that interfere with making these modules .dlls. In case you are curious about the snarky attitude: (0) You asked a question. (1) You got an informative answer which allowed you to succeed. (2) You then explained what you expect to work; something you _know_ by experience does not work, and ask if it is supported. Up until step 2, I was on your side. To follow with a question asking if something "totally new to you" is "just a hack which works," when your only alternative is the behavior you expected to work leaves me thinking you trust the knowledge you gain from introspection over that from experimentation or research. Further, if you built modules using the suggested method, (writing a setup.py, using "python setup.py build"; "python setup.py install", you would discover, by what I would guess to be your astonishment, that a .pyd file got put in site-packages or wherever. --Scott David Daniels [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Package problem
On Tue, May 19, 2009 at 9:29 PM, A. Cavallo wrote: >> > It is solved in other languages.. for example perl.. and delphi >> I don't know much about perl, and even less about delphi, but I am >> pretty sure it does not solve the problem of overwriting files from a >> package with an installation outside the control of the package >> manager. > > On a sytem a possible solution would be: > > /usr/lib/python2.5/site-package/foobar <- The os managed one > /usr/lib/python2.5/site-package/foobar-2.0 <- The alternatives > /usr/lib/python2.5/site-package/foobar-2.1 > > and using something (in the python interpreter) > > import foobar (imports the foobar) > import foobar requires >= 2.1 (imports foobar 2.1 or above) This does not solve the discussed problem. If you revwrite foobar-2.0 with foobar-2.0 installed from sources, you don't know whether you will break the system. You will most likely do so, because of difference filesystem conventions, for example. And what will happen when you will do apt-get remove foobar-2.0 (on a .deb system) ? Most likely, as the set of files installed from sources are not exactly the same as the set of files installed by dpkg, the uninstall will be broken. Specially in the case of configuration files, or daemon, this may be quite serious. >> >> There is no simple solution to the following situation: >> - install setuptools from ubuntu -> files get into /usr >> (/usr/lib/python2.5/site-packages, etc...) > > setuptools is the problem;) It tries to do too many things imho. The discussion has nothing to do with setuptools, or even python for that matter. The problem is that overwriting files managed by the software management system without its consent is bound to be broken, on any system (including windows). That's why you should avoid installing from sources into the locations managed by the OS, be it /usr for unix, or C:\Windows on windows, etc... David -- http://mail.python.org/mailman/listinfo/python-list
Re: Advanced Python books?
kj schrieb: > I have read a couple of "learn Python"-type books, and now I'm > looking for some more advanced books on Python, ... > Basically I'm looking for a book that assumes that one has the > basics of the language down, and instead focuses on standard problems > of software development, such as application architecture and > design, prototyping, debugging, profiling and performance-tuning, > testing, packaging/distribution, extending/embedding, threading > and IPC, persistence, etc., and on various prototypical cases such > as command-line utilities, GUI-apps, webapps, database-backed apps, > simulations, etc. I think there is no such book. Maybe the Python Cookbook comes near. webapps: I use django, other use turbogears, other even different stuff... There are several books about e.g. django. It would be hard to put all the magic of all web apps into one chapter. GUI-apps: You can use tkinter, qt or gtk again it would be hard to put something useable into one chapter. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- http://mail.python.org/mailman/listinfo/python-list
Re: Conceptual flaw in pxdom?
Emanuele D'Arrigo wrote: > This is all good and dandy and it works, mostly. However, if you look > at the code below for the method __getattr__, it appears to be > attempting to prevent direct access to -any- variable starting with an > underscore. > > def __getattr__(self, key): > if key[:1]=='_': > raise AttributeError, key > > But access isn't actually prevented because __getattr__ is invoked - > only- if an attribute is not found by normal means. So, is it just me > or that little snipped of code either has another purpose or simply > doesn't do the intended job? It doesn't do what you think it does; it is there to prevent "infinite" recursion. Have a look at the complete method: > def __getattr__(self, key): > if key[:1]=='_': > raise AttributeError, key > try: > getter= getattr(self, '_get_'+key) > except AttributeError: > raise AttributeError, key > return getter() If you instantiate the object and try to access the -- non-existent -- attribute yadda __getattr__() will be called with key="yadda" which doesn't start with an underscore and with gettattr(self, "_get_yadda") triggers another __getattr__() call as _get_yadda doesn't exist either. If the check weren't there yet another getattr(self, "_get__get_yadda") call would follow, and so on until the recursion limit is reached. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Which C compiler?
On Mon, 18 May 2009 15:47:41 -0700, norseman wrote: > I suspect that if all python users were in the same room and the > question "Are you NOT happy with python's upgrade requirements?" was > asked you would find most hands in the air. I have said it before - the > current attitude of 'new means we start over' was what nearly destroyed > Apple. Doesn't take joe public long to get tired of constantly > re-buying, re-writing themselves, re-hiring the same people to re-write > the same thing, etc... I dislike the "bleeding edge" aspect of Python culture too, but (as long as everyone ignores Python 3.0) it's not really something which hurts me in my daily life. *Not* using Python would hurt, though. I'm on Linux though, and use no third-party modules which haven't already been filtered by Debian's maintainers. I don't know if that's the reason, but my applications rarely or never break. So I'm not quite sure what happened in your case ... /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get the spesific line of the text in the clipboard
zhouhaifeng wrote:
I want to get the eighth line in the text of the text in the clipboad,
but when I call GetClipboardData
I only get a string, how can I repair it?
thanks a lot.
My code is here :
try: win32clipboard.OpenClipboard(hWnd)
#win32api.Sleep(500)
text = win32clipboard.GetClipboardData(win32con.CF_TEXT)
#win32clipboard.EmptyClipboard()
win32clipboard.CloseClipboard()
logging.info(len(text))
return text
except Exception, exc:
logging.info(exc)
[snip]
Split the string into lines and take the eighth line (at index 7). I've
limited the number of splits to 8 because I'm not interested in any of
the following lines:
line = text.split("\r\n", 8)[7]
--
http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
On May 18, 6:19 am, [email protected] wrote: > On 17 Mai, 04:22, Grant Edwards wrote: > > > On 2009-05-17, Thomas Vogel wrote: > > > > I'm currently have the problem that I try to read UDP messages from > > > multiple sockets in parallel. So let's say I get UDP packets from the > > > same IP on the ports 2000, 2001, 2002,... > > > Is there any reason you can't do it the easy way by using > > select? > > >http://docs.python.org/library/select.html > > > -- > > Grant > > The only honest answer would be that I'm totaly unfamiliar with select > and also the documentation I found wasn't able to clear the picture. > So are there examples of using select together with sockets available? > My two cents on this issue is that you should stick with asyncore for now and just figure out how to debug better what's going on. I understand the rationale behind the alternatives--there are certainly advantages (even in debugging) to using something closer to the metal, like select, or in using something that might be a better abstraction, like Twisted. But really, if you look at the source code for asyncore, it's just a thin layer on top of select.select, and the entire module is under 600 lines of code. Asyncore is much maligned, and there are some legitimate beefs with it, but it does well, for the most part, what it intends to do, which is to solve some of the more difficult, or at least tedious, problems with regards to dealing with select.select. My fear is that if you try to do this without asyncore, via select, you'll end up reinventing lots of asyncore with lots of your own bugs. I have less fear about going higher in the stack, except that it just puts another layer on top of the problem, and I think the issue you're dealing with is fairly low-level. So my suggestion is to figure out a good debugging strategy, either by getting a bit more familiar with asyncore internals (with a debugger, print statements, analysis, etc.), or by better using system tools (like snoop, truss, etc.) to see what's happening at the I/O level, or both. Good luck! Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
On Tue, 19 May 2009 10:25:35 +0200, Piet van Oostrum wrote: >> Laurent Luce (LL) wrote: > >>LL> I have the following list: > >>LL> [ 'test\n', test2\n', 'test3\n' ] > >>LL> I want to remove the '\n' from each string in place, what is the >>LL> most efficient way to do that ? > > I suppose you mean you have lists similar to the one given because with > a list of 3 elements efficiency is a non-issue unless you do something > stupid or repeat the operation thousands of times. Even with a list of > 1000 elements efficiency isn't very important. In fact you should worry > about efficiency only after there are signs that there might be a > problem. > > Secondly, in Python you cannot remove a character from a string in place > if that means modifying the string. Strings are immutable. So the best way is probably to make sure the '\n's do not end up in the list in the first place. I suspect that is often more elegant too. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Conceptual flaw in pxdom?
Emanuele D'Arrigo wrote: > On May 19, 6:50 am, Stefan Behnel wrote: >> It's pretty easy to write unmaintainable code that uses the DOM API, >> though. > > I'm finding that at my own expenses... > > Why would anybody want to use the DOM? I suppose the main reason is > that it is one of the most reliable standards around. It might be more > complicated, but that's probably because lots of very smart people > thought about it very carefully and it couldn't be made any simpler. > And hopefully will stand the test of time. Sorry to say so, but that's nonsense. DOM is not complicated because it contains anything superior - the reason (if any) is that it is formulated as language-agnostic as possible, with the unfortunate result it is rather clumsy to use in all languages. Additionally, it *attempts* to unify APIs in browsers, unfortunately it is only moderately successful. APIs such as ElementTree don't try to burden themselves with the language-agnosticism, and thus are much more powerful. And no, I don't think being language-agnostic is a virtue in an API. Simply because this can never really be reached, and then is questionable anyway. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get the spesific line of the text in the clipboard
I want to get the eighth line in the text of the text in the clipboad,
but when I call GetClipboardData
I only get a string, how can I repair it?
[snip]
Split the string into lines and take the eighth line (at index 7). I've
limited the number of splits to 8 because I'm not interested in any of
the following lines:
line = text.split("\r\n", 8)[7]
Strings have a .splitlines() method that makes this a little more
elegant:
line = text.splitlines()[7]
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
Re: DOM implementation
Hello Paul, sorry for the long delay, I was trying to wrap my mind around DOM and Events implementations... On May 15, 7:08 pm, Paul Boddie wrote: > Another implementation is probably a good thing, though, since I don't > trust my own interpretation of the specifications. ;-) Tell me about it. In general I like the work the W3C is doing, but some things could use a little less freedom and a little more clarity. =) But then again, maybe it's for the best to leave things as they are so that we can figure it out for ourselves. > > Why shouldn't the listeners be stored directly on the EventTarget? > > One reason for this might well be due to the behaviour of libxml2 and > libxml2dom: if I visit the same node in a document twice, obtaining a > node instance each time, these two instances will be different; Mmmm I don't know the specifics of libxml... are you saying that once the object tree is created out of an XML file, requesting twice the same node object -does not- result in a pointer to the same instance in memory? How's that possible? > The libxml2dom.svg module has classes which inherit from EventTarget. And what does the EventTarget inherit from? Or are those classes inheriting from both Nodes and EventTargets? > What I've tried to do is to make submodules to address particular > formats and document models. I think the issue to consider there is that the DOM does not restrict a document from being a mush-up of multiple formats. I.e. it should be possible to have XHTML and SVG tags in the same document. As long as those modules work at element/tag level and do not obstruct each other I think you are on the right track! > I think that if I were to expose an event-capable DOM, other than that > provided for SVG, I would just have a specific submodule for that > purpose. Ultimately I found it moderately easier to modify pxdom with the intention of releasing "pxdome", a fork of pxdom. Monkey-patching pxdom seemed to be a little too tricky and prone to error to create a separate module. > > > One of my tests tries to exercise the code, but I might be doing it > > > all completely wrong: > > >https://hg.boddie.org.uk/libxml2dom/file/91c0764ac7c6/tests/svg_event... I had a more in-depth look after having spent the weekend trying to wrap my head around all sorts of implementation issues. My understanding, also after a few exchanges in the [email protected] mailing-list, is that initialization of an event can happen wherever you feel like doing it, except in Document.createEvent(). I.e. it could be a method on the event itself or an external function. In your code however, I believe the initialization method should be initMouseEventNS() rather then initEventNS() and the namespace for DOM 3 Events should be -None-. Between the two implementations the first one seems to be more aligned with the DOM documentation. The way I'm doing it is that I invoke Document.createEvent(eventType), I initialize the resulting event in part manually and in part with type-related default settings and I finally use Document.pxdomTriggerEvent(event) to create a propagation path and iterate through its targets. I.e.: def _trigger_DOMSubtreeModified(target): relevantTargetTypes = (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE, Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE) if target.nodeType not in relevantTargetTypes: return if target.ownerDocument: event = target.ownerDocument.createEvent("MutationEvent") event._target = target target.ownerDocument.pxdomEventDefaultInitNS(None, "DOMSubtreeModified", event) target.ownerDocument.pxdomTriggerEvent(event) Notice that I'm currently keeping this function as a loose function but it could very well be placed as a method in the Document class or in each relevant classes. I'm not sure why one option would be better than all others and the DOM doesn't specify it. The dispatch of the event to each target on the propagation path is also a matter of implementation. In the discussion in www-dom three options have emerged: 1) the Document node establishes the propagation path and iterates through the targets listed to dispatch the event to each 2) an unspecified, external object does the same job 3) the propagation path is established, stored on the event and each event target is responsible for recursively dispatching the event to the next target if propagation hasn't been stopped. Apparently an earlier version of Mozilla's Gecko used option 3 but they eventually switched to option 1. Again, it's unclear in what circumstances to use one option or the other. What I don't know at this time is how to merge all this with the specific file formats such as SVG and HTML. I.e. in an SVG example, do I create a GroupElement(Element) class and I override the Document.createElement() method to create an instance of it any time a element is found in the input file? Or do I first create an application-neutral DOM tree out of the input file a
Re: how to get the spesific line of the text in the clipboard
Tim Chase wrote:
I want to get the eighth line in the text of the text in the
clipboad, but when I call GetClipboardData
I only get a string, how can I repair it?
[snip]
Split the string into lines and take the eighth line (at index 7). I've
limited the number of splits to 8 because I'm not interested in any of
the following lines:
line = text.split("\r\n", 8)[7]
Strings have a .splitlines() method that makes this a little more elegant:
line = text.splitlines()[7]
I thought it split only on "\n". Turns out it can handle "\r\n" too!
Yay! :-)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Best library to make XSLT 2.0 transformation
On Tue, 2009-05-19 at 13:42 +0200, Diez B. Roggisch wrote: > wdveloper wrote: > > > Hi there, > > > > I need to make xml transformation using XSLT 2.0 (since i want to use > > the powerful tag to produce multiple files). > > In your experience, which kind of library out there is better? > > XSLT is a standard, so if you find a library that implements it, there > shouldn't be much differences. > > Having said that, these days lxml2 is the craze, and it contains > xslt-processing. It would be my first (and hopefully last) stop. > > Diez While I firmly believe lxml is the best python XML library available, being built on libxml2 means that it only supports XSLT 1.0. As far as I know, if you want 2.0 support, you still need to be using one of the Java XSLT processors. -- John Krukoff Land Title Guarantee Company -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP reading on multiple sockets
[email protected] wrote: On 17 Mai, 04:22, Grant Edwards wrote: On 2009-05-17, Thomas Vogel wrote: I'm currently have the problem that I try to read UDP messages from multiple sockets in parallel. So let's say I get UDP packets from the same IP on the ports 2000, 2001, 2002,... Is there any reason you can't do it the easy way by using select? http://docs.python.org/library/select.html -- Grant The only honest answer would be that I'm totaly unfamiliar with select and also the documentation I found wasn't able to clear the picture. So are there examples of using select together with sockets available? Kind regards Thomas You could also try Twisted : http://twistedmatrix.com/trac/ Best, Gabriel -- http://mail.python.org/mailman/listinfo/python-list
Re: Which C compiler?
Jorgen Grahn wrote: On Mon, 18 May 2009 15:47:41 -0700, norseman wrote: I suspect that if all python users were in the same room and the question "Are you NOT happy with python's upgrade requirements?" was asked you would find most hands in the air. I have said it before - the current attitude of 'new means we start over' was what nearly destroyed Apple. Doesn't take joe public long to get tired of constantly re-buying, re-writing themselves, re-hiring the same people to re-write the same thing, etc... I dislike the "bleeding edge" aspect of Python culture too, but (as long as everyone ignores Python 3.0) it's not really something which hurts me in my daily life. *Not* using Python would hurt, though. agreed! emphatically so I'm on Linux though, and use no third-party modules which haven't already been filtered by Debian's maintainers. I don't know if that's the reason, but my applications rarely or never break. So I'm not quite sure what happened in your case ... Linux, me too. MY apps, same. Coupling to vendor apps - busted. /Jorgen I cannot speak for the OP, but I have run into version problems as a result of dealing with purchased applications that use python as the (or one of the allowed) scripting languages for user written tweaks. As an example I'll use fictitious Company-One that released 9.1 which had no python. Then they released 9.2 which came with python 2.4 and then they released 9.3 which came with python 2.5(.1) plus the other languages like VBA that have been there all along. A program NOT using Company-One hooks but rather just the python itself (as in a small scientific calculator for use 'on the side') which was written in 2.4 will not run on 2.5. Who knows why. (The first error noted had to do with version miss-match.) It's these types of inconsistencies that are annoying. Since the place I work converted to Company-One's 9.3 and someone fixed the calculator to run on 2.5, I left the research into what might be the actual problem in a file somewhere. I believe it was a circular file. :) I have my own calculator so I don't use the other one anyway. :) That scenario is probably the norm for most companies with more than one individual in them who use purchased applications and write in-house 'scripts'. The lack of upward compatibility is always annoying. In all fairness to Python, it is not nearly as bad as VBA when it comes to breaking. VBA quits when the OS version changes, when the VBA version changes, when the VB6 version changes. It also seems to break each time sneeze. :) Whereas when a given version of Python is loaded on both Linux and Windows I can samba a drive and use the same single one and only one file on both OSs at the same time if I wish, with the same certainty. All except the fonts. Three different Window machines all running the same OS release/patches and I get three different results for the same mono spaced font. Go figure. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 module for dbus ?
In article <[email protected]>, Timothy Madden wrote: > >Sorry if this is not the right newsgroup for python modules, I found no >other appropriate one. You're in the right place! >I would like to start a project in python and I think it would be good >to start with python3.0, but I need tu use glib, dbus, wxWidgets and >postgresql. > >Do you know if I can get dbus bindings for python3 and glib bindings for >python3 ? Or could I use them otherwise (like without the modules) ? Sorry, no answers to your questions off-hand, but what's wrong with using 2.x? -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines." --Ralph Waldo Emerson -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about locals()
Thank you all for great explanation on this subject. Maybe a few sentences from these conversations could be added to locals() documentation. I will make double sure myself while using locals() to end up with valid identifiers. Gökhan On Tue, May 19, 2009 at 1:06 AM, Steven D'Aprano < [email protected]> wrote: > Sorry for breaking threading, the original post is not being carried by > my ISP. > > > On Tue, 19 May 2009, Gökhan SEVER wrote: > > Hello, > > > > Could you please explain why locals() allow me to create variables that > > are not legal in Python syntax. Example: locals()['1abc'] = 55. Calling > > of 1abc results with a syntax error. Shouldn't it be better to raise an > > error during the variable creation time? > > No, because it isn't an error to use '1abc' as a dictionary key. > > "locals()['1abc'] = 55" does not create a variable. It creates an object > 55, a string '1abc', and uses that string as the key in a dict with 55 as > the value. > > "locals()['abc'] = 55" does not create a variable either. It does exactly > the same thing as above, except that in this case 'abc' happens to be a > valid identifier. > > "abc = 55" also does not create a variable. What it does is exactly the > same as the above, except that the dictionary key is forced to be a valid > identifier by the parser (or perhaps the lexer): the parser won't accept > 1abc as a valid identifier, so you can't execute "1abc = 55". > > (Almost... there's actually a slight complication, namely that making > changes to locals() inside a function does not work.) > > Python's programming model is based on namespaces, and namespaces are > implemented as dictionaries: so-called "variables" are key/value pairs > inside a dictionary. Just because a dictionary is used as a namespace > doesn't stop it from being used as a dictionary: you can add any keys/ > values which would otherwise be valid. It's still a dictionary, just like > any other dictionary. > > >>> globals()[45] = None > >>> globals() > {'__builtins__': , 45: None, '__name__': > '__main__', '__doc__': None} > > > As for *why* this is done this way, the answer is simplicity of > implementation. Dictionaries don't need to care about what counts as a > valid identifier. Only the lexer/parser needs to care. > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Best library to make XSLT 2.0 transformation
wdveloper wrote: > I need to make xml transformation using XSLT 2.0 (since i want to use > the powerful tag to produce multiple files). > In your experience, which kind of library out there is better? I'm not aware of a Python library that implements XSLT 2.0, although you might want to look around at the XQuery homepage, which links to a number of candidates. That said, if all you want is to generate multiple result documents from a single XSLT, lxml will happily help you if you take a minute to implement a custom XSLT element in Python that just writes an XSLT result to a file. http://codespeak.net/lxml/extensions.html#xslt-extension-elements Stefan -- http://mail.python.org/mailman/listinfo/python-list
Performance java vs. python
On Mon, May 18, 2009 at 5:56 AM, Aahz wrote: > In article , > Ulrich Eckhardt wrote: > >Steve Ferg wrote: > >> > >> On the one hand, there are developers who love big IDEs with lots of > >> features (code generation, error checking, etc.), and rely on them to > >> provide the high level of support needed to be reasonably productive > >> in heavy-weight languages (e.g. Java). > >> > >> On the other hand there are developers who much prefer to keep things > >> light-weight and simple. They like clean high-level languages (e.g. > >> Python) which are compact enough that you can keep the whole language > >> in your head, and require only a good text editor to be used > >> effectively. > > > >This distinction is IMHO not correct. If you took a look at Java, you > would > >notice that the core language syntax is much simpler than Python's. > > That's half-true. The problem is that you have to digest a much bigger > chunk of Java before you can start being productive. Consider how simple > it is to write a non-regex grep in Python. In addition, Python's object > model is simpler than Java's, not even talking about the contortions that > Java's static class model forces you into. I am new to Python. I am slowly realizing that Python might be a better choice when compared to java on the server side. Is there any performance comparison between Java and Python ? For example, if I use the J2EE solution vs. python (Django etc.) on the server side, would one perform better over the other ? -mohan P.S: I have changed the subject line to reflect the new thread > > -- > Aahz ([email protected]) <*> > http://www.pythoncraft.com/ > > "In 1968 it took the computing power of 2 C-64's to fly a rocket to the > moon. > Now, in 1998 it takes the Power of a Pentium 200 to run Microsoft Windows > 98. > Something must have gone wrong." --/bin/fortune > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Import and absolute file names, sys.path including ''... or not
Hi fellows,
I spent quite a time on a malicious issue. I found out that there is a
slight difference on the sys.path content when either executing code
from a shell or from within a script.
This difference is the '' item, which is present in the shell form of
sys.path.
For instance, let's write this code in test.py:
import sys
print sys.path
shell form:
python
Python 2.4.4 (#2, Oct 22 2008, 19:52:44)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
['', other misc stuff] <- sys.path
script form:
python test.py
[other misc stuff] <- sys.path
The '' item is not here.
Problem is, '' is required for absolute path to be properly resolved. In
my code I sometimes have to import file in that way :
__import__('/some/absolute/path')
So the immediate solution is to write this:
if '' not in sys.path:
sys.path.append('') # make sure absolute path are properly resolved
in any case
I'm not a big fan of manipulating sys.path at the begining of my files.
Is there something I'm doing wrong ? Is there a standard/nice way to
support absolute path ? I guess '' is in fact aimed at resolving
relative path from the execution directory...
best regards,
Jean-Michel
--
http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
>> >> On the one hand, there are developers who love big IDEs with lots of >> >> features (code generation, error checking, etc.), and rely on them to >> >> provide the high level of support needed to be reasonably productive >> >> in heavy-weight languages (e.g. Java). >> >> >> >> On the other hand there are developers who much prefer to keep things >> >> light-weight and simple. They like clean high-level languages (e.g. >> >> Python) which are compact enough that you can keep the whole language >> >> in your head, and require only a good text editor to be used >> >> effectively. >> > >> >This distinction is IMHO not correct. If you took a look at Java, you >> would >> >notice that the core language syntax is much simpler than Python's. >> >> That's half-true. The problem is that you have to digest a much bigger >> chunk of Java before you can start being productive. Consider how simple >> it is to write a non-regex grep in Python. In addition, Python's object >> model is simpler than Java's, not even talking about the contortions that >> Java's static class model forces you into. > > > I am new to Python. I am slowly realizing that Python might be a better > choice when compared to java on the server side. Is there any performance > comparison between Java and Python ? For example, if I use the J2EE solution > vs. python (Django etc.) on the server side, would one perform better over > the other ? Benchmarks always test for a given feature. The available benchmarks will most likely not test the feature relevant for your particular application simply because there are about a gazillion different ways of using a web framework. So the best you can do is simply test the bottleneck part of your application and see for yourself, otherwise you will be left with comments like "django is used at work because it's faster for us" or "I use j2ee because performance is better for my web app". When it will come to choosing your framework these will help little to none. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Python, Tkinter and popen problem
I have come across a problem that, as I understand all documentation I have found, should not exist. Python version is 2.5.2, Tinker in that package. Linux Slackware 10.2 I went to test os.popen and got mixed answers. 1) IF os.popen opens a command line or command window type THEN the read and writes work as expected 2) IF os.popen opens a Tkinter contained python program THEN the read is not consistant and write to it fails. OK - #1 runs as expected on shell scripts and other programs that were written for the keyboard and redirectors only. (non GUI types) #2 popen sometimes connects to stdout OF the child and sometimes not and has never shown signs of connection to stdin OF child The Tkinter usage has three (3) print statements. Two (2) never show up. One does. The one that does is the exit notice. In the 'child' program; print, sys.stdout.write(string), and os.write(stdout,string) all work for the one that does write back, but none work for the two that do not. Don't get picky on the syntax, the purpose is to get the message across. The print statements are: print "Notice of action" print VariableHavingTextOfAction print "Closing down\n" Yes I added the '\n' to the others - no change. Same loop reads/prints the stdout FROM child in all three cases. All three work fine when Tkinter included program is run 'solo'. Print statements show up in the text (command, whatever) window. The entire Tkinter included program runs normally except for the I/O linkage problem when using os.popen(. or Popen2.popen2 or ... then only third print shows up in text window. Acts as if first two prints were captured but never forwarded to screen. If it was a case of not sending until a system flush() took place then all three lines would appear at the closing. That is NOT happening. Only closing notice appears. The child has a pause expecting a keystroke from the master immediately following the print VariableH... which apparently is never received. This is a case of Python running a Python program that contains Tkinter. So what is going on and what can I do? I want the master to echo the slave's print statements and the slave get the 'continue' character so it will. Today is: 20090519 Versions noted above. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
On Tue, 2009-05-19 at 10:42 -0700, Daniel Fetchinson wrote: > Benchmarks always test for a given feature. The available benchmarks > will most likely not test the feature relevant for your particular > application simply because there are about a gazillion different ways > of using a web framework. So the best you can do is simply test the > bottleneck part of your application and see for yourself, Bingo! there will be hundreds of threads on this mailing list and many others which exactly do that. And it also serves as a great food for those bashing birds who just need a spart to start a flamewar. Till date I have worked with both languages into their core as will as with many libraries for different tasks. Fortunately I have some assessment for web frameworks which is based mostly on my personal experience and partially on some obvious facts. At the outset, I have seen that python's syntax is pritty clean and as some previous mail said on this thread, it needs just a few hours and the language is compact enough to fit in your head. Readers might ask, "so how is this associated with performance boosting etc?" Quite a good question. You see, the scope for making quick and suttle changes in the code should be wide enough and easy to do as wel. Since python has such easy and clean syntax and with the idea of "battries included ", it is much more quicker and easier to tune the application for many things including performance. Since I feel comfortable with the language I am confident enough that my code won't break too much when I try to do some serious alteration to the code. This alteration might now be to change the logic but to improve performance. This is the challenge and python is such a language that manipulating to this level is pritty doable in short period of time. Secondly, Java it seems comes with a lot of bagage which might be the case with python as well. But some how I don't know, python seems to be much light weight then java. May be there are many technical reasons for this and at the web application side it seems to be compact zippi and fast. Again this might be my personal assessment,and specially with database driven application, no language can be absolutely better than the other and as rightly suggested, test it on the bottleneck issues and fine tune that particular part. I have seen many apps migrating from ejb based framework to python, particularly one I remember in pylons and the feedback has been positive. Another thing is that I personally like to use OOP *only* when needed. Java would force me to write classes (add the over doing with static functions ) for every thing I do including a small function just for returning a connection object. This again is a major reason for me to stick to python. In addition python also can do the kind of work, j2ME can do and so I don't think there is any serious reason for choosing java over python. I am currently developing a major application and it is currently using the twisted library for xmlrpc and there is a thin client in pygtk. Right now we are in the process of moving it to turbogears2 and so far performance on both the ends have been good. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On 19 May, 10:24, Steven D'Aprano
wrote:
> On Mon, 18 May 2009 02:27:06 -0700, jeremy wrote:
> > Let me clarify what I think par, pmap, pfilter and preduce would mean
> > and how they would be implemented.
>
> [...]
>
> Just for fun, I've implemented a parallel-map function, and done a couple
> of tests. Comments, criticism and improvements welcome!
>
> import threading
> import Queue
> import random
> import time
>
> def f(arg): # Simulate a slow function.
> time.sleep(0.5)
> return 3*arg-2
>
> class PMapThread(threading.Thread):
> def __init__(self, clients):
> super(PMapThread, self).__init__()
> self._clients = clients
> def start(self):
> super(PMapThread, self).start()
> def run(self):
> while True:
> try:
> data = self._clients.get_nowait()
> except Queue.Empty:
> break
> target, where, func, arg = data
> result = func(arg)
> target[where] = result
>
> class VerbosePMapThread(threading.Thread):
> def __init__(self, clients):
> super(VerbosePMapThread, self).__init__()
> print "Thread %s created at %s" % (self.getName(), time.ctime())
> def start(self):
> super(VerbosePMapThread, self).start()
> print "Thread %s starting at %s" % (self.getName(), time.ctime())
> def run(self):
> super(VerbosePMapThread, self).run()
> print "Thread %s finished at %s" % (self.getName(), time.ctime())
>
> def pmap(func, seq, verbose=False, numthreads=4):
> size = len(seq)
> results = [None]*size
> if verbose:
> print "Initiating threads"
> thread = VerbosePMapThread
> else:
> thread = PMapThread
> datapool = Queue.Queue(size)
> for i in xrange(size):
> datapool.put( (results, i, f, seq[i]) )
> threads = [PMapThread(datapool) for i in xrange(numthreads)]
> if verbose:
> print "All threads created."
> for t in threads:
> t.start()
> # Block until all threads are done.
> while any([t.isAlive() for t in threads]):
> if verbose:
> time.sleep(0.25)
> print results
> return results
>
> And here's the timing results:
>
> >>> from timeit import Timer
> >>> setup = "from __main__ import pmap, f; data = range(50)"
> >>> min(Timer('map(f, data)', setup).repeat(repeat=5, number=3))
> 74.999755859375
> >>> min(Timer('pmap(f, data)', setup).repeat(repeat=5, number=3))
>
> 20.490942001342773
>
> --
> Steven
Hi Steven,
I am impressed by this - it shows the potential speedup that pmap
could give. Although the GIL would be a problem as things for speed up
of pure Python code. Do Jython and Iron Python include the threading
module?
Jeremy
--
http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On 17 May, 13:37, [email protected] wrote: > On 17 May, 13:05, [email protected] wrote:> From a user > point of view I think that adding a 'par' construct to > > Python for parallel loops would add a lot of power and simplicity, > > e.g. > > > par i in list: > > updatePartition(i) > > ...actually, thinking about this further, I think it would be good to > add a 'sync' keyword which causes a thread rendezvous within a > parallel loop. This would allow parallel loops to run for longer in > certain circumstances without having the overhead of stopping and > restarting all the threads, e.g. > > par i in list: > for j in iterations: > updatePartion(i) > sync > commitBoundaryValues(i) > sync > > This example is a typical iteration over a grid, e.g. finite elements, > calculation, where the boundary values need to be read by neighbouring > partitions before they are updated. It assumes that the new values of > the boundary values are stored in temporary variables until they can > be safely updated. > > Jeremy I have coded up a (slightly) more realistic example. Here is a code to implement the numerical solution to Laplace's equation, which can calculate the values of a potential field across a rectangular region given fixed boundary values: xmax = 200 ymax = 200 niterations = 200 # Initialisation old=[[0.0 for y in range(ymax)] for x in range(xmax)] for x in range(xmax): old[x][0] = 1.0 for y in range(ymax): old[0][y] = 1.0 new=[[old[x][y] for y in range(ymax)] for x in range(xmax)] # Iterations for i in range(1,100): print "Iteration: ", i for x in range(1,ymax-1): for y in range(1, xmax-1): new[x][y] = \ 0.25*(old[x-1][y] + old[x+1][y] + old[x][y-1] + old[x-1][y]) # Swap over the new and old storage arrays tmp = old old = new new = tmp # Print results for y in range(ymax): for x in range(xmax): print str(old[x][y]).rjust(7), print In order to parallelise this with the par construct would require a single alteration to the iteration section: for i in range(1,100): print "Iteration: ", i par x in range(1,ymax-1): for y in range(1, xmax-1): new[x][y] = \ 0.25*(old[x-1][y] + old[x+1][y] + old[x][y-1] + old[x-1][y]) # Swap over the new and old storage arrays tmp = old old = new new = tmp The par command tells python that it may choose to fire up multiple threads and automatically partition the data between them. So, for instance, if there were ten threads created each one would work on a sub-range of x values: thread 1 takes x from 1 to 100, thread 2 takes x from 101 to 200, etc. However with this approach there is an overhead in each iteration of starting up the threads and shutting them down again. Depending on the impact of this overhead, it might be better to keep the threads running between iterations by modifying the code like this, adding a 'sync' command to synchronise the threads at the end of each iteration and also making sure that only one of the threads performs the swap of the data arrays. par x in range(1,ymax-1): for i in range(1,100): if __thread__ == 0: print "Iteration: ", i for y in range(1, xmax-1): new[x][y] = \ 0.25*(old[x-1][y] + old[x+1][y] + old[x][y-1] + old[x-1][y]) # Swap over the new and old storage arrays sync if __thread__ == 0: tmp = old old = new new = tmp sync Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
Hi Steven, I am impressed by this - it shows the potential speedup that pmap could give. Although the GIL would be a problem as things for speed up of pure Python code. Do Jython and Iron Python include the threading module? Jython does, and AFAIK IronPython also. Jython also has no GIL I think, for IronPython I don't know that. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Best library to make XSLT 2.0 transformation
John Krukoff schrieb: On Tue, 2009-05-19 at 13:42 +0200, Diez B. Roggisch wrote: wdveloper wrote: Hi there, I need to make xml transformation using XSLT 2.0 (since i want to use the powerful tag to produce multiple files). In your experience, which kind of library out there is better? XSLT is a standard, so if you find a library that implements it, there shouldn't be much differences. Having said that, these days lxml2 is the craze, and it contains xslt-processing. It would be my first (and hopefully last) stop. Diez While I firmly believe lxml is the best python XML library available, being built on libxml2 means that it only supports XSLT 1.0. As far as I know, if you want 2.0 support, you still need to be using one of the Java XSLT processors. Ah, sorry, I missed the 2.0 requirement. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
On Tue, May 19, 2009 at 10:42 AM, Daniel Fetchinson < [email protected]> wrote: > >> >> On the one hand, there are developers who love big IDEs with lots of > >> >> features (code generation, error checking, etc.), and rely on them to > >> >> provide the high level of support needed to be reasonably productive > >> >> in heavy-weight languages (e.g. Java). > >> >> > >> >> On the other hand there are developers who much prefer to keep things > >> >> light-weight and simple. They like clean high-level languages (e.g. > >> >> Python) which are compact enough that you can keep the whole language > >> >> in your head, and require only a good text editor to be used > >> >> effectively. > >> > > >> >This distinction is IMHO not correct. If you took a look at Java, you > >> would > >> >notice that the core language syntax is much simpler than Python's. > >> > >> That's half-true. The problem is that you have to digest a much bigger > >> chunk of Java before you can start being productive. Consider how > simple > >> it is to write a non-regex grep in Python. In addition, Python's object > >> model is simpler than Java's, not even talking about the contortions > that > >> Java's static class model forces you into. > > > > > > I am new to Python. I am slowly realizing that Python might be a better > > choice when compared to java on the server side. Is there any performance > > comparison between Java and Python ? For example, if I use the J2EE > solution > > vs. python (Django etc.) on the server side, would one perform better > over > > the other ? > > Benchmarks always test for a given feature. The available benchmarks > will most likely not test the feature relevant for your particular > application simply because there are about a gazillion different ways > of using a web framework. So the best you can do is simply test the > bottleneck part of your application and see for yourself, otherwise > you will be left with comments like "django is used at work because > it's faster for us" or "I use j2ee because performance is better for > my web app". When it will come to choosing your framework these will > help little to none. Ah! I should have been careful before asking such "general" question about performance. I agree with you. But mine was more academic. I should not given a specific example. AFAIK, for java on the client side, JVM performance is one of the critical things which has been tuned to death until now. Even Google's Android which uses Java for the programming language uses a Dalvik Virtual machine which was spefically designed to handle low CPU, memory and power environments. Similarly, Python can also be used to program on Nokia phones etc. Of course programming natively (C/C++) would make a difference in environments where CPU, memory and power are a big constraint. Given the context, do we know how Python compares with Java or even native programming. What is the overhead of Python's interpreted code ? Some standard benchmarks would help compare apples to apples though it may not help deciding which framework to choose. -mohan > > Cheers, > Daniel > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
> Ah! I should have been careful before asking such "general" question about > performance. I agree with you. But mine was more academic. I should not given > a specific example. > > AFAIK, for java on the client side, JVM performance is one of the critical > things which has been tuned to death until now. Even Google's Android which > uses Java for the programming > language uses a Dalvik Virtual machine which was spefically designed to > handle low CPU, memory and power environments. Similarly, Python can also be > used to program on Nokia phones etc. > Of course programming natively (C/C++) > would make a difference in environments where CPU, memory and power are a big > constraint. Given the context, do we know how Python compares with > Java or even native programming. What is the overhead of Python's > interpreted code ? Some standard benchmarks would help compare apples to > apples though it may not help deciding which > framework to choose. > > -mohan Danger, will robinson- the dalvik jvm has precisely nothing to do with standard java. It uses the same syntax but otherwise operates entirely differently. Don't assume you'll get the same performance characteristics out of the other common jvm's. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
package with executable
Hi, my name is Stefano Costa, I am an archaeologist and I am developing GNUCal, a radiocarbon calibration program released under the GNU GPL. [1][2] Currently the program consists of a small "library", largely based on Matplotlib and Numpy, and a command line program. My goal is to create a distributable package, that should ideally contain both the "gnucal" package and the command line program. As you can see in the source code [3], I am following some sort of standard layout for my project, but some things aren't still clear to me, even after reading setuptools' documentation and looking to the source of some known Python packages (like sphinx, pastescript, django): * where should the executable module be wrt setup.py and/or the package directory in the source tree * how should I format the console_scripts entry in setup() to make the executable module available to the system PATH after installing * how should I call the "gnucal" package from inside the executable script (currently I'm using "from gnucal import core" but it doesn't seem to work) I'm using virtualenv to create testing environments for the install process, and my Python is 2.5.4 on Debian Sid. Any suggestion is appreciated, particularly if there are some real examples to draw from. thanks, steko [1] http://gnucal.iosa.it/ [2] http://en.wikipedia.org/wiki/Radiocarbon_dating#Calibration [3] http://bitbucket.org/steko/gnucal/ -- Stefano Costa http://www.iosa.it/ Open Archaeology signature.asc Description: Questa è una parte del messaggio firmata digitalmente -- http://mail.python.org/mailman/listinfo/python-list
Mock Form Post
Let me qualify this by saying I'm very new to python. I'm doing some work with mod_python and in a function I have defined I am passing in the form and then iterating through the form keys. I'm currently writing my unit tests and I'm trying to mock up a form object with kids so I can emulate my true form post. So I'm attempting to mock up a class that I'm calling "_Fakeform". I'm lost on how I should do it though. I thought by creating a dictionary object with key value pairs that would satisfy my need but I'm not sure how to get at it when I pass my mocked class in. -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a Par construct to Python?
On May 19, 5:05 am, [email protected] wrote: > Thanks for explaining a few things to me. So it would seem that > replacing the GIL with something which allows better scalability of > multi-threaded applications, would be very complicated. The paper by > Jesse Nolle which I referenced in my original posting includes the > following: > > "In 1999 Greg Stein created a patch set for the interpreter that > removed the GIL, but added granular locking around sensitive > interpreter operations. This patch set had the direct effect of > speeding up threaded execution, but made single threaded execution two > times slower." > > Source:http://jessenoller.com/2009/02/01/python-threads-and-the-global-inter... > > That was ten years ago - do you have any idea as to how things have > been progressing in this area since then? https://launchpad.net/python-safethread -- http://mail.python.org/mailman/listinfo/python-list
Re: package with executable
On May 19, 2:54 pm, Stefano Costa wrote:
> Hi,
> my name is Stefano Costa, I am an archaeologist and I am developing
> GNUCal, a radiocarbon calibration program released under the GNU GPL.
> [1][2]
>
> Currently the program consists of a small "library", largely based on
> Matplotlib and Numpy, and a command line program. My goal is to create a
> distributable package, that should ideally contain both the "gnucal"
> package and the command line program.
>
> As you can see in the source code [3], I am following some sort of
> standard layout for my project, but some things aren't still clear to
> me, even after reading setuptools' documentation and looking to the
> source of some known Python packages (like sphinx, pastescript, django):
> * where should the executable module be wrt setup.py and/or the
> package directory in the source tree
> * how should I format the console_scripts entry in setup() to make
> the executable module available to the system PATH after
> installing
> * how should I call the "gnucal" package from inside the
> executable script (currently I'm using "from gnucal import core"
> but it doesn't seem to work)
>
> I'm using virtualenv to create testing environments for the install
> process, and my Python is 2.5.4 on Debian Sid.
>
> Any suggestion is appreciated, particularly if there are some real
> examples to draw from.
>
> thanks,
> steko
>
> [1]http://gnucal.iosa.it/
> [2]http://en.wikipedia.org/wiki/Radiocarbon_dating#Calibration
> [3]http://bitbucket.org/steko/gnucal/
>
> --
> Stefano Costahttp://www.iosa.it/Open Archaeology
>
> signature.asc
> < 1KViewDownload
So, I've got a couple packages where I've used the same method.
Generally, I've formatted my entry_points argument as follows:
entry_points = {
'console_scripts': [ 'xmlrpctool =
hostapi.clients.xmlrpc:main' ]
},
It's just a dictionary with a 'console_scripts' key. The value is a
list of wrapper scripts that are to be installed along with the
library files. In this scenario, I'm installing a wrapper script
called 'xmlrpctool' which calls a function named main in the xmlrpc
module within my hostapi.clients package. SetupTools generates that
wrapper for you.
That main function can be any callable. Looking at the way you've
formatted your gnucal.py script, I'm not sure it's going to work
without a bit of modification.
My personal approach would be to move that code into your gnucal
directory, either as it's own module or within one of the existing,
and implement it as a "main" function.
Then an entry_points line such as the following will make sure
'gnucal' gets installed in a directory on your path:
entry_points = {
'console_scripts': [ 'gnucal = gnucal.core:main' ]
},
This, of course, assumes that you move your main function into
'gnucal.core.'
HTH,
Jeff
mcjeff.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Mock Form Post
On May 19, 3:40 pm, Scooter wrote: > Let me qualify this by saying I'm very new to python. I'm doing some > work with mod_python and in a function I have defined I am passing in > the form and then iterating through the form keys. I'm currently > writing my unit tests and I'm trying to mock up a form object with > kids so I can emulate my true form post. So I'm attempting to mock up > a class that I'm calling "_Fakeform". I'm lost on how I should do it > though. I thought by creating a dictionary object with key value pairs > that would satisfy my need but I'm not sure how to get at it when I > pass my mocked class in. 1 strike against me for poor proof reading. 1) While I did mention mod_python I didn't say I was referring to an HTML form. 2) I said I'm trying to mock up a form object with "kids". No idea how I messed that up, but it should be "keys" -- http://mail.python.org/mailman/listinfo/python-list
optparse options
Why do I need to put two options for this script to print the path? if I just specify the option and argument... $ python
Re: Advanced Python books?
I found Core Python Programming to cater to my needs as a Pro book. On Tue, May 19, 2009 at 6:48 PM, Thomas Guettler wrote: > kj schrieb: > > I have read a couple of "learn Python"-type books, and now I'm > > looking for some more advanced books on Python, > ... > > Basically I'm looking for a book that assumes that one has the > > basics of the language down, and instead focuses on standard problems > > of software development, such as application architecture and > > design, prototyping, debugging, profiling and performance-tuning, > > testing, packaging/distribution, extending/embedding, threading > > and IPC, persistence, etc., and on various prototypical cases such > > as command-line utilities, GUI-apps, webapps, database-backed apps, > > simulations, etc. > > I think there is no such book. Maybe the Python Cookbook comes near. > > webapps: I use django, other use turbogears, other even different stuff... > There are several books about e.g. django. It would be hard to > put all the magic of all web apps into one chapter. > > GUI-apps: You can use tkinter, qt or gtk again it would be hard > to put something useable into one chapter. > > Thomas > > -- > Thomas Guettler, http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.astorandblack.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a better way to chose a slice of a list?
On May 8, 5:55 pm, John Yeung wrote:
> On May 8, 3:03 pm,walterbyrd wrote:
>
> > This works, but it seems like there should be a better way.
>
> > --
> > week = ['sun','mon','tue','wed','thu','fri','sat']
> > for day in week[week.index('tue'):week.index('fri')]:
> > print day
> > ---
>
> I think you should provide much more information, primarily why you
> want to do this. What is the larger goal you are trying to achieve?
I am just looking for a less verbose, more elegant, way to print a
slice of a list. What is hard to understand about that? I am not sure
how enumerated types help.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
someone said: If you took a look at Java, you would notice that the core language syntax is much simpler than Python's. thanks for the laughs whoever you are! -- a game sig: http://tinyurl.com/d3rxz9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Conceptual flaw in pxdom?
On 19 Mai, 18:16, "Diez B. Roggisch" wrote: > > Sorry to say so, but that's nonsense. DOM is not complicated because it > contains anything superior - the reason (if any) is that it is formulated > as language-agnostic as possible, with the unfortunate result it is rather > clumsy to use in all languages. Although I presume that people really mean the core standards when they talk about "the DOM", not all the other ones related to those core standards, the API is not to everyone's taste because, amongst other things, it uses functions and methods when some people would rather use properties (which actually appear in various places in the standards, so it isn't as if the W3C haven't heard of such things), and for lots of other subjective reasons: some I can agree with, some I put at the same level as a lot of the API-posturing in numerous domains where Python code gets written, where such code jostles above all other concerns for the coveted "Pythonic" label. However, when people are actually choosing to use DOM-related technologies, and when those technologies do not necessarily have equivalents in whatever other technology stack that could be suggested, can we not just take it as read that they actually know that the DOM isn't very nice (or that other people don't think that it's very nice) and that there are alternatives to the core stuff (especially when the inquirer has actually indicated his familiarity with those alternatives) and that reminding everyone for the nth time about how bad the DOM is (for whatever tangential purpose only partially related to the topic under discussion) adds very little if anything in the way of advice? It's like someone saying that they're going to fly the Atlantic in a 747 only to be told that they should drive a Lexus because "Boeing make terrible cars". Feel free to replace "DOM" in the above with whatever else fits, because this kind of thing comes up all the time. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse options
On 2009-05-19 16:07, icarus wrote: Why do I need to put two options for this script to print the path? if I just specify the option and argument... $ python
Re: Performance java vs. python
On Tue, May 19, 2009 at 5:43 PM, namekuseijin wrote: > someone said: > > If you took a look at Java, you would > notice that the core language syntax is much simpler than Python's. > > thanks for the laughs whoever you are! > I'm no Java fan, but I do agree that the core language is a bit easier for people to grasp. I have also heard that from other developers as well. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Context manager, atexit processing, and PEP 3143 DaemonContext.close
> > If there is a function which triggers a one-shot switch, I like
> > to have a way to find out if it has already been triggered, I
> > prefer to have the function tell me if it triggered the switch
> > or not, but I would not want that to be by raising an exception.
>
> In this case, though, we're talking about a class intended to
> implement the context manager API (in addition to other API).
>
> So, following your argument above, we might expect a generic
> context manager object to be able to tell us whether we're
> currently inside that context or not. Does such a thing exist?
By a "one-shot switch" I meant as something which
changes once atomically in isolation, not as
something whose state comprises a transaction during
which the state of multiple externally visible
objects might change.
I imagine if there is an object used as a context
manager whose context state ("currently inside
that context or not") is not strictly under the
control of the single "with" statement where it is
fulfilling the "context manager" contract, would not
be a generic context manager.
In other words, to me it seems like the concept of
"currently inside a context or not" is not something
visible external to the object except in a case
where there is another thread of execution, which is
not a case I would expect to be part of the generic
context manager protocol, but can be added by an
object which implements the context manager protocol
and also keeps track of its state by setting flags
in the __enter__ and __exit__ functions.
Does this make sense?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Mock Form Post
Scooter schrieb: On May 19, 3:40 pm, Scooter wrote: Let me qualify this by saying I'm very new to python. I'm doing some work with mod_python and in a function I have defined I am passing in the form and then iterating through the form keys. I'm currently writing my unit tests and I'm trying to mock up a form object with kids so I can emulate my true form post. So I'm attempting to mock up a class that I'm calling "_Fakeform". I'm lost on how I should do it though. I thought by creating a dictionary object with key value pairs that would satisfy my need but I'm not sure how to get at it when I pass my mocked class in. 1 strike against me for poor proof reading. 1) While I did mention mod_python I didn't say I was referring to an HTML form. 2) I said I'm trying to mock up a form object with "kids". No idea how I messed that up, but it should be "keys" If you'd use mod_wsgi, you could create a WSGI-application that's easily testable with paste fixture, including filling out forms, following redirects and all that. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
On Tue, May 19, 2009 at 3:21 PM, David Stanek wrote: > On Tue, May 19, 2009 at 5:43 PM, namekuseijin wrote: >> someone said: >> >> If you took a look at Java, you would >> notice that the core language syntax is much simpler than Python's. >> >> thanks for the laughs whoever you are! >> > > I'm no Java fan, but I do agree that the core language is a bit easier > for people to grasp. I have also heard that from other developers as > well. Perhaps for those with a C/C++ background, but I doubt that's true generally speaking. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Package problem
On Wed, 20 May 2009 00:40:28 +0900, David Cournapeau wrote: > The discussion has nothing to do with setuptools, or even python for > that matter. It has everything to do with python > on any system (including windows). That's why you should avoid > installing from sources into the locations managed by the OS, be it > /usr for unix, or C:\Windows on windows, etc... I actually kind of agree with what you're saying here. Under Linux it seems to me that users shouldn't be playing around in the bowels of /usr/ or anything lower... but site-packages is the directory that one would want to keep python packages in. That should be a developer/sysop area and not owned and run by the o/s. maybe... maybe... although too late now (?) somewhere like /etc/site-packages might be a lot better place to keep ones site packages. Or /opt. Under windows in python 2.6, they have this concept of user-packages. One could easily also apply that concept to linux and have a /home/user/.user-packages directory in which one could keep all ones user packages. > The problem is that overwriting files managed by the > software management system without its consent is bound to be broken, Something like what I describe above would totally satisfy linux system organisation requirements. David -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
My experience has been that if the execution stays inside the VM, then for a "server side" application, the JVM is faster, and proportionally even faster when there are more threads ready to do something. When the VM has to do a lot of interaction with the OS, then I think it is difficult to make general statements about Java vs Python, because there is so much dependency on how a particular library interacts with the operating system or with a remote server. For example a database driver which is doing a lot of conversion between the data representation of the database and the native representation of the VM may chew up more time than anything else, and for CPython that driver may be doing all that stuff in a C library where the Java version of the driver may be doing it all in the JVM and taking an order of magnitude longer. It seems to me like the guts of the JVM and CPython VMs are pretty comparable in terms of performance, and both languages are amenable to taking advantage of the performance of the VM. Other than the library implementations for interfacing with the outside world, for me the major performance distinction is with concurrency. I tend to implement solutions which rely pretty heavily on shared objects and the java.util.concurrent facilities, and it seems to me like the CPython VM is not able to easily provide the level of simple clean shared object concurrency support the JVM does. And my experience with the Python "multiprocessing" module is that while it is better than nothing, it does not seem to facilitate nearly the level of efficient shared object support the JVM does. -- http://mail.python.org/mailman/listinfo/python-list
Re: issue: Permissions in odfpy
Hi Shruti,
your message is kind of hard to read. Please note the following:
· Do not put useless junk("issue") in title.
· Multiple exclamation marks convey a sure sign of a diseased mind,
especially syntactically interesting constructions such as "??.."
· You didn't purchase your keyboard in August 2001, did you? (
http://ars.userfriendly.org/cartoons/?id=20010820 )
· It's probably just me, but "so please give me some solution" sounds
really rude. Why not "any ideas?", "thanks in advance" or just nothing?
Would you answer an email that ended like this? Please keep in mind, you
are not paying us, and we're trying to help you just because we want
happy python users (or trying to offset us being evil at times).
· Everyone mistpyes, and I'd be throwing mountains in my glass house if
I complained about grammar, but please show at least some effort.
That being said, this might help:
import odf.opendocument
doc = odf.opendocument.load('in.ods')
# You may want to use another way to select the sheet,
# this selects just the first one
sheet = doc.spreadsheet.childNodes[0]
sheet.setAttrNS(
'urn:oasis:names:tc:opendocument:xmlns:table:1.0',
'protected',
'true')
doc.save('out.ods')
Regards,
Philipp
shruti surve wrote:
> hey,
> i am using odfpy and generating spreadsheet in open office..but nobody
> should modify the file..so can anybody tell me how can we give permissions
> (read only) to spreadsheet in odfpy??..i have change the properties of my
> normal open office spreadsheet file and made it read only..n also
extracted
> it..but in conteny.xml also i am not finding any property which can be
used
> in odfpy...so please give me some solution..
>
>
> regards
> shruti surve
>
signature.asc
Description: OpenPGP digital signature
--
http://mail.python.org/mailman/listinfo/python-list
