Re: bisect intersection

2008-05-05 Thread Gabriel Genellina
En Mon, 28 Apr 2008 13:50:13 -0300, Robert Bossy <[EMAIL PROTECTED]> escribió:

> I stumbled into a sorted list intersection algorithm by Baeza-Yates
> which I found quite elegant. For the lucky enough to have a springerlink
> access, here's the citation:
> http://dblp.uni-trier.de/rec/bibtex/conf/cpm/Baeza-Yates04
>
> I implemented this algorithm in python and I thought I could share it.
> I've done some tests and, of course, it can't compete against dict/set
> intersection, but it will perform pretty well. Computing union and
> differences are left as an exercise...

Nice. As it only uses comparisons, it can be used even if the elements aren't 
hashable, that's good.
But if they are hashable, using a set and sorting again at the end is much 
faster, as you discovered.

-- 
Gabriel Genellina

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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Szabolcs Horvát

Duncan Booth wrote:

Szabolcs Horvát <[EMAIL PROTECTED]> wrote:

I thought that it would be very nice if the built-in sum() function used 
this algorithm by default.  Has this been brought up before?  Would this 
have any disadvantages (apart from a slight performance impact, but 
Python is a high-level language anyway ...)?


There's a thread you might find interesting:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9eda29faf92f532e/027cef7d4429aa3a

In that thread I suggested that Python ought to implement sum by adding 
together each pair of values, then each pair of results and so on. This 
means that for input values of a similar magnitude the intermediate results 
stay balanced. The implementation doesn't actually do all the first level 
sums first, it builds up a stack containing the sum of 2^k, 2^(k-1)...2 
values. Also it works for other types as well, and for strings or lists has 
the advantage of minimising the number of large string or list concatenations.


If you follow that thread far enough you'll find a post by Jussi Salmela 
which shows that summing adjacent pairs performs as well as Kahan summation
(he says 'almost as good' but in fact the only time they get different 
results the 'correct' answer is 50.05 and Kahan and sumpairs get 
the two nearest representable results either side: 50.048 and 
50.054 respectively).


I never did get round to re-coding my sumpairs() function in C, I would be 
interested to see just how much overhead it introduces (and I suspect it

would be faster than the existing sum in some cases such as for lists).


Thanks for this link!  Though some of the thread is missing, it was an 
interesting read.


This sounds like a very good idea: it is more generally applicable than 
the Kahan summation because it does not require subtraction/negation, so 
it would work with user-defined types, too.


While now I am convinced that using Kahan summation by default is not 
such a good idea, I cannot see any serious disadvantages/problems with 
pairwise summation!

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


Re: config files in python

2008-05-05 Thread Michael Ströder

sandipm wrote:

 In my application, I have some configurable information which is used
by different processes. currently I have stored configration in a
conf.py file as name=value pairs, and I am importing conf.py file to
use this variable. it works well

import conf
print conf.SomeVariable

but if I need to change some configuration parameteres,  it would need
me to restart processes.


reload(conf)

http://docs.python.org/lib/built-in-funcs.html#l2h-61

But you should carefully consider what updating the configuration means 
in your application.


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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Szabolcs Horvát

Gabriel Genellina wrote:


Python doesn't require __add__ to be associative, so this should not be used as 
a general sum replacement.


It does not _require_ this, but using an __add__ that is not commutative 
and associative, or has side effects, would qualify as a serious misuse, 
anyway.  So I think that this isn't a real disadvantage (it can always 
be documented that sum() expects __add__ to have these properties).


But you are right that summing floats with a requirement of high 
precision is a quite specific use case, so there are no serious 
arguments to do this, either.

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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Raymond Hettinger
On May 3, 9:50 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> I did the following calculation:  Generated a list of a million random
> numbers between 0 and 1, constructed a new list by subtracting the mean
> value from each number, and then calculated the mean again.
>
> The result should be 0, but of course it will differ from 0 slightly
> because of rounding errors.

See:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090



> Here's the program (pardon my style, I'm a newbie/occasional user):
 . . .
> mean = sum(data)/len(data)
> print sum(x - mean for x in data)/len(data)

See:
http://svn.python.org/view/sandbox/trunk/statistics/statistics.py?rev=40981&view=markup


Raymond

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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Raymond Hettinger
> > > However I find the seccond argument hack ugly. Does the sum way have any
> > > performance advantages over the reduce way?
>
> > Yes, sum() is faster:
...

> Not really; you measure the import and the attribute access time in
> the second case. sum() is 2x faster for adding numbers only:

Try it with Py2.6 or Py3.0.  The sum() function has been optimized and
should be at least 6x faster for summing ints and floats.  It should
even beat psyco optimized sums!


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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Szabolcs
On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> Gabriel Genellina wrote:
>
> > Python doesn't require __add__ to be associative, so this should not be 
> > used as a general sum replacement.
>
> It does not _require_ this, but using an __add__ that is not commutative
> and associative, or has side effects, would qualify as a serious misuse,
> anyway.

Sorry, I meant associative only, not commutative.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Duncan Booth
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote:

> En Sun, 04 May 2008 12:58:25 -0300, Duncan Booth
> <[EMAIL PROTECTED]> escribió: 
> 
>> Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>>
>>> I thought that it would be very nice if the built-in sum() function
>>> used this algorithm by default.  Has this been brought up before? 
>>> Would this have any disadvantages (apart from a slight performance
>>> impact, but Python is a high-level language anyway ...)?
>>
>> There's a thread you might find interesting:
>>
>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/9
>> eda29faf92f532e/027cef7d4429aa3a 
>>
>> In that thread I suggested that Python ought to implement sum by
>> adding together each pair of values, then each pair of results and so
>> on. This means that for input values of a similar magnitude the
>> intermediate results stay balanced. The implementation doesn't
>> actually do all the first level 
> 
> Python doesn't require __add__ to be associative, so this should not
> be used as a general sum replacement. But if you know that you're
> adding floating point numbers you can use whatever algorithm best fits
> you. Or use numpy arrays; I think they implement Kahan summation or a
> similar algorithm. 
> 
Yes, my argument is more along the line that it should have been 
implemented that way in the first place, but changing things now would 
require time machine intervention. :)


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


Re: Weird import problem

2008-05-05 Thread Anton81
>> NS/dir1/file1.py
>> NS/dir2/file2.py
> This *must* be wrong or at least not the full directory listing - please
> read
It is the directory structure in one of the python paths.

> Missing __init__.py in the dir2?
Oh right. I forgot about this. Thank you!
--
http://mail.python.org/mailman/listinfo/python-list


How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread n00m
os:windows
ml = 'line1 \n line2 \n line3 \n'
exec('some.exe "' + ml + '"')

and some.exe get only 'line1'...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Duncan Booth
Szabolcs <[EMAIL PROTECTED]> wrote:

> On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>> Gabriel Genellina wrote:
>>
>> > Python doesn't require __add__ to be associative, so this should
>> > not be 
> used as a general sum replacement.
>>
>> It does not _require_ this, but using an __add__ that is not
>> commutative and associative, or has side effects, would qualify as a
>> serious misuse, anyway.
> 
> Sorry, I meant associative only, not commutative.
> 
Unfortunately an __add__ which is not associative is actually perfectly 
reasonable. For example you could have a Tree class where adding two trees 
returns a new tree so (a+b)+c gives you:

.
   / \
   .  c
  / \
  a  b

but a+(b+c) gives:

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


Re: USB HID documentation?

2008-05-05 Thread Diez B. Roggisch
ETP wrote:

> I have a little robot project I'm programming in python using the
> Lynxmotion SSC-32 servo controller via serial.  I'd like to use a USB
> game controller (PS2 style) to control the robot.
> 
> I've read a number of threads about the difficulty of using USB
> without extensive understanding of the way it works, but a few have
> stated that HID is different somehow.  I definitely do not have any
> USB knowledge, and I don't care to get into that.  However, if USB-HID
> is much simpler I would love to learn.
> 
> I have the python extensions for windows:
>  http://sourceforge.net/project/showfiles.php?group_id=78018
> but I haven't found any documentation on how to implement HID in
> python.  Can anyone give me some examples or links?

You seem to misunderstand HID. HID is a protocol over USB (and Bluetooth I
believe) that will create user input device events which are mapped to your
OS input layer. That means that whenever you e.g. attach a keyboard device,
it's keyboard events will generate key-strokes on screen.

There are various kinds of HID-devices, and gamepads/joysticks generate
certain events.

So you need to look up you OS game device API and use that. Then attaching
any compliant HID-device should work.

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


use php in python httpservers

2008-05-05 Thread artasis
Hi, that is my task:
I need to create python webserver-like extension(dll) which will run
php and python scripts as plugins.
I have no problems with dll creating and run python scripts, but I
cannot understand how to run php(CLI is not a solution).
Is there a way to solve this problem? I've thought to implement php to
HTTPServer-like python module, but as I see it's impossible. Solutions
with creating intermediate C-based module is allowed, but better
without them :).
AFAIK, php5ts.dll is that what I must use but how integrate it to
python webserver? that is a question
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread n00m
Hint:
for some reason in VBScript it works fine.
What makes it different, with Python?
I tried all possible ways to combine quotes, ' and ",
with no avail
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread alexelder
On May 5, 10:25 am, n00m <[EMAIL PROTECTED]> wrote:
> os:windows
> ml = 'line1 \n line2 \n line3 \n'
> exec('some.exe "' + ml + '"')
>
> and some.exe get only 'line1'...

I think your problem lies with your "\n", escape chars. Assuming these
are not arguments and are indeed separating statements, I suggest
replacing "\n", with "&". That way, the command shell probably wont
complain.

An example:
ml = 'line1 & line2 & line3'

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


Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread Peter Otten
n00m wrote:

> os:windows
> ml = 'line1 \n line2 \n line3 \n'
> exec('some.exe "' + ml + '"')
> 
> and some.exe get only 'line1'...

My crystall ball says you want

subprocess.call(["some.exe", ml])

exec is a python statement that executes python code.

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


pygame music, cant read mp3?

2008-05-05 Thread globalrev
http://www.pygame.org/docs/ref/mixer.html

import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2,
buffer=3072)  //it complained abiout words=
so i guess its only the nbrs should be there//

pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load("example1.mp3")
pygame.mixer.music.play(loops=1, start=0.0)



Traceback (most recent call last):
  File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in

pygame.mixer.music.load("example1.mp3")
error: Couldn't read from 'example1.mp3'
--
http://mail.python.org/mailman/listinfo/python-list


threading: getting latest elements from list/dict

2008-05-05 Thread Vaibhav.bhawsar
Hello
I have a thread updating a dictionary with new elements. How can I check for
new elements as they are inserted into the dictionary by the thread? In
general is it safe to read a dictionary or a list while it is being updated
by a running thread? Does the dictionary or list have to be locked while
reading?
many questions! :)
vaibhav
--
http://mail.python.org/mailman/listinfo/python-list

Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread n00m
actually, it's this doesn't work (again, in VBS the "same"
construction works properly):

f = os.popen('osql -E -S(local) -dpubs -w800 -Q"' + query + '"', 'r')

res=f.readlines()

===
here "query" is a multiline string like:

select getdate()

select 555*666

select getdate()
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread Diez B. Roggisch
globalrev wrote:

> http://www.pygame.org/docs/ref/mixer.html
> 
> import pygame
> 
> #pygame.mixer.init(frequency=22050, size=-16, channels=2,
> buffer=3072)  //it complained abiout words=
> so i guess its only the nbrs should be there//
> 
> pygame.mixer.init(22050, -16, 2, 3072)
> pygame.mixer.music.load("example1.mp3")
> pygame.mixer.music.play(loops=1, start=0.0)
> 
> 
> 
> Traceback (most recent call last):
>   File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
> 
> pygame.mixer.music.load("example1.mp3")
> error: Couldn't read from 'example1.mp3'

Give it the full path to the MP3. Be aware of backward slashes + the need to
escape them.

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


Re: use php in python httpservers

2008-05-05 Thread Jeff
ctypes?
--
http://mail.python.org/mailman/listinfo/python-list


confused about self, why not a reserved word?

2008-05-05 Thread globalrev
class Foo(object):
def Hello(self):
print "hi"

object is purple, ie some sort of reserved word.

why is self in black(ie a normal word) when it has special powers.
replacing it with sel for example will cause an error when calling
Hello.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread globalrev
On 5 Maj, 13:47, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> globalrev wrote:
> >http://www.pygame.org/docs/ref/mixer.html
>
> > import pygame
>
> > #pygame.mixer.init(frequency=22050, size=-16, channels=2,
> > buffer=3072)  //it complained abiout words=
> > so i guess its only the nbrs should be there//
>
> > pygame.mixer.init(22050, -16, 2, 3072)
> > pygame.mixer.music.load("example1.mp3")
> > pygame.mixer.music.play(loops=1, start=0.0)
>
> > Traceback (most recent call last):
> >   File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
> > 
> > pygame.mixer.music.load("example1.mp3")
> > error: Couldn't read from 'example1.mp3'
>
> Give it the full path to the MP3. Be aware of backward slashes + the need to
> escape them.
>
> Diez

escape them?




import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072)
pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
pygame.mixer.music.play(loops=1, start=0.0)

Traceback (most recent call last):
  File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in

pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
error: Couldn't read from 'C:/Python25/myPrograms/pygameProgs/
example1.mp3'
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread globalrev
On 5 Maj, 14:03, globalrev <[EMAIL PROTECTED]> wrote:
> On 5 Maj, 13:47, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>
>
> > globalrev wrote:
> > >http://www.pygame.org/docs/ref/mixer.html
>
> > > import pygame
>
> > > #pygame.mixer.init(frequency=22050, size=-16, channels=2,
> > > buffer=3072)  //it complained abiout words=
> > > so i guess its only the nbrs should be there//
>
> > > pygame.mixer.init(22050, -16, 2, 3072)
> > > pygame.mixer.music.load("example1.mp3")
> > > pygame.mixer.music.play(loops=1, start=0.0)
>
> > > Traceback (most recent call last):
> > >   File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
> > > 
> > > pygame.mixer.music.load("example1.mp3")
> > > error: Couldn't read from 'example1.mp3'
>
> > Give it the full path to the MP3. Be aware of backward slashes + the need to
> > escape them.
>
> > Diez
>
> escape them?
>
> import pygame
>
> #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072)
> pygame.mixer.init(22050, -16, 2, 3072)
> pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
> example1.mp3')
> pygame.mixer.music.play(loops=1, start=0.0)
>
> Traceback (most recent call last):
>   File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
> 
> pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
> example1.mp3')
> error: Couldn't read from 'C:/Python25/myPrograms/pygameProgs/
> example1.mp3'

tried filenames with \ also but same result.
--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about self, why not a reserved word?

2008-05-05 Thread Wojciech Walczak
2008/5/5, globalrev <[EMAIL PROTECTED]>:
> class Foo(object):
> def Hello(self):
> print "hi"
>
>  object is purple, ie some sort of reserved word.
>
>  why is self in black(ie a normal word) when it has special powers.
>  replacing it with sel for example will cause an error when calling
>  Hello.

Could you give an example of such an error?

-- 
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread Wojciech Walczak
2008/5/5, globalrev <[EMAIL PROTECTED]>:
> pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')


Are you sure that:

os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?

Check it with python.

-- 
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about self, why not a reserved word?

2008-05-05 Thread Jean-Paul Calderone

On Mon, 5 May 2008 04:57:25 -0700 (PDT), globalrev <[EMAIL PROTECTED]> wrote:

class Foo(object):
def Hello(self):
print "hi"

object is purple, ie some sort of reserved word.


What your text editor of choice does with syntax coloring is its own business.
It doesn't really have anything to do with the language, except inasmuch as one
might hope that it is *somehow* based on it.


why is self in black(ie a normal word) when it has special powers.
replacing it with sel for example will cause an error when calling
Hello.


Not true.

   [EMAIL PROTECTED]:~$ python -c '
   > class Foo(object):
   > def Hello(monkeys):
   > print "hi"
   >
   > Foo().Hello()
   > '
   hi
   [EMAIL PROTECTED]:~$

`self´ as the name of the first parameter to an instance method is
convention; beyond that, it has no special meaning in the language.

`object´, on the other hand, is a builtin name which refers to a
particular object.

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

Re: Problems with psycopg2

2008-05-05 Thread c james

David Anderson wrote:
The thing is this query works fine on the console through psql, but not 
in my code? can anyone explain me why?


On Thu, May 1, 2008 at 9:31 PM, David Anderson <[EMAIL PROTECTED] 
> wrote:


Hi all
I have this function:
def checkName(self, name):
cur = self.conn.cursor()
 
sql = "SELECT * from patient WHERE fn_pat = '" + name + "'"

cur.execute(sql)
rows = cur.fetchall()
   
if rows == "[]":

self.insert()

It seems to work fine, But I'm getting this exception:
psycopg2.ProgrammingError: current transaction is aborted, commands
ignored until end of transaction block
at: cur.execute(sql)

What's the problem?
thx

ps: fn_pat is the column of the db, name is the string passed in the
function parameter





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


Does `name` happen to have an apostrophe in it?  You may want to look at 
using bind variables.


cur.execute("SELECT * from patient WHERE fn_pat=%(name)s",
{'name': name})


http://wiki.python.org/moin/DbApiCheatSheet
http://mail.python.org/pipermail/python-list/2005-March/314154.html

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


Re: confused about self, why not a reserved word?

2008-05-05 Thread Diez B. Roggisch
globalrev wrote:

> class Foo(object):
> def Hello(self):
> print "hi"
> 
> object is purple, ie some sort of reserved word.

It is not.
 
> why is self in black(ie a normal word) when it has special powers.
> replacing it with sel for example will cause an error when calling
> Hello.

That must be some other problem. This is perfectly legal python code and
works:

class Foo(object):
def bar(imafancyobject):
print imafancyobject

f = Foo()
f.bar()

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


Re: confused about self, why not a reserved word?

2008-05-05 Thread J. Cliff Dyer
On Mon, 2008-05-05 at 04:57 -0700, globalrev wrote:
> class Foo(object):
>   def Hello(self):
>   print "hi"
> 
> object is purple, ie some sort of reserved word.
> 
> why is self in black(ie a normal word) when it has special powers.
> replacing it with sel for example will cause an error when calling
> Hello.
> 

Wow.  No it won't.  sel is perfectly legal.  I've seen s used on
occasion, and of course metaclass methods often use cls.

Direct ^C^V from my python interpreter:

$ python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52) 
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def Hello(sel):
... print "hi"
... 
>>> f = Foo()
>>> f.Hello()
hi
>>> 

Can you paste an example that breaks for you?


-- 
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

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


Re: using sqlite3 - execute vs. executemany; committing ...

2008-05-05 Thread Vlastimil Brom
>
>
> Thanks for further comments David,

You are right, the choice of an appropriate data structure isn't easy; I
described the requirements in an earlier post:
http://mail.python.org/pipermail/python-list/2007-December/469506.html

Here is a slightly modified sample of the text source I currently use in my
present (ad hoc and quite dirty) code:

Wi den L...n
m...k gein den Pragern.

Wen dy her czu T... vf dy vient
wern gesampt czu hertin strit,
dez m...s vs gein obint
W... stunt s...t.
Doch gar Sthir czu em kam,
h...g W... sich ken em nom.
Ez irgink ubil den L...:
S... slug W...um daz houbt ab vil gern.
Den Pragern mochtin dy L...ner nit intken,
si slugin si, das si plutis hin runnen.

Wi dem Stracka geschach,
du er do heim sin husfrowin sach.

Aus allin L...tern einer hin quom,
der waz S...raka gnant mit
dem nom.
Em ein vetil den rat gab, ...


The corresponding data stored as a dict  look like the following dict (here
sorted, at least on the highest level):
(, ,  ... are ignored here, these are used for the text formatting
for the gui and aren't retrieved any more)

{0: {u'KC': u'12', u'VCC': u'0', u'KNJ': u'13', u'FN': u'21rb', u'VN':
u'rn_1_vers_1'},
13: {u'KC': u'12', u'VCC': u'0', u'KNJ': u'13', u'VN': u'rn_2_vers_1',
u'FN': u'21rb'},
39: {u'KC': u'12', u'VCC': u'1', u'KNJ': u'13', u'VN': u'1', u'VNJ': u'1',
u'FN': u'21rb'},
71: {u'KC': u'12', u'VCC': u'2', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'2', u'VN': u'2'},
102: {u'KC': u'12', u'VCC': u'2', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'3', u'VN': u'3'},
126: {u'KC': u'12', u'VCC': u'3', u'KNJ': u'13', u'VN': u'4', u'VNJ': u'4',
u'FN': u'21rb'},
144: {u'KC': u'12', u'VCC': u'3', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'5', u'VN': u'5'},
171: {u'KC': u'12', u'VCC': u'5', u'KNJ': u'13', u'VN': u'6', u'VNJ': u'6',
u'FN': u'21rb'},
199: {u'KC': u'12', u'VCC': u'6', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'7', u'VN': u'7'},
224: {u'KC': u'12', u'VCC': u'7', u'KNJ': u'13', u'VN': u'8', u'VNJ': u'8',
u'FN': u'21rb'},
264: {u'KC': u'12', u'VCC': u'7', u'KNJ': u'13', u'VN': u'9', u'VNJ': u'9',
u'FN': u'21rb'},
307: {u'KC': u'12', u'VCC': u'8', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'10', u'VN': u'10'},
348: {u'KC': u'12', u'VCC': u'9', u'KNJ': u'13', u'VN': u'_rn_1_vers_11',
u'VNJ': u'00', u'FN': u'21rb'},
373: {u'KC': u'12', u'VCC': u'9', u'KNJ': u'13', u'FN': u'21rb', u'VNJ':
u'00', u'VN': u'rn_2_vers_11'},
409: {u'KC': u'12', u'VCC': u'9', u'KNJ': u'13', u'VN': u'11', u'VNJ':
u'11', u'FN': u'21rb'},
444: {u'KC': u'12', u'VCC': u'10', u'KNJ': u'13', u'VN': u'12', u'VNJ':
u'12', u'FN': u'21va'},
480: {u'KC': u'12', u'VCC': u'11', u'KNJ': u'13', u'FN': u'21va', u'VNJ':
u'13', u'VN': u'13'}}

The keys are indices of the places in text, where the
value of some tag/property ... changes; also the not changing values are copied
in the inner dicts, hence after determining the index of the first such
"boundary" preceeding the given text position (using bisect), the
complete parameters can be retrieved with a single dict lookup.
The other way seems much more complicated with this dict
structure. I.e. it should be possible to find the index/or all
indices/or the lowest index given some combinations of tag values - e.g.
with the input: u'FN': u'21va' >> 444 should  be found (as the lowest index
with this value)
for u'KC': u'12' AND u'VN': u'3' >> 102
(there are of course several other combinations to search for)
I couldn't find an effective way to lookup the specific values of the inner
dict (other than nested loops), probably using a set of tuples instead the
inner dict would allow the checks for intersection with the input data, but
this also seems quite expensive, as it requires the loop with checks over
the entire data ... the same would probably be true for multiple reversed
dicts keyed on the tags and containing the indices and the
corresponding values (but I actually haven't  tested the latter two
approaches).

The approach with sqlite I'm testing now simply contains columns for all
relevant "tags" plus a column for text index; this way I find it quite easy
to query the needed information in both directions (index >> tags; tag(s) >>
index/indices) with the db selects - even as a beginner with SQL.

The exact set of tags will be complete with the availability of all
texts, then the gui will be adapted to make the user selections available
(comboboxes). The searches are restricted
to the predefined "properties", they are not manually queried.
With the dynamic building of the db I just
tried, not to hardcode all the tags, but it would be later
possible to create the database tables and columns also in a
controlled "static" way.

Comparing the two versions I have, the dictionary approach really seems
quite a bit more complicated (the data as well as the functions for the
retrieval), than the sqlite3 version.

For this app I really actually don't need a persistent db, nor should it be
shared etc. The only used thing are th

Re: using sqlite3 - execute vs. executemany; committing ...

2008-05-05 Thread David
Hi Vlasta.

Don't have time to reply to your mail in detail now. Will do so later.

Have you tried the eGenix text tagging library? It sounds to me that
this is exactly what you need:

http://www.egenix.com/products/python/mxBase/mxTextTools/

Disclaimer: I've never actually used this library ;-)

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


Re: Where are Tkinter event.type constants defined?

2008-05-05 Thread Mike Driscoll
On May 4, 7:22 pm, Noah <[EMAIL PROTECTED]> wrote:
> I'm trying to match against Event.type for KeyPress and ButtonPress.
> Currently I'm using integer constants (2 and 4). Are these constants
> defined anywhere? The docs talk about KeyPress and ButtonPress, but I
> don't see them in any of the Tkinter source files. Are these just
> magic values that come out of the TK side of things and are not
> defined in Python? Code like this makes me think I'm doing something
> wrong:
>
>     if event.type == 2:
>         handle_key_press (event.char)
>     elif event.type == 4:
>         do_something_for_button ()
>     else:
>         pass # unknown event
>
> (I understand that usually you would bind these function so that they
> are called as a callback.)
>
> I don't mind defining the constants myself. I just want to make sure
> that I'm not missing something already done for me. Does anyone happen
> to have a complete list of Event.type constants?
>
> --
> Noah

Hey Noah,

I recommend checking out Lundh's site (effbot) since he has lots of
information on Tkinter there. Here's his Tkinter event page:

http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

And there's this (less helpful):

http://docs.python.org/lib/node699.html

There's a whole chapter on events Grayson's Tkinter book, but I'm not
seeing constants defined. I think they might vary somewhat across
platforms anyway...but hopefully someone else more knowledgeable will
come along and address that.

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


Re: confused about self, why not a reserved word?

2008-05-05 Thread Marc Christiansen
globalrev <[EMAIL PROTECTED]> wrote:
> class Foo(object):
>def Hello(self):
>print "hi"
> 
> object is purple, ie some sort of reserved word.
> 
> why is self in black(ie a normal word) when it has special powers.

Because `self` is just a name. Using `self` is a convention, but one can
use any name which is not reserved.

> replacing it with sel for example will cause an error when calling
> Hello.

Which error? I don't get one.

0:tolot:/tmp> python f.py
hi
0:tolot:/tmp> cat f.py
class Foo(object):
def Hello(sel):
print "hi"

Foo().Hello()
0:tolot:/tmp> 

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


Re: confused about self, why not a reserved word?

2008-05-05 Thread globalrev
sorry i noticed now a little error, i was playing around a lot and saw
that on the sel-example i had then called foo.hello() instead of
foo.Hello().


but it was an informing error now i egt it. was wondering about self
anyway so thanks for clearing it up.


but it still is a bit confusing that u can pass with any word.
wouldnt:


class Foo(object):
def Hello():
print "hi"


make more sense?

the class-thing seems inside out somehow in python. if im doing
foo.Hello() im already saying that im using the class foo because i
did foo=Foo() before and then still when calling Hello() i am
invisibly passing the class itself a s a parameter by default?
just seems backwards and weird.
--
http://mail.python.org/mailman/listinfo/python-list


How to convert unicode string to unsigned char *

2008-05-05 Thread Simon Posnjak
Hi!

I have a C module for which I created a wrapper with swig. The function def is:

C:

int some_thing(unsigned char * the_str);

eg:

Python:

some_module.some_thing (the_str)

Now I would like to feed it with a UTF-8 formatted string:

test = u'Make \u0633\u0644\u0627\u0645, not war.'

If I try:

some_module.some_thing (test)

I get:

TypeError with message: in method 'some_thing', argument 1 of type
'unsigned char *'

I also tried to pack the string into array or struct but I can not get
it to work.

What would be the best solution for this problem?

[I am working on Windows]

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


Re: How to convert unicode string to unsigned char *

2008-05-05 Thread Jean-Paul Calderone

On Mon, 5 May 2008 15:41:08 +0200, Simon Posnjak <[EMAIL PROTECTED]> wrote:

Hi!

I have a C module for which I created a wrapper with swig. The function def is:

C:

int some_thing(unsigned char * the_str);

eg:

Python:

some_module.some_thing (the_str)

Now I would like to feed it with a UTF-8 formatted string:

test = u'Make \u0633\u0644\u0627\u0645, not war.'


`test´ is not a UTF-8 encoded string.  It's a unicode string.

To get a UTF-8 encoded string from a unicode string, use the `encode´
method:

   some_module.some_thing(test.encode('utf-8'))

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

Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Szabolcs
On May 5, 12:24 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Szabolcs <[EMAIL PROTECTED]> wrote:
> > On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> >> Gabriel Genellina wrote:
>
> >> > Python doesn't require __add__ to be associative, so this should
> >> > not be
> > used as a general sum replacement.
>
> >> It does not _require_ this, but using an __add__ that is not
> >> commutative and associative, or has side effects, would qualify as a
> >> serious misuse, anyway.
>
> > Sorry, I meant associative only, not commutative.
>
> Unfortunately an __add__ which is not associative is actually perfectly
> reasonable.

Well, 'reasonable' is a subjective notion in this case :-)  I have
never seen a non-associative use of the plus sign in maths, so I would
tend to take associativity for granted when seeing a + b + c in code,
therefore I would avoid such uses.  (Multiplication signs are a
different story.)  Of course others may feel differently about this,
and technically there's nothing in the way of using a non-associative
__add__! :)

> For example you could have a Tree class where adding two trees
> returns a new tree so (a+b)+c gives you:
>
>     .
>    / \
>    .  c
>   / \
>   a  b
>
> but a+(b+c) gives:
>
>     .
>    / \
>    a  .
>      / \
>      b  c

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


Re: pygame music, cant read mp3?

2008-05-05 Thread globalrev
On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
wrote:
> 2008/5/5, globalrev <[EMAIL PROTECTED]>:
>
> > pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
>
> Are you sure that:
>
> os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?
>
> Check it with python.
>
> --
> Regards,
> Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/


>>> import os
>>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False


but...it is there

>>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
False

does it matter if i use / or \? which si recommended?
--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about self, why not a reserved word?

2008-05-05 Thread [EMAIL PROTECTED]
> the class-thing seems inside out somehow in python. if im doing
> foo.Hello() im already saying that im using the class foo because i
> did foo=Foo() before and then still when calling Hello() i am
> invisibly passing the class itself a s a parameter by default?
> just seems backwards and weird.

You're not passing a reference to the class, you're passing a
reference to the object. Any object-orientated programming language
will be passing methods references to an object; Python just makes
that explicit within the method definition. See 
http://www.python.org/doc/faq/general/#id35
--
http://mail.python.org/mailman/listinfo/python-list


Re: pygame music, cant read mp3?

2008-05-05 Thread Dan Upton
On Mon, May 5, 2008 at 10:09 AM, globalrev <[EMAIL PROTECTED]> wrote:
> On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
>  wrote:
>  > 2008/5/5, globalrev <[EMAIL PROTECTED]>:
>
> >
>  > > 
> pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
>  >
>
> > Are you sure that:
>  >
>  > os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?
>  >
>  > Check it with python.
>  >
>  > --
>  > Regards,
>  > Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>
>
>  >>> import os
>  >>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
>  False
>
>
>  but...it is there
>
>  >>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
>  False

What about:

os.path.exists('C:\\Python25\\myPrograms\\pygameProgs\\dront.mp3') == True

That's what Diez mentioned earlier in the thread about escaping the slashes.
>
>  does it matter if i use / or \? which si recommended?


Which slash to use basically depends on whether you're on Windows
(uses \ as a path separator) or *nix (uses / as a path separator).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert unicode string to unsigned char *

2008-05-05 Thread Jean-Paul Calderone

On Mon, 5 May 2008 16:05:08 +0200, Simon Posnjak <[EMAIL PROTECTED]> wrote:

On Mon, May 5, 2008 at 3:48 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:

On Mon, 5 May 2008 15:41:08 +0200, Simon Posnjak <[EMAIL PROTECTED]> wrote:

> Hi!
>
> I have a C module for which I created a wrapper with swig. The function
def is:
>
> C:
>
> int some_thing(unsigned char * the_str);
>
> eg:
>
> Python:
>
> some_module.some_thing (the_str)
>
> Now I would like to feed it with a UTF-8 formatted string:
>
> test = u'Make \u0633\u0644\u0627\u0645, not war.'
>

 `test´ is not a UTF-8 encoded string.  It's a unicode string.

 To get a UTF-8 encoded string from a unicode string, use the `encode´
 method:

   some_module.some_thing(test.encode('utf-8'))


Yes you are correct. It is unicode string. But still if I use encode I
get the same error:

TypeError with message: in method 'some_thing', argument 1 of type
'unsigned char *'

So I am looking for a way to "cast" unicode string to unsigned char *.



You need to provide some more information about `some_module.some_thing´.
How is it implemented?  What Python type does it expect?  If it doesn't
take a unicode string and it doesn't take a byte string, I don't know
what kind of string it does take.

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

Re: SSL through python. possible ?

2008-05-05 Thread TkNeo
On May 2, 1:43 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> On 29 Apr, 15:56,TkNeo<[EMAIL PROTECTED]> wrote:
>
> > I need to do SSL file transfer using python? Is there a library i can
> > use ?
>
> > Thanks.
>
> If you have patience you can wait for Python 2.6 which will include a
> new ssl module, otherwise there are a lot of third party libraries out
> there which already binds OpenSSL for Python.
>
> --- Giampaolohttp://code.google.com/p/pyftpdlib/


Python 2.6. Ah, that sounds very nice. I would be happy to upgrade to
2.4 from 2.3.
My boss does not think we need to upgrade.
--
http://mail.python.org/mailman/listinfo/python-list


get the pid of a process with pexpect

2008-05-05 Thread Karim Bernardet

Hi

I am using pexpect to do ssh tunneling and to open a vnc server (jobs on 
a grid cluster). When the job is canceled, these 2 processes remain on 
the worker node (they are detached), so I have to kill them (using a 
trap command in the bash script of the job) but I need the pid of each 
process. I have tried to get it like this


ssh_tunnel = pexpect.spawn (tunnel_command % globals())
...
print ssh_tunnel.pid

but ssh_tunnel is not the pid of the ssh tunnel

Is there a way to get it using pexpect ?

Cheers

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


Nested os.path.join()'s

2008-05-05 Thread Paul Scott

Today, I needed to concatenate a bunch of directory paths and files
together based on user input to create file paths. I achieved this
through nested os.path.join()'s which I am unsure if this is a good
thing or not.

example:

if os.path.exists(os.path.join(basedir,picdir)) == True :
blah blah

Question is, is there a better way of doing this? The above *works* but
it looks kinda hackish...

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
--
http://mail.python.org/mailman/listinfo/python-list

Browser + local Python-based web server vs. wxPython

2008-05-05 Thread python
I'm looking at rewriting some legacy VB applications and am pondering
which of the following techniques to use:

1. Browser based GUI with local web server (Browser +
wsgiref.simple_server) (I'm assuming that simple_server is class I want
to build from for a local web server)

-OR-

2. wxPython based GUI

My thought is that a browser/local web server setup may be more portable
to mobile environments than wxPython and may offer a way to scale a
single user offline application to a multi-user online application using
a remote vs. local web server. Some groups of users may feel more
comfortable with a browser based interface as well.

I'm looking for feedback from anyone that has pondered the same question
as well as any pros/cons or tips from anyone that has chosen the
browser/lcoal web server route.

Thanks,

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


Re: Nested os.path.join()'s

2008-05-05 Thread Paul Scott

On Mon, 2008-05-05 at 16:21 +0200, Paul Scott wrote:
> example:
> 
> if os.path.exists(os.path.join(basedir,picdir)) == True :
> blah blah
> 

Sorry, pasted the wrong example...

Better example:

 pics =  glob.glob(os.path.join(os.path.join(basedir,picdir),'*'))


> Question is, is there a better way of doing this? The above *works* but
> it looks kinda hackish...

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
--
http://mail.python.org/mailman/listinfo/python-list

Re: pygame music, cant read mp3?

2008-05-05 Thread globalrev
On 5 Maj, 16:09, globalrev <[EMAIL PROTECTED]> wrote:
> On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
> wrote:
>
> > 2008/5/5, globalrev <[EMAIL PROTECTED]>:
>
> > > pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
>
> > Are you sure that:
>
> > os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?
>
> > Check it with python.
>
> > --
> > Regards,
> > Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
> >>> import os
> >>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
>
> False
>
> but...it is there
>
> >>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
>
> False
>
> does it matter if i use / or \? which si recommended?

i can find .png image in the same folder and when i just change
filename from snake.png to example1.mp3 it is false.

i renamed the file once, could that have anything to do with it?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert unicode string to unsigned char *

2008-05-05 Thread Simon Posnjak
On Mon, May 5, 2008 at 4:16 PM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
>
> On Mon, 5 May 2008 16:05:08 +0200, Simon Posnjak <[EMAIL PROTECTED]> wrote:
>
> > On Mon, May 5, 2008 at 3:48 PM, Jean-Paul Calderone <[EMAIL PROTECTED]>
> wrote:
> >
> > > On Mon, 5 May 2008 15:41:08 +0200, Simon Posnjak <[EMAIL PROTECTED]>
> wrote:
> > >
> > > > Hi!
> > > >
> > > > I have a C module for which I created a wrapper with swig. The
> function
> > > def is:
> > > >
> > > > C:
> > > >
> > > > int some_thing(unsigned char * the_str);
> > > >
> > > > eg:
> > > >
> > > > Python:
> > > >
> > > > some_module.some_thing (the_str)
> > > >
> > > > Now I would like to feed it with a UTF-8 formatted string:
> > > >
> > > > test = u'Make \u0633\u0644\u0627\u0645, not war.'
> > > >
> > >
> > >  `test´ is not a UTF-8 encoded string.  It's a unicode string.
> > >
> > >  To get a UTF-8 encoded string from a unicode string, use the `encode´
> > >  method:
> > >
> > >   some_module.some_thing(test.encode('utf-8'))
> > >
> >
> > Yes you are correct. It is unicode string. But still if I use encode I
> > get the same error:
> >
> > TypeError with message: in method 'some_thing', argument 1 of type
> > 'unsigned char *'
> >
> > So I am looking for a way to "cast" unicode string to unsigned char *.
> >
> >
>
>  You need to provide some more information about `some_module.some_thing´.
>  How is it implemented?  What Python type does it expect?  If it doesn't
>  take a unicode string and it doesn't take a byte string, I don't know
>  what kind of string it does take.

some_module.some_thing(the_string) function is a swig generated
function from a C lib. The C lib function expects unsigned char *.

The generated function is:

SWIGINTERN PyObject *_wrap_some_thing(PyObject *SWIGUNUSEDPARM(self),
PyObject *args) {
  PyObject *resultobj = 0;
  unsigned char *arg1 = (unsigned char *) 0 ;
  unsigned char result;
  void *argp1 = 0 ;
  int res1 = 0 ;
  PyObject * obj0 = 0 ;

  if (!PyArg_ParseTuple(args,(char
*)"O:cpot_printer_simple_printf",&obj0)) SWIG_fail;
  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_unsigned_char, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '"
some_thing"" "', argument " "1"" of type '" "unsigned char *""'");
  }
  arg1 = (unsigned char *)(argp1);
  result = (unsigned char)some_thing(arg1);
  resultobj = SWIG_From_unsigned_SS_char((unsigned char)(result));
  return resultobj;
fail:
  return NULL;
}
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nested os.path.join()'s

2008-05-05 Thread Jean-Paul Calderone

On Mon, 05 May 2008 16:28:33 +0200, Paul Scott <[EMAIL PROTECTED]> wrote:


On Mon, 2008-05-05 at 16:21 +0200, Paul Scott wrote:

example:

if os.path.exists(os.path.join(basedir,picdir)) == True :
blah blah



Sorry, pasted the wrong example...

Better example:

pics =  glob.glob(os.path.join(os.path.join(basedir,picdir),'*'))



Question is, is there a better way of doing this? The above *works* but
it looks kinda hackish...


How about not nesting the calls?

   >>> from os.path import join
   >>> join(join('x', 'y'), 'z') == join('x', 'y', 'z')
   True
   >>>

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


Re: pygame music, cant read mp3?

2008-05-05 Thread globalrev
On 5 Maj, 16:29, globalrev <[EMAIL PROTECTED]> wrote:
> On 5 Maj, 16:09, globalrev <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
> > wrote:
>
> > > 2008/5/5, globalrev <[EMAIL PROTECTED]>:
>
> > > > pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
>
> > > Are you sure that:
>
> > > os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?
>
> > > Check it with python.
>
> > > --
> > > Regards,
> > > Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
> > >>> import os
> > >>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
>
> > False
>
> > but...it is there
>
> > >>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
>
> > False
>
> > does it matter if i use / or \? which si recommended?
>
> i can find .png image in the same folder and when i just change
> filename from snake.png to example1.mp3 it is false.
>
> i renamed the file once, could that have anything to do with it?

\\ or \ or / all works.


the title of the mp3 is a long number still. i mena if i go to
properties the name is example1.mpg but the title if i go to details
is stillt he old one.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nested os.path.join()'s

2008-05-05 Thread Paul Scott

On Mon, 2008-05-05 at 10:34 -0400, Jean-Paul Calderone wrote:
> How about not nesting the calls?
> 
> >>> from os.path import join
> >>> join(join('x', 'y'), 'z') == join('x', 'y', 'z')
> True
> >>>
> 

Great! Thanks. Didn't realise that you could do that... :)

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
--
http://mail.python.org/mailman/listinfo/python-list

Re: Nested os.path.join()'s

2008-05-05 Thread Grant Edwards
On 2008-05-05, Paul Scott <[EMAIL PROTECTED]> wrote:

> Today, I needed to concatenate a bunch of directory paths and files
> together based on user input to create file paths. I achieved this
> through nested os.path.join()'s which I am unsure if this is a good
> thing or not.
>
> example:
>
> if os.path.exists(os.path.join(basedir,picdir)) == True :
> blah blah

That's not an example of nested os.path.join()'s.

> Question is, is there a better way of doing this? 

I don't think so.

> The above *works* but it looks kinda hackish...

What about it do you think looks hackish?

I supposed you could do this instead:

  path = os.path.join(basedir,picdir)
  if os.path.exists(path) == True :
  blah blah

But I don't really see why that's any better.  

-- 
Grant Edwards   grante Yow! Like I always say
  at   -- nothing can beat
   visi.comthe BRATWURST here in
   DUSSELDORF!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about self, why not a reserved word?

2008-05-05 Thread Bruno Desthuilliers

globalrev a écrit :

sorry i noticed now a little error, i was playing around a lot and saw
that on the sel-example i had then called foo.hello() instead of
foo.Hello().


but it was an informing error now i egt it. was wondering about self
anyway so thanks for clearing it up.


but it still is a bit confusing that u can pass with any word.
wouldnt:


class Foo(object):
def Hello():
print "hi"


make more sense?


What would make sens in your example would be to either make hello a 
staticmethod, since it doesn't use any reference to the current instance 
nor it's class.




the class-thing seems inside out somehow in python.


Python's object model is indeed a bit pecular wrt/ most mainstream 
OOPLs. But once you understand how it works, it happens to be mostly 
well designed (IMHO) and really powerful.



if im doing
foo.Hello() im already saying that im using the class foo because i
did foo=Foo()


Nope. You are saying your using an instance of class Foo.


before and then still when calling Hello() i am
invisibly passing the class itself a s a parameter by default?


It's not the class that get passed (unless you use a classmethod, but 
that's not the case here), but the instance. And you are not "invisibly" 
passing it, you just pass it another way. In fact, foo.hello() is 
equivalent to type(foo).hello(foo).



just seems backwards and weird.


Each and every OOPL needs to have a way to "inject" the instance a 
method was called on into the method's local namespace. Python solved 
this it's own way - by making 'methods' thin wrappers around 
instance/function couples, these wrappers being in charge of calling the 
function with the instance as first argument. From the implementation 
POV, this allow to build methods on existing, more general features - 
functions and the descriptor protocol - instead of having to 
special-case them. From the programmer's POV, this allow to define 
functions outside classes, then dynamically add them as 'methods' either 
on a per-class or per-instance basis.


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


Pygame and PGU

2008-05-05 Thread Zaka
Hi. I need some help to make map system in PGU. For exmple we have 2
maps and when we leave first we enter to second.



   !


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


Re: Pygame and PGU

2008-05-05 Thread Diez B. Roggisch
Zaka wrote:

> Hi. I need some help to make map system in PGU. For exmple we have 2
> maps and when we leave first we enter to second.
> 
> 
> 
>!
> 
> 
> ___

What is a PGU? What is a map-system? And what is that ascii art above?

And what might you learn from reading this:

http://www.catb.org/~esr/faqs/smart-questions.html

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


Re: Pygame and PGU

2008-05-05 Thread Zaka
On 5 Maj, 16:45, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Zaka wrote:
> > Hi. I need some help to make map system in PGU. For exmple we have 2
> > maps and when we leave first we enter to second.
>
> > 
> >!
>
> > ___
>
> What is a PGU? What is a map-system? And what is that ascii art above?
>
> And what might you learn from reading this:
>
> http://www.catb.org/~esr/faqs/smart-questions.html
>
> Diez

PGU is http://www.imitationpickles.org/pgu/wiki/index

Meaby this is not map-system but map changer like in RPG game
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread n00m
it can be done like this:

osql=popen2.popen2('osql -E -S(local) -dpubs -c"GO" -n -
w800')
osql[1].write(query+'\nGO\n')
osql[1].close()
res=osql[0].readlines()
osql[0].close()
res=join(res,'')

btw, is it necessarily to close() osql[1] in order to get res?
without close() the script seems is waiting for smth.
I'd like to get "res" in a loop:
write()
read()
write()
read()
...
is it possible?
--
http://mail.python.org/mailman/listinfo/python-list


Interested to code leecher mods in python?

2008-05-05 Thread WorldWide
Hi. Is here anyone interested to help us code some bittorrent leecher
mods?
We need a bit help with the gui in the mods.
You just need to have python knowledge.
We have our own [quite successful] forums and a great team.

Please email me: [EMAIL PROTECTED]

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


Re: pygame music, cant read mp3?

2008-05-05 Thread J. Cliff Dyer
On Mon, 2008-05-05 at 07:32 -0700, globalrev wrote:
> On 5 Maj, 16:29, globalrev <[EMAIL PROTECTED]> wrote:
> > On 5 Maj, 16:09, globalrev <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > On 5 Maj, 14:17, "Wojciech Walczak" <[EMAIL PROTECTED]>
> > > wrote:
> >
> > > > 2008/5/5, globalrev <[EMAIL PROTECTED]>:
> >
> > > > > pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')
> >
> > > > Are you sure that:
> >
> > > > os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == 
> > > > True?
> >
> > > > Check it with python.
> >
> > > > --
> > > > Regards,
> > > > Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
> > > >>> import os
> > > >>> os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
> >
> > > False
> >
> > > but...it is there
> >
> > > >>> os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True
> >
> > > False
> >
> > > does it matter if i use / or \? which si recommended?
> >
> > i can find .png image in the same folder and when i just change
> > filename from snake.png to example1.mp3 it is false.
> >
> > i renamed the file once, could that have anything to do with it?
> 
> \\ or \ or / all works.
> 
> 
> the title of the mp3 is a long number still. i mena if i go to
> properties the name is example1.mpg but the title if i go to details
> is stillt he old one.
> 

Now I'm confused.  What is the name of the *file* on the filesystem?
You can verify this using

>>> os.listdir('C:/Python25/myPrograms/pygameProgs')

As for the question of \\ vs. \ vs. /:  Windows will accept forward
slashes, but you may run into trouble later on down the line if windows
treats one of your forward slashes as a command line option.  The native
format is to use backslashes as separators, but backslashes need to be
escaped in python's regular string literals, because of escape
sequences.  Single backslashes seem to be working for you, but that's
only because you've been lucky in not having escape characters following
your backslash.  Particularly, x, n, t, u, and U will cause trouble.
Probably others.

Cut'n'paste example:

$ python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52) 
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> '\efoo'
'\\efoo'
>>> '\dfoo'
'\\dfoo'
>>> '\ufoo'
'\\ufoo'
>>> '\uabcd'
'\\uabcd'
>>> u'\uabcd'
u'\uabcd'
>>> u'\ufoo'
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
0-4: end of string in escape sequence
>>> '\xfoo'
ValueError: invalid \x escape
>>> '\nfoo'
'\nfoo'
>>> print '\nfoo'

foo
>>>

Notice that the \ gets doubled (escaped) automatically by python in many
of the instances, but not for the \n, and an exception gets raised for
\u (in unicode strings only), and for \x (in regular strings too).  It's
safer just to escape your strings yourself.  So 'C:\\foo' is always
better than 'C:\foo', even though the latter may sometimes work.  Better
still is to create a list of directories, and use os.path.join(dirlist)
as follows:

directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
os.path.join(directory)

Then python can worry about the gritty details, and you don't have to.

-- 
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

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


Re: pygame music, cant read mp3?

2008-05-05 Thread Diez B. Roggisch
> directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
> os.path.join(directory)
> 
> Then python can worry about the gritty details, and you don't have to.

Or somewhat neater IMHO:

 
os.path.join('C:','Python25','myPrograms','pygameProgs','dront.mp3')

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


Re: logger output

2008-05-05 Thread skunkwerk
On May 4, 10:40 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 05 May 2008 00:33:12 -0300,skunkwerk<[EMAIL PROTECTED]> escribió:
>
>
>
> > i'm redirecting the stdout & stderr of my python program to a log.
> > Tests i've done on a simple program with print statements, etc. work
> > fine.  however, in my actual program i get weird output like this:
>
> > 2008-05-04 20:20:44,790 DEBUG Grabbing message from queue, if any
> > 2008-05-04 20:20:44,790 DEBUG DEBUG:doit:Grabbing message from queue,
> > if any
> > 2008-05-04 20:20:44,790 DEBUG DEBUG:doit:DEBUG:doit:Grabbing message
> > from queue, if any
> > 2008-05-04 20:20:44,790 DEBUG
> > DEBUG:doit:DEBUG:doit:DEBUG:doit:Grabbing message from queue, if any
>
> > class write2Log:
> >def write(self, x):
> >if x!='\n':
> >logger.debug(str(x))
>
> > any ideas what might be causing the problems?  some of the messages
> > being output are quite long - might this be a problem?
>
> Try this simplified example and see by yourself:
>
> import sys
>
> class Write2Log:
>  def write(self, x):
>  sys.__stdout__.write('[%s]' % x)
>
> sys.stdout = Write2Log()
>
> print "Hello world!"
> age = 27
> name = "John"
> print "My name is", name, "and I am", age, "years old."
>
> --
> Gabriel Genellina

thanks Gabriel,
   i tried the code you sent and got output like the following:
[My name is][][john][][and I am][][27][][years old.]

it doesn't really help me though.  does this have any advantages over
the syntax i was using?
are there any limits on what kind of objects the logger can write?  ie
ascii strings of any length?

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


Re: Python application distribution

2008-05-05 Thread Ville M. Vainio

ron.longo wrote:


unable to execute.  Why is this?  At this point I'm not really keen on
handing out the source files to my application, it feels unprofessional.


If you plan to deploy on windows, py2exe could be the more 
"professional" approach you are thinking of.

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


Re: Python application distribution

2008-05-05 Thread Ville M. Vainio

ron.longo wrote:

> unable to execute.  Why is this?  At this point I'm not really keen on
> handing out the source files to my application, it feels unprofessional.

If you plan to deploy on windows, py2exe could be the more 
"professional" approach you are thinking of.

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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Rhamphoryncus
On May 3, 4:31 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote:
> On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
> > On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
>
> > > Arnaud Delobelle wrote:
>
> > >> sum() works for any sequence of objects with an __add__ method, not
> > >> just floats!  Your algorithm is specific to floats.
>
> > > This occurred to me also, but then I tried
>
> > > sum(['abc', 'efg'], '')
>
> > Interesting, I always thought that sum is like shortcut of
> > reduce(operator.add, ...), but I was mistaken.
>
> > reduce() is more forgiving:
> > reduce(operator.add, ['abc', 'efg'], '' ) # it works
> > 'abcefg'
>
> Hm, it works for lists:
> sum(([1], [2]), [])
> [1, 2]
>
> However I find the seccond argument hack ugly.
> Does the sum way have any performance advantages over the reduce way?

The relative differences are irrelevant.  The important thing is they
both perform quadratically, which makes them the wrong choice (unless
you can guarantee your inputs are trivial.)

$ python2.5 -m timeit 'x = [[0]*1000]*10' 'sum(x, [])'
1000 loops, best of 3: 566 usec per loop
$ python2.5 -m timeit 'x = [[0]*1000]*100' 'sum(x, [])'
10 loops, best of 3: 106 msec per loop
$ python2.5 -m timeit 'x = [[0]*1000]*1000' 'sum(x, [])'
10 loops, best of 3: 18.1 sec per loop

Per element of the outer list, that's 0.0566, 1.06, 18.1 msec.
Nasty.  Use this instead:

$ python2.5 -m timeit -s 'x = [[0]*1000]*10' 'y = []' 'for a in x:
y.extend(a)'
1 loops, best of 3: 80.2 usec per loop
$ python2.5 -m timeit -s 'x = [[0]*1000]*100' 'y = []' 'for a in x:
y.extend(a)'
1000 loops, best of 3: 821 usec per loop
$ python2.5 -m timeit -s 'x = [[0]*1000]*1000' 'y = []' 'for a in x:
y.extend(a)'
10 loops, best of 3: 24.3 msec per loop
$ python2.5 -m timeit -s 'x = [[0]*1000]*1' 'y = []' 'for a in x:
y.extend(a)'
10 loops, best of 3: 241 msec per loop
$ python2.5 -m timeit -s 'x = [[0]*1000]*10' 'y = []' 'for a in x:
y.extend(a)'
10 loops, best of 3: 2.35 sec per loop

Per element of the outer list t hat's 0.00802, 0.00821, 0.0243,
0.0241, 0.0235 msec.  At 1000 elements it seemed to cross some
threshold (maybe cache related, maybe allocation related), but overall
it scales linearly.  Know your algorithm's complexity.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert unicode string to unsigned char *

2008-05-05 Thread Martin v. Löwis
> some_module.some_thing(the_string) function is a swig generated
> function from a C lib. The C lib function expects unsigned char *.
> 
> The generated function is:

If you don't want to change the generated function, I recommend to
put a wrapper around it, as Jean-Paul suggested:

def some_thing(s):
  return some_thing_real(s.encode("utf-8"))

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


Re: generator functions in another language

2008-05-05 Thread castironpi
On May 5, 12:28 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 05 May 2008 00:09:02 -0300, hdante <[EMAIL PROTECTED]> escribió:
>
>
>
>
>
> >  Isn't this guy a bot ? :-) It's learning fast. I believe there is a
> > "frame" in C, composed of its stack and globals. For generators in C,
> > you may look for "coroutines". For example, see:
>
> >http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
>
> >  A sample code follows:
>
> > #define crBegin static int state=0; switch(state) { case 0:
> > #define crReturn(i,x) do { state=i; return x; case i:; } while (0)
> > #define crFinish }
> > int function(void) {
> >     static int i;
> >     crBegin;
> >     for (i = 0; i < 10; i++)
> >         crReturn(1, i);
> >     crFinish;
> > }
>
> >  The "suspended state" is saved in the static variable. It's not
> > necessary to save the complete "frame", only the suspended state.
>
> Quoting the author himself, "this is the worst piece of C hackery ever seen"
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -

At some point, code goes "on" and "off" the processor, which knowledge
I do owe to spending money.  Thus, if the group news is a localcy
(other dimension of currency), that's bounce check the house dollar.
What do [second person plural] spend on [vernacular]?

More strictly speaking, processor freely goes on and off binaries.  Is
Goto a hardware instruction?  Perhaps a Linux-Python-binding could
yield a frame, pun intended.  Do [you] have access the file system?

Could yield merely be implemented as multiple strings of processses?
Get the variables on disk.  Question is, is it worth optimizing away
from flash rom?  There's a gig of chips in a bowling ball.


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


Re: config files in python

2008-05-05 Thread Francesco Bochicchio
On Mon, 05 May 2008 00:35:51 -0700, sandipm wrote:

> Hi,
>  In my application, I have some configurable information which is used
> by different processes. currently I have stored configration in a
> conf.py file as name=value pairs, and I am importing conf.py file to
> use this variable. it works well
> 
> import conf
> print conf.SomeVariable
> 
> but if I need to change some configuration parameteres,  it would need
> me to restart processes.
> 
> I want to store this data in some conf file (txt) and would like to
> use it same way as I am using these variables as defined in py
> files.
> 
> one solution I can think of is writing data as a dictionary into conf
> file. and then by reading data, apply eval on that data. and update
> local dict? but this is not a good solution
> 
> any pointers?
> 
> Sandip

 The 'simple but relatively dangerous way', already suggested, is to
 reload() the module. 

A safer way - but requiring more work - could be to build something around
the Configparser module in the standard library ...

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


Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-05 Thread Robert Kern

Gabriel Genellina wrote:

Python doesn't require __add__ to be associative, so this should not be used as 
a general sum replacement. But if you know that you're adding floating point 
numbers you can use whatever algorithm best fits you. Or use numpy arrays; I 
think they implement Kahan summation or a similar algorithm.


No, we do a straightforward sum, too. Less magic in the default case.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


STL multimap

2008-05-05 Thread castironpi
Is multimap just a syntax-checked dictionary of mutable sequences?

Is def( a ): a[:]= [x] a trick or part of the language?  It looks
pretty sharp in variable-width.
--
http://mail.python.org/mailman/listinfo/python-list


Re: get the pid of a process with pexpect

2008-05-05 Thread Nick Craig-Wood
Karim Bernardet <[EMAIL PROTECTED]> wrote:
>  Hi
> 
>  I am using pexpect to do ssh tunneling and to open a vnc server (jobs on 
>  a grid cluster). When the job is canceled, these 2 processes remain on 
>  the worker node (they are detached), so I have to kill them (using a 
>  trap command in the bash script of the job) but I need the pid of each 
>  process. I have tried to get it like this
> 
>  ssh_tunnel = pexpect.spawn (tunnel_command % globals())
>  ...
>  print ssh_tunnel.pid
> 
>  but ssh_tunnel is not the pid of the ssh tunnel
> 
>  Is there a way to get it using pexpect ?

If I understand you correctly what you need to do is run "echo $$" on
the remote shell then "exec tunnel_command".  The $$ will print the
pid and the exec will run tunnel_command without changing the pid.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: Script using generators produces different results when invoked as a CGI

2008-05-05 Thread Nick Craig-Wood
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>  En Mon, 05 May 2008 00:31:45 -0300, Barclay, Ken <[EMAIL PROTECTED]> 
> escribió:
> 
> > I attended David Beazley's awe-inspiring tutorial on the use of
> > generators in systems programming:
> >http://www.dabeaz.com/generators/
> > http://www.dabeaz.com/generators/>
> >I used his approach to write a web tool that can display search results
> > from different log files. But the resulting script produced fewer
> > results when invoked as CGI than it did when run from the command line,
> > and I can't figure out why.
> 
> > Problem: For small sets of files this works great. But when I had 19Meg
> > worth of log files in a test directory, the script would return the
> > correct number of matching lines (288) only when it was invoked directly
> > from the command line. When invoked from a CGI script, it returns 220
> > lines instead
> 
>  No entry in the error log, on the web server? (Apache?)
>  Perhaps you're hitting some internal limit of the cgi process, either memory 
> or cpu time per request or temp file size...
>  Are you sure the script runs to completion? Output a message at the
>  end, to be sure.

Check the ownership of all the files too.  Remember that the web
server (and hence your cgi) will likely run as nobody or www-data.
You are unlikely to be logging in as one of those users.


-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass a multiline arg to exec('some.exe arg')?

2008-05-05 Thread Ian Kelly
>  btw, is it necessarily to close() osql[1] in order to get res?
>  without close() the script seems is waiting for smth.
>  I'd like to get "res" in a loop:
>  write()
>  read()
>  write()
>  read()
>  ...
>  is it possible?

Yes, call flush() each time you're done writing.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Twisted-Python] Counting errors in a DeferredList and avoiding Unhandled error in Deferred messages

2008-05-05 Thread Jean-Paul Calderone

On Mon, 5 May 2008 19:10:39 +0200, Terry Jones <[EMAIL PROTECTED]> wrote:

If I pass a list of deferreds to DeferredList and want to add a callback to
the DeferredList to look at whatever errors have occurred in the underlying
deferreds, should I do something like this:

 deferreds = []
 for x in whatever:
   deferreds.append(funcReturningDeferred(x))

 dl = DeferredList(deferreds)
 dl.addCallback(errorCheckingFunc)

 for d in deferreds:
   d.addErrback(lambda _: pass)


This ensures that errorCheckingFunc gets defer.FAILURE for those deferreds
that finished up in their errback chain. Adding the lambda _: pass errback
to each deferred in deferreds after it has been passed to DeferredList
makes sure the errback chain doesn't later reach its end with an unhandled
error.

It that the right/best/approved way to handle needing to deal with errors
in the callback of a DeferredList and not trigger the "Unhandled error in
Deferred" message?



You can do this (if you replace `pass´ with `None´, anyway) or you can
pass `consumeErrors=True´ to the `DeferredList´ initializer which will
make it do something equivalent.

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

Visual Studio 6 compile of 2.5.2 fails with missing db.h

2008-05-05 Thread brucoder
Hi Folks,

Searched the archives, but I can only find mention of db.h problems
relating to Linux.

I've downloaded the source for 2.5.2 and am trying to compile it in
Visual Studio 6 (SP6).  The error reports read:

Configuration: _bsddb - Win32
Debug
Compiling...
_bsddb.c
C:\Documents and Settings\Tim\My Documents\Python-2.5.2\Modules
\_bsddb.c(90) : fatal error C1083: Cannot open include file: 'db.h':
No such file or directory
Error executing cl.exe.

_bsddb_d.pyd - 1 error(s), 0 warning(s)

Any pointers?  A prerequisite that I might be missing?  The source is
the Python-2.5.2.tar.gz from the Python.org site.

Thanks for any help,
Tim
--
http://mail.python.org/mailman/listinfo/python-list


Re: generator functions in another language

2008-05-05 Thread J. Cliff Dyer
On Mon, 2008-05-05 at 10:08 -0700, [EMAIL PROTECTED] wrote:
> At some point, code goes "on" and "off" the processor, which knowledge
> I do owe to spending money.  Thus, if the group news is a localcy
> (other dimension of currency), that's bounce check the house dollar.
> What do [second person plural] spend on [vernacular]? 

Sometimes I'm not sure whether castironpi is a bot or a really good
troll who wants us to think he or she is a bot.  

At any rate, somebody's having a chuckle.

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


cgitb performance issue

2008-05-05 Thread Ethan Furman

Greetings!

I tried adding a form to our website for uploading large files.  
Personally, I dislike the forms that tell you you did something wrong 
and make you re-enter *all* your data again, so this one cycles and 
remembers your answers, and only prompts for the file once the rest of 
the entered data is good.  However, the first time the form loads it can 
take up to 30 seconds... any ideas why?


My server is using Apache 2.0.53 and Python 2.4.1 on a FreeBSD 5.4 system.

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

Re: unicode newbie - printing mixed languages to the terminal

2008-05-05 Thread David
>  I suggest you read http://www.amk.ca/python/howto/unicode to demystify what
> Unicode is and does, and how to use it in Python.

That document really helped.

This page helped me to setup the console:http://www.jw-stumpel.nl/stestu.html#T3

I ran:

dpkg-reconfigure locales # And enabled a en_ZA.utf8
update-locale LANG=en_ZA.utf8

(And then rebooted, but I don't know if that was necessary).

I can now print mixed language unicode to the console from Python.

Thanks for your help.

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


Re: So you think PythonCard is old? Here's new wine in an old bottle.

2008-05-05 Thread jbarciela
John, you are the man

> during my search for perfection, I found Qooxdoo (http://qooxdoo.org/).
>
> ...
>
> I found QxTransformer 
> (http://sites.google.com/a/qxtransformer.org/qxtransformer/Home) which is a
> XSLT toolkit that creats XML code that invoke qooxdoo.

Qooxdoo is indeed really impressive. But I read that YAHOO will serve
the javascript files for you from their CDN when you use YUI, for
free, and that's no peanuts, so I wonder, did you find anything at all
like that that could be used with YUI?

I have evaluated XForms, Laszlo, Flex, ZK, ... but I have to say
QxTransformer is the cleverest solution I have found so far (thanks to
you). I love it.


> I want Pythoncard.

I feel with you

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


Re: SSL through python. possible ?

2008-05-05 Thread TkNeo
On May 2, 1:52 pm, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On May 2, 1:20 pm, Heikki Toivonen <[EMAIL PROTECTED]> wrote:
>
> > Mike Driscoll wrote:
> > > On Apr 29, 8:56 am,TkNeo<[EMAIL PROTECTED]> wrote:
> > >> I need to do SSL file transfer using python? Is there a library i can
> > >> use ?
>
> > >http://sandbox.rulemaker.net/ngps/m2/
>
> > M2Crypto has since moved tohttp://chandlerproject.org/Projects/MeTooCrypto
>
> > --
> >   Heikki Toivonen
>
> Whoops...I just went with the first link Google gave me. The link I
> gave doesn't mention that the project has moved. Looks like the one
> you link to is the 9th link on my Google search using the terms:
> "python m2crypto".
>
> Sorry if I spread misinformation though.
>
> Mike

ok i have tried around a lot but no luck. I think M2Crypto is my best
option except it requires a minimum of python 2.4 which i don't have.

What i am trying to do is to do an FTP transfer that uses SSL
(username, password authentication) and not a certificate file. The
few example i have found of the Openssl module use a certificate for
authentication unlike what i want to do.

Anyone has any ideas ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: ]ANN[ Vellum 0.16: Lots Of Documentation and Watching

2008-05-05 Thread Ville M. Vainio
"Zed A. Shaw" <[EMAIL PROTECTED]> writes:

> GPLv3?
>
> How do people feel about Vellum's GPLv3 status?  It actually doesn't
> impact anyone unless you embed Vellum into a project/product or you

Yeah, but it effectively prevents people from embedding it into their
apps that wish to remain BSD/MIT clean.

It's not likely that some evil corporation is going to hijack Vellum
source code as a basis of their next evil app (which is basically what
GPL is used to prevent) any time soon, so I don't really see a
particular reason for such a developer-oriented tool to be released
under GPL.

Basically, avoiding GPL maximizes the brainshare that a small-ish tool
is going to attract, and many (including myself, FWIW) view GPL as a
big turn-off when I consider spending some time to familiarize myself
with a tool, or recommending it to someone else.

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


Re: So you think PythonCard is old? Here's new wine in an old bottle.

2008-05-05 Thread Daniel Fetchinson
>
> For serveral years, I have been looking for a way to migrate away from
> desktop GUI/client-server programming onto the browser based network
> computing model of programming.  Unfortunately, up until recently,
> browser based programs are very limited - due to the limitation of
> HTML itself.  Eventhough PythonCard hasn't keep up with the latest
> widgets in wxpython, the programs so created still works a lot better
> - until now.
>
> If you look at programs at some of the major sites these days - like
> Google calendar, Netflix, blockbuster, and so forth - you would
> undoubtedly notice that the quality of the programs are pretty much at
> par with the desktop programs we use everyday.  Since the curious mind
> wanted to know how these programs are done, I started investigating
> and found out that what a difference a few years have made to
> Javascript - the once much hated beast of the Internet age - and
> during my search for perfection, I found Qooxdoo (http://
> qooxdoo.org/).
>
> Qooxdoo is a Javascript toolkit that sits on top of Ajax.  Take a look
> at some of the *impressive* widgets
> at http://demo.qooxdoo.org/current/showcase/#Form.
>
> So, what's that got to do with Pythoncard?  Read on.
>
> After trying for a few days learning Qooxdoo, my head really really
> hurts.  Getting too old to learn this stuff, I was mumbling.
>
> Then I looked some more.  I found QxTransformer (http://
> sites.google.com/a/qxtransformer.org/qxtransformer/Home) which is a
> XSLT toolkit that creats XML code that invoke qooxdoo.
>
> So, what's that got to do with Pythoncard?  Read on.
>
> After trying for a few days learning QxTransformer, my head really
> really hurts.  Getting too old to learn
> this stuff, I was mumbling.
>
> I want Pythoncard.
>
> Damn Pythoncard!  Once you got hooked, everything else looks
> impossibly complicated and unproductive.
>
> But then I looked closer.  It turns out the XML file created by
> QxTransformer is *very* similar in structure when compared to the
> resource files used in PythonCard.  Since there are no GUI builders
> for QxTransformer, and I can't affort to buy the one for Qooxdoo
> (Java!  Yuk!), I decided to roll up my sleeves, took the Pythoncard's
> Layout Manager and modified it and created my own "Poor Man's Qooxdoo
> GUI Layout Designer".
>
> The result?  See the partially completed application at:
>
> http://test.powersystemadvisors.com/
>
> and the same application running from the desktop:
>
> http://test.powersystemadvisors.com/desktopHelloWorld.jpg
>
> It shouldn't be long before I can fill in the gaps and have the GUI
> builder maps the rest of the Pythoncard widgets to Qooxdoo widgets.
> Once I've done that, I can have the same application running from the
> desktop, or from the browser.  And it shouldn't take more than minutes
> to create such applications.
>
> Welcome to the modernized world of Pythoncard!!!



Any reason you chose qooxdoo over ext.js?

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

Re: How do I say "Is this a function"?

2008-05-05 Thread Fabiano Sidler

John Henry schrieb:

  exec fct



You don't want this. You want to store the function in a list instead:

l = [ f1, f3, others ]
for i in [0,1]: l[i]()

Greetings,
Fabiano
--
http://mail.python.org/mailman/listinfo/python-list


need help of regular expression genius

2008-05-05 Thread RJ vd Oest
 

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

psycopg2 ReferenceManual

2008-05-05 Thread David Anderson
Hi all, where can I find the reference manual from the psycopg2 or the
dbapi2.0 because in their official pages I could'nt find
thx
--
http://mail.python.org/mailman/listinfo/python-list

listing computer hard drives with python

2008-05-05 Thread Ohad Frand
Hi

I am looking for a way to get a list of all active logical hard drives
of the computer (["c:","d:"..])

 

Thanks,

Ohad

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

Re: Best way to store config or preferences in a multi-platform way.

2008-05-05 Thread python
Lance,

> I am still undecided if the ability for the user to edit the file 
> independently of the program is a good or bad thing.

I prefer user viewable plain (non-XML) text files because:

- easy to make a change in case of emergency
- easy to visually review and search
- easy to version control, diff, and optionally spellcheck
- easy to translate
- easy to generate programmatically
- less opportunity for corruption
- best compression

IMO, the 3 biggest advantages are:
- easy to make field changes in case of emergency
- diff
- less opportunity for corruption

Interesting thread. I'm looking forward to hearing what others say on
this topic.

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


Re: STL multimap

2008-05-05 Thread Aaron Watters
Hi there.  Maybe a little more context would
help us figure out what you want here...

On May 5, 1:28 pm, [EMAIL PROTECTED] wrote:
> Is multimap just a syntax-checked dictionary of mutable sequences?

I think the equivalent of a multimap can be
implemented several different ways, depending on
what you need:

  for
   1 maps to 2,3
   5 maps to 7
  - dictionary mapping to lists
   { 1:[2,3], 5:[7] } # supports unhashable values
  - dictionary mapping to dictionary
   { 1:{2:None,3:None}, 4:{7:None} } # faster for certain lookups
and dense data
  - dictionary with tuple/pairs as keys
   { (1,2):None, (1,3):None, (4,7):None } # streamlined for
existence testing

If you search usenet (google groups) for multimap
you will find some nice discussions by Alex Martelli and others.

> Is def( a ): a[:]= [x] a trick or part of the language?  It looks
> pretty sharp in variable-width.

You lost me here.

python 2.6:
>>> def (a): a[:]=[x]
  File "", line 1
def (a): a[:]=[x]
^
SyntaxError: invalid syntax

All the best.  -- Aaron Watters

===
http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=gaping+security+hole
--
http://mail.python.org/mailman/listinfo/python-list


os.open and O_EXCL

2008-05-05 Thread Ethan Furman

Greetings!

I am trying to lock a file so no other process can get read nor write 
access to it.  I thought this was possible with os.open(filename, 
os.O_EXCL), but that is not working.  I am aware of the win32file option 
to do file locking, so my question is this:  what is the purpose of the 
os.O_EXCL flag?


Thanks for any help.
--
Ethan
--
http://mail.python.org/mailman/listinfo/python-list

Re: Best way to store config or preferences in a multi-platform way

2008-05-05 Thread python
Lance,

> I am still undecided if the ability for the user to edit the file 
> independently of the program is a good or bad thing.

I prefer user viewable plain (non-XML) text files because:

- easy to make a change in case of emergency
- easy to visually review and search
- easy to version control, diff, and optionally spellcheck
- easy to translate
- easy to generate programmatically
- less opportunity for corruption
- best compression

IMO, the 3 biggest advantages are:
- easy to make field changes in case of emergency
- diff
- less opportunity for corruption

Interesting thread. I'm looking forward to hearing what others say on
this topic.

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


Writing elapsed time as a string

2008-05-05 Thread Simon Pickles

Hello.

I'm sorry if this has been asked a thousand (million) times.

Is there a nifty pythonesque way to produce a string representing an 
elapsed time period, in terms of years, months, days, hours, mins, seconds?


I am storing times in a MySQL db, and would love to be able to write the 
time elapsed between accesses of certain data. These are in seconds 
since the epoch, as produced by time.time()


It is probable right in front of me in the docs but I am spinning off 
into outer space (mentally!)


Thanks for the temporary loan of your clarity and experience.

Simon
--

http://www.squirtual-reality.com

Linux user #458601 - http://counter.li.org.



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


Writing elapsed time as a string

2008-05-05 Thread Simon Pickles

Hello.

I'm sorry if this has been asked a thousand (million) times.

Is there a nifty pythonesque way to produce a string representing an 
elapsed time period, in terms of years, months, days, hours, mins, seconds?


I am storing times in a MySQL db, and would love to be able to write the 
time elapsed between accesses of certain data. These are in seconds 
since the epoch, as produced by time.time()


It is probable right in front of me in the docs but I am spinning off 
into outer space (mentally!)


Thanks for the temporary loan of your clarity and experience.

Simon
--

http://www.squirtual-reality.com

Linux user #458601 - http://counter.li.org.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing 'bad' filenames from raising errors in os.path

2008-05-05 Thread python
Matimus and John,

Thank you both for your feedback.

Matimus: I agree with your analysis. I blame lack of caffeine for my
original post :)

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


Re: ISBN Barecode reader in Python?

2008-05-05 Thread Max Erickson
Nick Craig-Wood <[EMAIL PROTECTED]> wrote:

> Joseph <[EMAIL PROTECTED]> wrote:
>>  All: I have written a program to query Amazon with ISBN and get
>>  the book details. I would like to extend so that I can read
>>  ISBN from the barcode (I will take a photo of the same using
>>  webcam or mobile). Are there any opensource/free SDK doing the
>>  same? As it is a hobby project, I don't like to spend money on
>>  the SDK. 
> 
> Pick yourself up a cue-cat barcode reader, eg from here or ebay
> 
>   http://www.librarything.com/cuecat
> 
> These appear as a keyboard and "type" the barcode in to your
> program. 
> 
> Cheap and effective.
> 

The killer application for ISBN lookup on Amazon is checking prices 
while in the bookstore. Being able to email a photo from your phone  
and then getting an email with the Amazon price in response would be 
way easier than typing the isbn into Google or whatever.


max

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


Re: [ANN] Vellum 0.16: Lots Of Documentation and Watching

2008-05-05 Thread Ville M. Vainio
[EMAIL PROTECTED] writes:

> I didn't find your language offensive but you might consider toning down
> your review of the Awesome Window Manager :)

Nah - keep up the bad attitude. Your (Zed) blog/articles are one of
the few things on the programmosphere that actually make me laugh
audibly.

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


Re: Visual Studio 6 compile of 2.5.2 fails with missing db.h

2008-05-05 Thread brucoder
On May 5, 11:43 am, brucoder <[EMAIL PROTECTED]> wrote:
> Hi Folks,
>
> Searched the archives, but I can only find mention of db.h problems relating 
> to Linux.
>
> I've downloaded the source for 2.5.2 and am trying to compile it in Visual 
> Studio 6 (SP6).

I've just stepped back to 2.3.7 and receive the same error when
compiling bsddb...

>  The error reports read:
>
> Configuration: _bsddb - Win32 Debug
> Compiling...
> _bsddb.c
> C:\Documents and Settings\Tim\My Documents\Python-2.5.2\Modules\_bsddb.c(90) 
> : fatal error C1083: Cannot open include file: 'db.h':
> No such file or directory
> Error executing cl.exe.
>
> _bsddb_d.pyd - 1 error(s), 0 warning(s)

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


Re: ISBN Barecode reader in Python?

2008-05-05 Thread Ville M. Vainio
Max Erickson <[EMAIL PROTECTED]> writes:

> The killer application for ISBN lookup on Amazon is checking prices 
> while in the bookstore. Being able to email a photo from your phone  
> and then getting an email with the Amazon price in response would be 
> way easier than typing the isbn into Google or whatever.

Yeah, or just create a S60 python app to do it directly. Basically,
just put up a web service somewhere that allows pushing an image of
the barcode and returns the lowest price for that item, and the PyS60
app will be done in a day.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are rank noobs tolerated, here?

2008-05-05 Thread notbob
On 2008-05-04, notbob <[EMAIL PROTECTED]> wrote:

> I'm trying to learn how to program.  I'm using:
>   
> How to Think Like a Computer Scientist
>
> Learning with Python
> 2nd Edition

http://openbookproject.net//thinkCSpy/index.xhtml

OK then, using the above, I get everything up till chap 3 and functions and
then it all falls apart.  I try using his code and nothing.  I'm running
vers 2.5.1 on slackware 12.  Here's what I don't get:

--

"Here is an example of a user-defined function that has a parameter:


def print_twice(bruce):
print bruce, bruce

This function takes a single argument and assigns it to the parameter named
bruce.  The value of the parameter (at this point we have no idea what it
will be) is printed twice, followed by a newline.  The name bruce was chosen
to suggest that the name you give a parameter is up to you, but in general,
you want to choose something more illustrative than bruce.

ME
is this just an example of how the def should be written and it doesn't
really do anthing... yet?  I read another newb explanation here:
http://www.codepedia.com/1/BeginnersGuideToPython_Functions
...and it doesn't work, either.  I define myfirstfunction in the pyth editor
and give the command print myfirstfuntion and I get back this:

when I add the ._doc_, it get this:
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'function' object has no attribute '_doc_'
so, there is a no go there, too.
ME


The interactive Python shell provides us with a convenient way to test
our functions.  We can use the import statement to bring the functions
we have defined in a script into the interpreter session.  To see how this
works, assume the print_twice function is defined in a script
named chap03.py.  We can now test it interactively by
importing it into our Python shell session:

ME
ok, I try and follow the above, but where is he getting the script?  So, I
make a script called chap03.py and put it in ~/pyth/chap03/.  
ME

>>> from chap03 import *
>>> print_twice('Spam')
Spam Spam
>>> print_twice(5)
5 5
>>> print_twice(3.14159)
3.14159 3.14159

ME
I then try an do the import thing above, but the pyth ed accepts none of it.
not from:
from ~/pyth/chap03/ import *   
from chap03 import *#taken from ~/pyth/
nor from any other configuration I can imagine, so that "from" command
makes no sense.  
ME


In a function call, the value of the argument is assigned to the
corresponding parameter in the function definition.  In effect, it is if
bruce = 'Spam' is executed when print_twice('Spam')
is called, bruce = 5 in print_twice(5), and
bruce = 3.14159 in print_twice(3.14159)."

ME
OK, I'm totally lost.  Neither the above or the other link works or make any
sense at all.  Is the above print_twice(5), etc, supposed to work like the
original print_twice(bruce) function (which still doesn't!), just with a
different parameter?  Call me stupid, but I'd sure like to get past this.
How am I supposed to get the original def to work?  I've yet to figure out
how to get plain ol':
bruce bruce
Yes, I've indented 4 spaces where I should.  
ME

--

I feel dumber'n a bag 0' hammers and in need of clarification.

Thank you
nb
--
http://mail.python.org/mailman/listinfo/python-list


Re: generator functions in another language

2008-05-05 Thread [EMAIL PROTECTED]
On May 4, 1:11 pm, [EMAIL PROTECTED] wrote:
> There is no such thing as a 'frame' per se in C; byte code is
> integral.  As there is no such thing as suspended state without
> frames, and no such thing as generators without suspended state.

Well, for implementing generators there are alternatives to using
frames + byte code. In CLPython generators are implemented with
closures. (Which does not help much when it comes to reimplementing
generators in C, alas.)

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


Re: confused about self, why not a reserved word?

2008-05-05 Thread Terry Reedy

"globalrev" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| sorry i noticed now a little error, i was playing around a lot and saw
| that on the sel-example i had then called foo.hello() instead of
| foo.Hello().

Lesson: whenever one inquires about an 'error', one should cut and paste 
the error traceback along with a relevant snippet of code. 



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


  1   2   >