Re: windows / unix path

2008-10-23 Thread Tim Roberts
greg <[EMAIL PROTECTED]> wrote:
>
>Dennis Lee Bieber wrote:
>> The command line is the only place the slash direction has any
>> effect any way... Avoid os.system(), subprocess with shell = True, and
>> forward is safe in any position.
>
>I'm not sure that's quite true. On Windows, it's not the
>shell that splits up the command line into arguments, it's
>the program being run. So you need to avoid any kind of
>exec or spawn operation, whether it goes through the shell
>or not, unless you know the program being run isn't going
>to interpret '/' as an option.

Well, you actually said the same thing as Dennis here, in a slightly
different way.

The executive summary here is that the Windows APIs all accept either
forward or backward slashes just fine.  The trouble happens when you start
using command lines, just as Dennis said.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Commercial Products in Python

2008-10-23 Thread Diez B. Roggisch

azrael schrieb:

Why don't you give a try to IronPython. I began playin with it
yesterday, and as far as I can see, My worries about selling a python
application are gone, so far.


Why? It's byte-compiled as the CPython code, and needs an explicit 
interpreter installed. So where is the advantage?


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


[2.5.1] Converting string to int?

2008-10-23 Thread Gilles Ganault
Hello

I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass
data from a dictionary to the database which expects an integer:

#array filled by reading a two-column text file as input
for (isbn,carton) in data.items():
#TypeError: int argument required
sql = "INSERT INTO books (isbn,carton) VALUES ('%s',%u)" %
(isbn,carton)

#Incorrect number of bindings supplied.  The current statement uses
0 and there are 2 supplied.  Current offset is 0
sql = "INSERT INTO books (isbn,carton) VALUES ('%s',%u)" %
(isbn,int(carton))

cursor.execute(sql,(isbn,carton))
==

What is the right way to turn items from a dictionary into an integer
so as to match the column definition in the database?

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


Re: [ANN]pygccxml - 1.0

2008-10-23 Thread Matthieu Brucher
Hi,

I'm trying to use your package, but the gccxml installer is not
available from your website anymore. Is it possible for you to upload
it again ?

Thanks,

Matthieu

2008/10/20 Roman Yakovenko <[EMAIL PROTECTED]>:
> Hello!
>
> I'm pleased to announce the 1.0 release of pygccxml.
>
> What is pygccxml?
> ===
>
> "...The purpose of the GCC-XML extension is to generate an XML description of 
> a
> C++ program from GCC's internal representation. "
>
> -- Introduction to GCC-XML
>
> The purpose of pygccxml is to read a generated file and provide a simple
> framework to navigate C++ declarations, using Python classes.
>
> Where is pygccxml?
> 
>
> Site: http://language-binding.net/pygccxml/pygccxml.html
>
> Download: http://language-binding.net/pygccxml/download.html
>
> What's new?
> ===
>
> Features
> -
>
> * Support for ellipsis was added.
>
> * New experimental back-end, based on ``.pdb`` (progam database file),
> was added.
>
> * New high-level API wrapper for ``.bsc`` (browse source code file) was added.
>
>
> Bug fixes
> -
>
> * Search algorithm, for template instantiated classes, was improved.
>
>
> For a more complete list, please see the news:
> http://language-binding.net/pygccxml/history/history.html
>
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-23 Thread Christian Heimes

Andy wrote:

2) Barriers to "free threading".  As Jesse describes, this is simply
just the GIL being in place, but of course it's there for a reason.
It's there because (1) doesn't hold and there was never any specs/
guidance put forward about what should and shouldn't be done in multi-
threaded apps (see my QuickTime API example).  Perhaps if we could go
back in time, we would not put the GIL in place, strict guidelines
regarding multithreaded use would have been established, and PEP 3121
would have been mandatory for C modules.  Then again--screw that, if I
could go back in time, I'd just go for the lottery tickets!! :^)


I'm very - not absolute, but very - sure that Guido and the initial 
designers of Python would have added the GIL anyway. The GIL makes 
Python faster on single core machines and more stable on multi core 
machines. Other language designers think the same way. Ruby recently got 
a GIL. The article 
http://www.infoq.com/news/2007/05/ruby-threading-futures explains the 
rationales for a GIL in Ruby. The article also holds a quote from Guido 
about threading in general.


Several people inside and outside the Python community think that 
threads are dangerous and don't scale. The paper 
http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf sums it 
up nicely, It explains why modern processors are going to cause more and 
more trouble with the Java approach to threads, too.


Python *must* gain means of concurrent execution of CPU bound code 
eventually to survive on the market. But it must get the right means or 
we are going to suffer the consequences.


Christian


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


Re: Possible read()/readline() bug?

2008-10-23 Thread Carl Banks
On Oct 22, 2:54 pm, Mike Kent <[EMAIL PROTECTED]> wrote:
> Before I file a bug report against Python 2.5.2, I want to run this by
> the newsgroup to make sure I'm not being stupid.
>
> I have a text file of fixed-length records I want to read in random
> order.  That file is being changed in real-time by another process,
> and my process want to see the changes to the file.  What I'm seeing
> is that, once I've opened the file and read a record, all subsequent
> seeks to and reads of that same record will return the same data as
> the first read of the record, so long as I don't close and reopen the
> file.  This indicates some sort of buffering and caching is going on.
>
> Consider the following:
>
> $ echo "hi" >foo.txt  # Create my test file
> $ python2.5              # Run Python
> Python 2.5.2 (r252:60911, Sep 22 2008, 16:13:07)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> f = open('foo.txt')  # Open my test file
> >>> f.seek(0)                # Seek to the beginning of the file
> >>> f.readline()             # Read the line, I get the data I expected
> 'hi\n'
> >>> # At this point, in another shell I execute 'echo "bye" >foo.txt'.  
> >>> 'foo.txt' now has been changed

I thought this might be a case where the shell unlinks foo.txt and
creates a new file... but it doesn't for me, and I still get the same
behavior as you.  It is indeed the buffering that's causing this.

> >>> # on the disk, and now contains 'bye\n'.
> >>> f.seek(0)                # Seek to the beginning of the still-open file
> >>> f.readline()             # Read the line, I don't get 'bye\n', I get the 
> >>> original data, which is no longer there.
> 'hi\n'
> >>> f.close()                 # Now I close the file...
> >>> f = open('foo.txt') # ... and reopen it
> >>> f.seek(0)               # Seek to the beginning of the file
> >>> f.readline()            # Read the line, I get the expected 'bye\n'
> 'bye\n'
>
> It seems pretty clear to me that this is wrong.  If there is any
> caching going on, it should clearly be discarded if I do a seek.

I totally disagree.  If you need to discard the buffers, there's a way
to do it: flush().  If you force seek() to discard perfectly good
buffers you will hurt performance when not dealing with volatile data.

Anyway, in Python 2.x, the behavior of the various file methods is
documented as reflecting the underlying C stdio library.  In fact, the
documentation for fseek specifically says it sets the file's current
position "like stdio's fseek()".  Whatever stdio does is what Python
does.  So even if this behavior were a bug, it would be a bug in
stdio, not in Python.


> Note
> that it's not just readline() that's returning me the wrong, cached
> data, as I've also tried this with read(), and I get the same
> results.  It's not acceptable that I have to close and reopen the file
> before every read when I'm doing random record access.

You can call f.flush() to force it to discard the cache.  Or use
unbuffered I/O.  Better yet, get rid of file I/O altogether and use an
memory mapped file.


> So, is this a bug, or am I being stupid?

Well, it's not a bug, so

Seriously, I advise you not to submit a bug report.  Doesn't mean
you're stupid, maybe you didn't know about unbuffered I/O or the
flush() method.  That just means you're uneducated. :)   But please
leave seek() out it.


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


"Find" in list of objects

2008-10-23 Thread Andreas Müller
Hi!

(Python 2.2.3 if this is relevant :-)

I have a list of objects with, lets say, the attributes "ID", "x" and
"y". Now I want to find the index of list element with ID=10.

Of course I can loop through the list manually, but is there a
construct like

list.find (10, key='ID')

? Thanks for your ideas.

Best regards,
Martin



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


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gilles Ganault
On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina"
<[EMAIL PROTECTED]> wrote:
>In case you didn't notice, B.D. already provided the answer you're after -  
>reread his 3rd paragraph from the end.

Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):

>> The recommended way is to pass the arguments to cursor.execute, ie:

I'm getting an error when doing it this way:

===
isbn = "123"
sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'"

#Incorrect number of bindings supplied.  The current statement uses 0
and there are 1 supplied.  Current offset is 0
cursor.execute(sql, (isbn,))
===

I don't know enough about Python and this wrapper to tell why it
triggers an error.

>> you want:
>> row = cursor.fetchone()
>> count = row[0]
>> if not count:

This wrapper doesn't seem to support fetchone():

=
#AttributeError: 'apsw.Cursor' object has no attribute 'fetchone'
row = cursor.fetchone()
=

This works, though:

cursor.execute(sql)
for row in cursor.execute(sql):
#Record not found -> Insert
if not row[0]:



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


Re: [ANN]pygccxml - 1.0

2008-10-23 Thread Roman Yakovenko
On Thu, Oct 23, 2008 at 9:20 AM, Matthieu Brucher
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to use your package, but the gccxml installer is not
> available from your website anymore. Is it possible for you to upload
> it again ?

No :-(. It caused too much damage and didn't work reliably.

I suggest you to follow GCCXML install instructions (
http://gccxml.org/HTML/Install.html ) and you will have it in less
than 20 minutes.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [2.5.1] Converting string to int?

2008-10-23 Thread Gilles Ganault
On Thu, 23 Oct 2008 09:19:07 +0200, Gilles Ganault <[EMAIL PROTECTED]>
wrote:
>I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass
>data from a dictionary to the database which expects an integer:

Found it: Apparently, this wrapper uses a different placeholder and
takes care of conversion if needed:

cursor.execute("INSERT INTO books (isbn,carton) VALUES (?,?)",
(isbn,carton))

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


Re: [ANN]pygccxml - 1.0

2008-10-23 Thread Matthieu Brucher
2008/10/23 Roman Yakovenko <[EMAIL PROTECTED]>:
> On Thu, Oct 23, 2008 at 9:20 AM, Matthieu Brucher
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I'm trying to use your package, but the gccxml installer is not
>> available from your website anymore. Is it possible for you to upload
>> it again ?
>
> No :-(. It caused too much damage and didn't work reliably.
>
> I suggest you to follow GCCXML install instructions (
> http://gccxml.org/HTML/Install.html ) and you will have it in less
> than 20 minutes.

Too bad, I'll have to wait, I need a full Internet access, which I
don't have at the moment :|

Thanks though ;)

Matthieu
-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list


Re: Append a new value to dict

2008-10-23 Thread Frank Niemeyer
[EMAIL PROTECTED] schrieb:
> Frank Niemeyer:
>> There's simply no
>> way to increment a non-existent value - not without performing some
>> obscure implict behind-the-scenes stuff.
> 
> Like importing and using a defaultdict(int).

There's nothing implicit in explicitly defining some default behaviour.

Frank

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


Re: Dummy explanation to win32com needed

2008-10-23 Thread Tim Golden

korean_dave wrote:

Hi. I need a dummy's explanation to utilizing the win32com component
to access Microsoft Excel.

So far, I have this code.

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = 1

workbook = xl.Workbooks.Open("C:\test.xls")


Well, for a start, you want to be raw-stringing that filename.
(And, possibly, putting it somewhere other than the root
of your c: drive ;) )



Now, my question is, where do I find the snytax I can use to access
such functions like workbook.ActiveSheet.Cells(1,1).Value etc...



All the pywin32 / win32com stuff is doing is wrapping the
Microsoft Excel Object Model. So, if you want to drive
Excel you have two tools: the Macro Recorder in Excel
itself; and Google:

http://www.google.co.uk/search?q=site%3Amicrosoft.com+excel%20object%20model



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


Re: PyGUI as a standard GUI API for Python?

2008-10-23 Thread Kay Schluehr
On 11 Okt., 09:56, lkcl <[EMAIL PROTECTED]> wrote:
> > The role of Python is somewhat arbitrary. This could change only if
> > Python becomes a client side language executed by AVM,V8etc.
>
> pyv8 -http://advogato.org/article/985.html
> pyjs.py - standalone python-to-javascript compiler, seehttp://pyjs.org.

O.K. you got me all. I give up!

I've already imlemented some small Flex supporting functionality in
the P4D Langlet [1] and I'll also checkout pyjamas ( didn't worn them
for long ) and if they are fine I work out a bridge the next days.
Then only style sheets are left :)

[1] http://pypi.python.org/pypi/P4D Langlet/
--
http://mail.python.org/mailman/listinfo/python-list


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Tino Wildenhain

Gilles Ganault wrote:

Hello

I'm trying to use the APSW package to access a SQLite database, but
can't find how to check if a row exists. I just to read a
tab-separated file, extract a key/value from each line, run "SELECT
COUNT(*)" to check whether this tuple exists in the SQLite database,
and if not, run an INSERT.

The problem is that "if not row" isn't run:

==
import apsw

connection=apsw.Connection("test.sqlite")
cursor=connection.cursor()

data = {}

f = open("data.tsv", "r") 
textlines = f.readlines()

f.close()

p = re.compile('^(\d+)\t(\d+)$') 
for line in textlines:

m = p.search(line)
if m:
data[m.group(1)] = m.group(2)

for (key,value) in data.items():
sql = "SELECT COUNT(*) FROM mytable WHERE key='%s'" % key
row=cursor.execute(sql)

#Why not run?
if not row:
print "Row doesn't exist : %s" % key
sql = "INSERT INTO mytable (key,value) VALUES ('%s',%u)" %
key,value
cursor.execute(sql)

connection.close(True)
sys.exit()
==

Any idea what's wrong with the above?


Apart from the other comments, what is obviously wrong is
the way you aliased the variables into SQL.
Please read on parametrized queries, e.g. the following
should work:

sql = "SELECT COUNT(*) FROM mytable WHERE key=%s"

cursor.execute(sql,(key,))

(see also SQL injection)

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need some advice

2008-10-23 Thread Bruno Desthuilliers

Larry Bates a écrit :

azrael wrote:

On Oct 22, 9:48 am, Bruno Desthuilliers  wrote:

azrael a écrit :


If my memory is me well http transfers data in plaintext.
Because of
the risk of datacapturing, is there a better soulutioon to suggest to
be more secure like shttp

I suppose you mean https...

(snip)

I mean shttp. (secure hyper text transfer protocol)




Bruno is correct, the protocol IS https, you don't type shttp into your 
browser get secure http connection.


Well, there *is* a shttp protocol too - or at least, there's a RFC. Now 
the fact is I never heard of it in 5 years of doing mostly web 
development, and it seems that there are pretty few (if any) working 
implementation available.


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


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Bruno Desthuilliers

Gilles Ganault a écrit :

On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina"
<[EMAIL PROTECTED]> wrote:
In case you didn't notice, B.D. already provided the answer you're after -  
reread his 3rd paragraph from the end.


Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):


The recommended way is to pass the arguments to cursor.execute, ie:


I'm getting an error when doing it this way:

===
isbn = "123"
sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'"

#Incorrect number of bindings supplied.  The current statement uses 0
and there are 1 supplied.  Current offset is 0
cursor.execute(sql, (isbn,))


There was a notice about checking the correct placeholder for your 
db-api implementation - it's not necessarily '%s' !-)



===

I don't know enough about Python and this wrapper to tell why it
triggers an error.


you want:
row = cursor.fetchone()
count = row[0]
if not count:


This wrapper doesn't seem to support fetchone():

=
#AttributeError: 'apsw.Cursor' object has no attribute 'fetchone'
row = cursor.fetchone()
=

This works, though:

cursor.execute(sql)
for row in cursor.execute(sql):
#Record not found -> Insert
if not row[0]:


Ok, so I wrongly assumed this apws stuff was db-api compliant, and you 
can as well forget everything I wrote. My fault, I should have 
double-checked this before answering.

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


Re: socket programming (client-server) error

2008-10-23 Thread Python


On 23 okt 2008, at 05:49, ryan wrote:


On Oct 22, 6:18 pm, Python <[EMAIL PROTECTED]> wrote:

On 22 okt 2008, at 13:50, ryan fox wrote:




i have implemented a small client server model to do file transfer
over a LAN network.



It work with some machines on the network and on others it doesnt.
when i run the server.py file in some machine then it pops up a
windows security alert.



The message is as follows:



 Do you want to keep blocking this program?
there are three options below it. 1. Keep Blocking 2. Unblock 3. Ask
Me later.


I selected the option  unblock.Even then the client and server are  
not

able to communicate.
I get a error saying that:-



socket.error: (10060, 'Operation timed out')



I guess its a firewall problem... How do i go abt it?
any help? --


does it work if you temporarily switch off the firewall?

gr
Arno


HI arno ,

In the firewall setting i have unblocked this program and tried. But
it works on some machines on the LAN and doesnt work on other
machines.
Even if the firewall is on it work on some machines. So narrowing down
on the problem seems tough here

any ideas?
--

yeah a million ideas...
really it sounds like a firewall problem, specially cu it work on one  
machine but not on the other.
try switch it off completely... obviously "unblocking" doesn't seem to  
do the job


if it works on one machine, the code is obviously ok
i assume you;re on a windows machine?

to mention some other possible reasons,
are you using an IP or DNS name?
maybe the firewall blocks the DNS server and can't retrieve an IP for  
the server?

can you access the internet from those machines?

maybe the machine is not on the same subnet as the server
can you ping the server?

for more reasons i'm afraid you have to try another list
since this doesn't sound like a python problem
and i'm definitely not a windows guru (only osx, linux and freebsd here)

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


Re: Append a new value to dict

2008-10-23 Thread bearophileHUGS
Marc 'BlackJack' Rintsch:
> counter['B'] = counter.get('B', 0) + 1

If you benchmark it, you will find that using the get() method it's
quite slower.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering python sets

2008-10-23 Thread Duncan Booth
Peter Otten <[EMAIL PROTECTED]> wrote:

> I guess I have to move the goal posts to beat you:
> 
 set([-1,-2]), set([-2,-1])
> (set([-2, -1]), set([-1, -2]))
> 
> For that one the number of slots doesn't matter because
> 
 hash(-1), hash(-2)
> (-2, -2)
> 

Neat.

>>> last = []
>>> for i in range(0,1,5):
pair = list(set(range(-2,i)))[-2:]
if pair != last:
print "%4d(%4d): %s" % (i, i*3/2, pair)
last = pair


   0(   0): [-1, -2]
   5(   7): [-2, -1]
  20(  30): [-1, -2]
  85( 127): [-2, -1]
 340( 510): [-1, -2]
1365(2047): [-2, -1]
5460(8190): [-1, -2]

The order of those two values reverses each time the hash table is 
resized, but they will always appear at the end of a set of consecutive 
integers from -2 upwards. (Highly implementation dependant of course.)

I think this demonstrates quite nicely how the hash table always 
contains  some power of 2 slots and is resized whenever it is about 
2/3rds full. Also it shows that even when you construct a set from a 
list, the set is grown one element at a time rather than pre-allocated 
(otherwise you wouldn't get the alternating order).

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Find" in list of objects

2008-10-23 Thread bearophileHUGS
Andreas Müller:
> is there a construct like
> list.find (10, key='ID')

You can create yourself a little convenience function, or you can use
something like the following. First some testing code:

class C:
def __init__(self, id):
self.id = id
def __repr__(self):
return "<%s>" % self.id
seq = map(C, [1, -5, 10, 3])
print seq

That prints:
[<1>, <-5>, <10>, <3>]

Then you can find the index of all the classes with id = 10:
print [i for i, obj in enumerate(seq) if obj.id == 10]

It returns a [2]. If seq doesn't contain the requires object(s) it
returns an empty list.

Or just the first, working lazily:
print (i for i, obj in enumerate(seq) if obj.id == 10).next()

This time if seq doesn't contain the requires object(s) it raises a
StopIteration exception.

You can of course wrap that into a function, using seq and 10 as
arguments.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Find" in list of objects

2008-10-23 Thread Gabriel Genellina
En Thu, 23 Oct 2008 05:23:51 -0200, Andreas Müller <[EMAIL PROTECTED]>  
escribió:



(Python 2.2.3 if this is relevant :-)

I have a list of objects with, lets say, the attributes "ID", "x" and
"y". Now I want to find the index of list element with ID=10.

Of course I can loop through the list manually, but is there a
construct like

list.find (10, key='ID')


If you define __eq__ for your objects you may use list.index:

class Obj:
  def __init__(self, id_, x=0, y=0):
self.id = id_
self.x = x
self.y = y
  def __eq__(self, other):
if not isinstance(other, Obj): raise NotImplementedError
return self.id==other.id

py> a = Obj(10)
py> b = Obj(11)
py> c = Obj(12)
py> alist = [a,b,c]
py> print alist.index(Obj(11))
1
py> print alist.index(Obj(20))
Traceback (most recent call last):
  File "", line 1, in 
ValueError: list.index(x): x not in list

Note that this is a "global" change - two separate instances with the same  
ID were "not equal" before, and are "equal" now, everywhere, not just  
regarding list.index


Of course you always have the old "for" loop solution (`enumerate` would  
make things a lot nicer, but it requires 2.3):


def index_by_id(alist, id_):
  for i in range(len(alist)):
if alist[i].id==id_:
  return i

--
Gabriel Genellina

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


substitution __str__ method of an instance

2008-10-23 Thread netimen
I couldn't substitute __str__ method of an instance. Though I managed
to substitute ordinary method of an instance:

from types import MethodType

class Foo(object):
pass

class Printer(object):

def __call__(self, obj_self):
return 'printed'

f = Foo()

f.printer = MethodType(Printer(), f, Foo)
print f.printer()  # works fine - I get: 'printed'

print f  # get: <__main__.Foo object at 0x00D69C10>
f.__str__ = MethodType(Printer(), f, Foo)
print f  # still get: <__main__.Foo object at 0x00D69C10>. Why?
Foo.__str__ = MethodType(Printer(), None, Foo)
print f  # works fine - I get: 'printed'


How can I substitute __str__ method of an instance?
--
http://mail.python.org/mailman/listinfo/python-list


Re: substitution __str__ method of an instance

2008-10-23 Thread Christian Heimes

netimen wrote:

How can I substitute __str__ method of an instance?


It's not possible. For performance and other reasons most __*__ methods 
are looked up on the type only.


Christian

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


Re: substitution __str__ method of an instance

2008-10-23 Thread Diez B. Roggisch
netimen wrote:

> I couldn't substitute __str__ method of an instance. Though I managed
> to substitute ordinary method of an instance:
> 
> from types import MethodType
> 
> class Foo(object):
> pass
> 
> class Printer(object):
> 
> def __call__(self, obj_self):
> return 'printed'
> 
> f = Foo()
> 
> f.printer = MethodType(Printer(), f, Foo)
> print f.printer()  # works fine - I get: 'printed'
> 
> print f  # get: <__main__.Foo object at 0x00D69C10>
> f.__str__ = MethodType(Printer(), f, Foo)
> print f  # still get: <__main__.Foo object at 0x00D69C10>. Why?
> Foo.__str__ = MethodType(Printer(), None, Foo)
> print f  # works fine - I get: 'printed'
> 
> 
> How can I substitute __str__ method of an instance?

You can't. Special methods are only looked up on classes. 

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


Re: Snapshot+Clipboard

2008-10-23 Thread [EMAIL PROTECTED]



Claudio Grondi wrote:
> 
> Yves Lange wrote:
>> Hello,
>> i'm searching a method to take a snapshot and save it in a jpg, bmp or 
>> gif file. I tried with win32api and win32con but it save the snapshot to 
>> the clipboard, so i tried to redirect this in a file but i have some 
>> problems while getting the IMAGE stocked in the clipboard and save it to 
>> a file. Can somebody help me ?
>> 
>> Questions:
>> -How can i read the snapshot in the clipboard ?
>> -How can i take a snapshot in a different way (less difficult) ?
>> 
>> Thks.
> 
> Use PIL which on Windows supports taking snapshots of the screen.
> 
> import ImageGrab
> GrabbedImage = ImageGrab.grab() # store screenshot as "RGB" Image
> GrabbedImage.save("TheScreenshot.jpg") # PIL evaluates extension
> 
> For more details see:
>http://effbot.org/imagingbook/imagegrab.htm
> (works on Windows only)
> 
> Claudio Grondi
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

In my project I need a module to do the ImageGrab's job but in linux,
so is there a linux version module by now or do you know the other module
fit for linux?

if anybody knows that, please reply me, thanks.

-- 
View this message in context: 
http://www.nabble.com/Snapshot%2BClipboard-tp5400375p20127327.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Append a new value to dict

2008-10-23 Thread [EMAIL PROTECTED]



Frank Niemeyer wrote:
> 
>> However incrementing a non-existing key throws an exception.
> 
> Right. And that's exactly what I would expect, according to the
> "principle of least surprise" Python tries to obey. There's simply no
> way to increment a non-existent value - not without performing some
> obscure implict behind-the-scenes stuff.
> 
>> So you 
>> either have to use a workaround:
>> 
>>  >>> try:
>> ...   counter['B'] += 1
>> ... except KeyError:
>> ...   counter['B'] = 1
> 
> Or you could simply use
> 
> if counter.has_key('B'):
> counter['B'] += 1
> else:
> counter['B'] = 1
> 
> Regards,
> Frank
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

or 

if 'B' in counter:
counter['B'] += 1
else:
ocunter['B'] = 1
-- 
View this message in context: 
http://www.nabble.com/Append-a-new-value-to-dict-tp19953085p20127415.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Tzury Bar Yochay
What is the reason math.pow yields OverflowError while python itself
can
calculate these large numbers. e.g:

>>> import math
>>> math.pow(100, 154)
1e+308
>>> math.pow(100, 155)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: math range error
>>> eval(('100*'* 155)[:-1])
100
000
000
000
000
L
>>>
--
http://mail.python.org/mailman/listinfo/python-list


Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread John Machin
On Oct 23, 8:21 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote:
> What is the reason math.pow yields OverflowError while python itself
> can
> calculate these large numbers. e.g:
>
> >>> import math
> >>> math.pow(100, 154)
> 1e+308
> >>> math.pow(100, 155)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> OverflowError: math range error>>> eval(('100*'* 155)[:-1])
>
> 100
> 000
> 000
> 000
> 000
> L

Because math.pow returns a float; 100 ** 155 won't fit in a float.
--
http://mail.python.org/mailman/listinfo/python-list


Re: better scheduler with correct sleep times

2008-10-23 Thread sokol
On Oct 22, 2:28 am, greg <[EMAIL PROTECTED]> wrote:
> sokol wrote:
> > Also, the
> > scheduler runs inside a loop. How do you suppose to
> > run other code while the loop is executing?
>
> The sleep function could be doing a select with a
> timeout on some other source of events, such as a
> socket or a gui input event stream. One possible
> response to such an event is to schedule another
> event. There's not so much need for that nowadays,
> since most gui libraries provide a way of scheduling
> timed events as part of their built-in event loop,
> but you might want to use something like this in
> a server that deals with network connections.
>
> Another possible use is discrete-event simulation,
> where the "sleep" function doesn't physically sleep
> but just advances a simulated time, and all events
> (other than the first one that starts everything off)
> are scheduled by callbacks for other events.
>
> So while its uses are rather specialized, I wouldn't
> say it's useless. The main problem is that its nature
> needs to be much more clearly spelled out in the
> docs -- it's something of an attractive nuisance the
> way it is.
>
> --
> Greg

I see. The delayfunc is user defined function so it
doesn't have to sleep at all. If you are creative
enough, you can use this scheduler in many ways.

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


Re: Module for creating a screenshot of a web page given a URL?

2008-10-23 Thread [EMAIL PROTECTED]



John J. Lee wrote:
> 
> [EMAIL PROTECTED] writes:
> 
>> > Untestetd, but I'm pretty sure something like this will do.
>> > If you need more control, and on windows, try pywinauto
>> 
>> I do need it to run on Windows. I'll check out pywinauto. Thanks.
> 
> Note he didn't say you *need* pywinauto to run on Windows.
> 
> 
> John
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

Is there anyway to do the same job in linux? 
The ImageGrab doesn't support for linux system.

If anyone knows that, please, reply me. Thanks a lot.
-- 
View this message in context: 
http://www.nabble.com/Module-for-creating-a-screenshot-of-a-web-page-given-a-URL--tp5188873p20127934.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


How to get the time of message Received of an outlook mail in python..

2008-10-23 Thread [EMAIL PROTECTED]
Hi,,
  How can we access the time of message received ( UTC time) of an
outlook mail in python? As far as I know the time which it displays in
the mail is not the exact time... this UTC time will be present in
MIME Header of an outlook mail.

Any Help is appreciated..and thanks in advance,,
Venu.
--
http://mail.python.org/mailman/listinfo/python-list


f2py Error - module crashes after several iterations...

2008-10-23 Thread John [H2O]

Hello,

I have a module created from a Fortran file to read in unformatted binary
fortran output. It works fine for some datasets, but crashes with others.
The strange thing is it will loop through several files before it crashes,
then suddently giving me this output:

*** glibc detected *** python: munmap_chunk(): invalid pointer: 0xb34ac008
***
=== Backtrace: =
/lib/libc.so.6[0x7b0874]
/usr/lib/python2.5/site-packages/numpy/core/multiarray.so[0x44a24b]
/usr/lib/libpython2.5.so.1.0[0x55cf0cf]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x579)[0x5636c59]
/usr/lib/libpython2.5.so.1.0[0x55d0eb2]
/usr/lib/libpython2.5.so.1.0(PyObject_Call+0x37)[0x55b10b7]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalFrameEx+0x466f)[0x5633e7f]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x695)[0x5636d75]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCode+0x63)[0x5636fd3]
/usr/lib/libpython2.5.so.1.0[0x5652542]
/usr/lib/libpython2.5.so.1.0(PyRun_FileExFlags+0x92)[0x5652602]
/usr/lib/libpython2.5.so.1.0(PyRun_SimpleFileExFlags+0x1bc)[0x5653d8c]
/usr/lib/libpython2.5.so.1.0(PyRun_AnyFileExFlags+0x7a)[0x56544fa]
/usr/lib/libpython2.5.so.1.0(Py_Main+0xc4f)[0x565e3df]
python(main+0x32)[0x80485d2]
/lib/libc.so.6(__libc_start_main+0xe6)[0x7595d6]
python[0x8048501]
=== Memory map: 
0011-00111000 r-xp 0011 00:00 0  [vdso]
00111000-00115000 r-xp  fd:00 1835759   
/usr/lib/python2.5/lib-dynload/stropmodule.so
00115000-00117000 rw-p 4000 fd:00 1835759   
/usr/lib/python2.5/lib-dynload/stropmodule.so
00117000-0011a000 r-xp  fd:00 1835717   
/usr/lib/python2.5/lib-dynload/_localemodule.so
0011a000-0011b000 rw-p 3000 fd:00 1835717   
/usr/lib/python2.5/lib-dynload/_localemodule.so
0011b000-00121000 r-xp  fd:00 1835750   
/usr/lib/python2.5/lib-dynload/operator.so
00121000-00122000 rw-p 6000 fd:00 1835750   
/usr/lib/python2.5/lib-dynload/operator.so
00122000-00128000 r-xp  fd:00 1835727   
/usr/lib/python2.5/lib-dynload/_struct.so
00128000-00129000 rw-p 6000 fd:00 1835727   
/usr/lib/python2.5/lib-dynload/_struct.so
00129000-0012c000 r-xp  fd:00 1835762   
/usr/lib/python2.5/lib-dynload/timemodule.so

[snip ...]

Anyone have some inputs on how to determine the cause???

Thanks,
john
-- 
View this message in context: 
http://www.nabble.com/f2py-Error---module-crashes-after-several-iterations...-tp20128015p20128015.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: substitution __str__ method of an instance

2008-10-23 Thread Diez B. Roggisch
Christian Heimes wrote:

> netimen wrote:
>> How can I substitute __str__ method of an instance?
> 
> It's not possible. For performance and other reasons most __*__ methods
> are looked up on the type only.

Is that documented somewhere? I *know* it is that way, yet I'd like to have
place to read up on it (and point to when this question pops up)

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


Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Tzury Bar Yochay
> Because math.pow returns a float; 100 ** 155 won't fit in a float.

Sure that is the reason.
May I rephrase, my question:
Why not returning another type as long as we can calculate it?
After all, math module is likely to be used on large numbers as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Christian Heimes

Tzury Bar Yochay wrote:

Because math.pow returns a float; 100 ** 155 won't fit in a float.


Sure that is the reason.
May I rephrase, my question:
Why not returning another type as long as we can calculate it?
After all, math module is likely to be used on large numbers as well.


Because it's very complicated to get it right. The math module is a thin 
wrapper around the platform math library. It took Mark and me very long 
to get cmath and math right for floats (C doubles). Arbitrary precision 
and arbitrary length numbers are a different story. You have to use 3rd 
party tools for those. The standard library aims to solve common 
problems, not special problems.


Christian

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


Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread John Machin
On Oct 23, 9:24 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote:
> > Because math.pow returns a float; 100 ** 155 won't fit in a float.
>
> Sure that is the reason.
> May I rephrase, my question:
> Why not returning another type as long as we can calculate it?
> After all, math module is likely to be used on large numbers as well.

The math module is intended to replicate the functionality found in
math.h in the C Standard Library; that's it, no more, no less. There
are other libraries if you want more-than-float precision.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the time of message Received of an outlook mail in python..

2008-10-23 Thread Tzury Bar Yochay
On Oct 23, 12:04 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,,
>       How can we access the time of message received ( UTC time) of an
> outlook mail in python? As far as I know the time which it displays in
> the mail is not the exact time... this UTC time will be present in
> MIME Header of an outlook mail.
>
> Any Help is appreciated..and thanks in advance,,
> Venu.

You may google for how to utilize outlook using OLE-COM automation
When finding out how, implement it using python's com wrappers
--
http://mail.python.org/mailman/listinfo/python-list


Python Imaging Library Question

2008-10-23 Thread Marek Kralewski
Hi,

I am writing a script to convert EPS to PNG images. I need to set the
resolution (and geometry accordingly), since the rendered images are to
small. The resolution and geometry must be given as switches to the gs
command. Is there a way to overload the Ghostcript function in the
EpsImagePlugin.py file or to overload the plugin or to write a custom
plugin without interfering with the PIL?
The question hopefully seems trivial to a python programmer..

Thank you, Marek


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


Re: Python 2.6, multiprocessing module and BSD

2008-10-23 Thread MRAB
On Oct 22, 5:14 pm, Philip Semanchuk <[EMAIL PROTECTED]> wrote:
> On Oct 22, 2008, at 11:37 AM, Jesse Noller wrote:
>
> > On Wed, Oct 22, 2008 at 11:06 AM, Philip Semanchuk <[EMAIL PROTECTED]
> > > wrote:
> >>> One oversight I noticed the multiprocessing module docs is that a
> >> semaphore's acquire() method shouldn't have a timeout on OS X as
> >> sem_timedwait() isn't supported on that platform. (You note OS X's  
> >> lack of
> >> support for sem_getvalue() elsewhere.)
>
> > Please file a ticket or updatehttp://bugs.python.org/issue4012so I
> > don't loose it, my memory is increasingly lossy. Good catch.
>
> I updated issue4012.
>
> >> A question - how do you handle the difference in error messages on  
> >> various
> >> platforms? For instance, sem_trywait() raises error 35, "Resource
> >> temporarily unavailable" under OS X but error 11 under Ubuntu.  
> >> Right now I'm
> >> just passing these up to the (Python) caller as OSErrors. This  
> >> makes it
> >> really hard for the Python programmer to write cross-platform code.
>
> > If you look at the code, we're pretty much raising OSError - it's
> > possible we could enhance this in later versions, but given MP is
> > supposed to be a cross-platform as possible and protect the user from
> > the seedy underbelly of semaphores/pipes/etc - when an OSError does
> > occur, it's generally a bug in our code, not the users.
>
> Gotcha. I had a look at the code, and you're testing for errno ==  
> EAGAIN when sem_trywait() fails. This is correct for OS X and Ubuntu  
> (the platforms I mentioned above) and probably most other Unices. I  
> just don't have confidence that it will be true across all platforms,  
> esp. ones to which I don't have access like AIX and big-iron systems  
> that support POSIX. Maybe I am just taking defensive programming too  
> far.
>
>
>
> >> The only solution I can think of (which I haven't coded yet) is to  
> >> compile &
> >> run a series of small C programs during setup.py that test things  
> >> like
> >> sem_trywait() to see what errors occur, and provide those constants  
> >> to my
> >> main .c module so that it can detect those errors exactly and wrap  
> >> them into
> >> a specific, custom error for the Python caller.
>
> >> Any thoughts on this?
>
> > That's actually (while feeling hacky) a possibly sensible idea, the
> > problem is is that you'd need to maintain documentation to tell users
> > the exceptions for their platform.
>
> If I pass all errors up as OSError, yes, that will be true. But that's  
> actually the situation I was trying to avoid.
>
> By generating the error at install time, I can see exactly what  
> platform X returns in that situation (e.g. 11). Then I can create a  
> #define something like this:
> #define ERRNO_WHEN_CALLING_SEM_TRYWAIT_ON_A_LOCKED_SEMAPHORE  11
>
> My main .c module can then test for errno ==  
> ERRNO_WHEN_CALLING_SEM_TRYWAIT_ON_A_LOCKED_SEMAPHORE and wrap that in  
> a custom error, like posix_ipc.SemaphoreBusyError.
>
> Again, maybe I'm just taking defensive programming too far. I've been  
> bitten by other cross-platform inconsistencies at the C API level and  
> I'm trying to get the jump on them here.
>
Re the error codes, the OS-specific code can be mapped to an OS-
agnostic(?) code. On Windows there's a Windows-specific subclass of
OSError, WindowsError, containing the Windows error code winerror as
well as errno which is inherited from OSError.
--
http://mail.python.org/mailman/listinfo/python-list


Question about scope

2008-10-23 Thread Pat

I have a Globals class.

In it, I have a variable defined something like this:

remote_device_enabled = bool

In one module, I assign True/False to Globals.remote_device_enabled. 
Once set, this value never changes.


In another module, at the top after the imports statements, I tried this:

from Globals import *

RDE = Globals.remote_device_enabled

This way, I thought that I could just use 'if RDE:'

Within the functions, however, I get a different value.  What am I 
misunderstanding?


I tried this at the top of the module (but it didn't word):

global RDE
RDE =  Globals.remote_device_enabled

Of course, within a function, the variable using the same two lines of 
code assigns the correct value to RDE.


Thank you,

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


Re: "Find" in list of objects

2008-10-23 Thread bearophileHUGS
Andreas Müller:
> is there a construct like
> list.find (10, key='ID')

Given the current Python a syntax like this is more probable:

somelist.find(10, key=attrgetter('ID'))

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the time of message Received of an outlook mail in python..

2008-10-23 Thread [EMAIL PROTECTED]
On Oct 23, 4:01 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote:
> On Oct 23, 12:04 pm, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Hi,,
> >       How can we access the time of message received ( UTC time) of an
> > outlook mail in python? As far as I know the time which it displays in
> > the mail is not the exact time... this UTC time will be present in
> > MIME Header of an outlook mail.
>
> > Any Help is appreciated..and thanks in advance,,
> > Venu.
>
> You may google for how to utilize outlook using OLE-COM automation
> When finding out how, implement it using python's com wrappers

Thanks for your suggestion.. but I couldn't get the actual parameter
for getting the time of a mail
received... could get other features of a mail like the subject of a
mail, its content and senders n receivers address :-)

Venu.


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


Slow comparison between two lists

2008-10-23 Thread Jani Tiainen
I have rather simple 'Address' object that contains streetname,
number, my own status and x,y coordinates for it. I have two lists
both containing approximately 3 addresses.

I've defined __eq__ method in my class like this:

def __eq__(self, other):
return self.xcoord == other.xcoord and \
self.ycoord == other.ycoord and \
self.streetname == other.streetname and \
self.streetno == other.streetno

But it turns out to be very, very slow.

Then I setup two lists:

list_external = getexternal()
list_internal = getinternal()

Now I need get all all addresses from 'list_external' that are not in
'list_internal', and mark them as "new".

I did it like this:

for addr in list_external:
if addr not in list_internal:
addr.status = 1 # New address

But in my case running that loop takes about 10 minutes. What I am
doing wrong?

--

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


Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
Jani Tiainen <[EMAIL PROTECTED]> writes:

> for addr in list_external:
> if addr not in list_internal:
> addr.status = 1 # New address
>
> But in my case running that loop takes about 10 minutes. What I am
> doing wrong?

The nested loop takes time proportional to the product of the number
of elements in the loops.  To avoid it, convert the inner loop to a
set, which can be looked up in constant time:

internal = set(list_internal)
for addr in list_external:
if addr in internal:
addr.status = 1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Slow comparison between two lists

2008-10-23 Thread Peter Otten
Jani Tiainen wrote:

> I have rather simple 'Address' object that contains streetname,
> number, my own status and x,y coordinates for it. I have two lists
> both containing approximately 3 addresses.
> 
> I've defined __eq__ method in my class like this:
> 
> def __eq__(self, other):
> return self.xcoord == other.xcoord and \
> self.ycoord == other.ycoord and \
> self.streetname == other.streetname and \
> self.streetno == other.streetno
> 
> But it turns out to be very, very slow.
> 
> Then I setup two lists:
> 
> list_external = getexternal()
> list_internal = getinternal()
> 
> Now I need get all all addresses from 'list_external' that are not in
> 'list_internal', and mark them as "new".
> 
> I did it like this:
> 
> for addr in list_external:
> if addr not in list_internal:
> addr.status = 1 # New address
> 
> But in my case running that loop takes about 10 minutes. What I am
> doing wrong?

Even if list_external and list_internal contain the same items you need
about len(list_external)*(len(list_internal)/2), or 45 million comparisons.
You can bring that down to 3*some_small_factor if you make your
addresses hashable and put the internal ones into a dict or set

def __hash__(self):
   return hash((self.xcoord, self.yccord, self.streetname, self.streetno))
def __eq__(self, other):
   # as above

Then

set_internal = set(list_internal)
for addr in list_external:
if addr not in set_internal:
addr.status = 1

Note that the attributes relevant for hash and equality must not change
during this process.

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


Re: Slow comparison between two lists

2008-10-23 Thread bearophileHUGS
Hrvoje Niksic:
> internal = set(list_internal)
...

To do that the original poster may have to define a __hash__ and
__eq__ methods in his/her class.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Slow comparison between two lists

2008-10-23 Thread Stef Mientki
On Thu, Oct 23, 2008 at 2:03 PM, Jani Tiainen <[EMAIL PROTECTED]> wrote:

> I have rather simple 'Address' object that contains streetname,
> number, my own status and x,y coordinates for it. I have two lists
> both containing approximately 3 addresses.
>
> I've defined __eq__ method in my class like this:
>
>def __eq__(self, other):
>return self.xcoord == other.xcoord and \
>self.ycoord == other.ycoord and \
>self.streetname == other.streetname and \
>self.streetno == other.streetno
>
> But it turns out to be very, very slow.
>
> Then I setup two lists:
>
> list_external = getexternal()
> list_internal = getinternal()
>
> Now I need get all all addresses from 'list_external' that are not in
> 'list_internal', and mark them as "new".
>
> I did it like this:
>
> for addr in list_external:
>if addr not in list_internal:
>addr.status = 1 # New address
>
> But in my case running that loop takes about 10 minutes. What I am
> doing wrong?
>
Sorry I don't see what you're doing wrong,
except I'lde write "if not ( addr in list  internal) :"

but you might consider using dictionaries.
A couple of days ago I did some speed comparison between C and Python.
We used the lookup of a string in a hash table (= dictionary in Python),
the results were amazing:
Search string was between 50 and 100 characters.
The table / dictionary was build with 10 million strings, each also 50 ..
100 characters long.
We repeated the search 100 million times and measured the time.

Code length:
C, about 150 lines of unreadable code
Python: about 20 lines of very easy to read code lines

Development time
C : 1.5 days
Python : 20 minutes

Execution time:
C: 20 seconds
Python: 11 seconds !!

Who dares to ask Python is slow ?

cheers,
Stef






C: 20 seconds
Python



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


Re: Slow comparison between two lists

2008-10-23 Thread Bruno Desthuilliers

Jani Tiainen a écrit :

I have rather simple 'Address' object that contains streetname,
number, my own status and x,y coordinates for it. I have two lists
both containing approximately 3 addresses.

I've defined __eq__ method in my class like this:

def __eq__(self, other):
return self.xcoord == other.xcoord and \
self.ycoord == other.ycoord and \
self.streetname == other.streetname and \
self.streetno == other.streetno

But it turns out to be very, very slow.

Then I setup two lists:

list_external = getexternal()
list_internal = getinternal()

Now I need get all all addresses from 'list_external' that are not in
'list_internal', and mark them as "new".

I did it like this:

for addr in list_external:
if addr not in list_internal:
addr.status = 1 # New address

But in my case running that loop takes about 10 minutes. What I am
doing wrong?


mmm... not using sets ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question about scope

2008-10-23 Thread Lave
Newbie too. I think you shoud qualify Global with the module name.

On 10/23/08, Pat <[EMAIL PROTECTED]> wrote:
> I have a Globals class.
>
> In it, I have a variable defined something like this:
>
> remote_device_enabled = bool
>
> In one module, I assign True/False to Globals.remote_device_enabled.
> Once set, this value never changes.
>
> In another module, at the top after the imports statements, I tried this:
>
> from Globals import *
>
from  import Globals ?
> RDE = Globals.remote_device_enabled
>
Here,

RDE = .Globals.remote_device_enabled

> This way, I thought that I could just use 'if RDE:'
>
> Within the functions, however, I get a different value.  What am I
> misunderstanding?
>
> I tried this at the top of the module (but it didn't word):
>
> global RDE
> RDE =  Globals.remote_device_enabled
>
> Of course, within a function, the variable using the same two lines of
> code assigns the correct value to RDE.
>
> Thank you,
>
> Total Newbie
> --
> http://mail.python.org/mailman/listinfo/python-list
>


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


Re: f2py Error - module crashes after several iterations...

2008-10-23 Thread Robert Kern

John [H2O] wrote:

Hello,

I have a module created from a Fortran file to read in unformatted binary
fortran output. It works fine for some datasets, but crashes with others.
The strange thing is it will loop through several files before it crashes,
then suddently giving me this output:


Can you run it under gdb to get a more complete backtrace? Please join us on 
numpy-discussion.


http://www.scipy.org/Mailing_Lists

--
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


Re: substitution __str__ method of an instance

2008-10-23 Thread Bruno Desthuilliers

netimen a écrit :

I couldn't substitute __str__ method of an instance. Though I managed
to substitute ordinary method of an instance:

from types import MethodType

class Foo(object):
pass

class Printer(object):

def __call__(self, obj_self):
return 'printed'

f = Foo()

f.printer = MethodType(Printer(), f, Foo)
print f.printer()  # works fine - I get: 'printed'

print f  # get: <__main__.Foo object at 0x00D69C10>
f.__str__ = MethodType(Printer(), f, Foo)
print f  # still get: <__main__.Foo object at 0x00D69C10>. Why?
Foo.__str__ = MethodType(Printer(), None, Foo)
print f  # works fine - I get: 'printed'


How can I substitute __str__ method of an instance?


Now that others told you you couldn't do so, there's eventually a 
workaround - that is, if you have the hand on class Foo:


class Foo(object):
def __str__(self):
printer = getattr(self, 'printer', super(Foo, self).__str__)
return printer()

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


BDSM HARDCORE 1 Tb movi

2008-10-23 Thread fernandena
 http://traxanki.byethost15.com/bdsm.htm BDSM
http://traxanki.byethost15.com/hardcore.htm
HARDCORE  http://s0x0.blogspot.com  
http://groups.google.com/group/porntube-best-movies-collection
--
http://mail.python.org/mailman/listinfo/python-list


Re: Slow comparison between two lists

2008-10-23 Thread Jani Tiainen
On 23 loka, 15:24, Peter Otten <[EMAIL PROTECTED]> wrote:
> Jani Tiainen wrote:
> > I have rather simple 'Address' object that contains streetname,
> > number, my own status and x,y coordinates for it. I have two lists
> > both containing approximately 3 addresses.
>
> > I've defined __eq__ method in my class like this:
>
> >     def __eq__(self, other):
> >         return self.xcoord == other.xcoord and \
> >             self.ycoord == other.ycoord and \
> >             self.streetname == other.streetname and \
> >             self.streetno == other.streetno
>
> > But it turns out to be very, very slow.
>
> > Then I setup two lists:
>
> > list_external = getexternal()
> > list_internal = getinternal()
>
> > Now I need get all all addresses from 'list_external' that are not in
> > 'list_internal', and mark them as "new".
>
> > I did it like this:
>
> > for addr in list_external:
> >     if addr not in list_internal:
> >         addr.status = 1 # New address
>
> > But in my case running that loop takes about 10 minutes. What I am
> > doing wrong?
>
> Even if list_external and list_internal contain the same items you need
> about len(list_external)*(len(list_internal)/2), or 45 million comparisons.
> You can bring that down to 3*some_small_factor if you make your
> addresses hashable and put the internal ones into a dict or set
>
> def __hash__(self):
>    return hash((self.xcoord, self.yccord, self.streetname, self.streetno))
> def __eq__(self, other):
>    # as above
>
> Then
>
> set_internal = set(list_internal)
> for addr in list_external:
>     if addr not in set_internal:
>         addr.status = 1
>
> Note that the attributes relevant for hash and equality must not change
> during this process.

Very complete answer, thank you very much.

I tried that hash approach and sets but it seemed to get wrong results
first time and it was all due my hash method.

Now it takes like 2-3 seconds to do all that stuff and result seem to
be correct. Apparently I have lot to learn about Python... :)

--

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


Re: substitution __str__ method of an instance

2008-10-23 Thread Bruno Desthuilliers

Diez B. Roggisch a écrit :

Christian Heimes wrote:


netimen wrote:

How can I substitute __str__ method of an instance?

It's not possible. For performance and other reasons most __*__ methods
are looked up on the type only.


Is that documented somewhere? I *know* it is that way, yet I'd like to have
place to read up on it (and point to when this question pops up)


http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes

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


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gerhard Häring

Dennis Lee Bieber wrote:

On Thu, 23 Oct 2008 09:26:54 +0200, Gilles Ganault <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:



Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):


APSW is not, so far as I recall, a "DB-API 2" adapter -- it is a
touch more low-level (closer to the raw C-interface). pysqlite2 IS a
DB-API 2 adapter.

For APSW, one will need to read the specific documentation on all
the calls to determine behavior (even if the same person is now
maintaining both APSW and pysqlite2 )


Maintainership of pysqlite or APSW hasn't changed. pysqlite is still 
maintained by me and APSW still by Roger Binns.


-- Gerhard

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


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gerhard Häring

Gilles Ganault wrote:

On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina"
<[EMAIL PROTECTED]> wrote:
In case you didn't notice, B.D. already provided the answer you're after -  
reread his 3rd paragraph from the end.


Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):


The recommended way is to pass the arguments to cursor.execute, ie:


I'm getting an error when doing it this way:

===
isbn = "123"
sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'"

#Incorrect number of bindings supplied.  The current statement uses 0
and there are 1 supplied.  Current offset is 0
cursor.execute(sql, (isbn,))
===

I don't know enough about Python and this wrapper to tell why it
triggers an error.


you want:
row = cursor.fetchone()
count = row[0]
if not count:


This wrapper doesn't seem to support fetchone():

=
#AttributeError: 'apsw.Cursor' object has no attribute 'fetchone'
row = cursor.fetchone() [...]


Directly calling next() should probably do the trick with APSW. Its 
cursors support the iterator interface and iterators are implemented by 
providing __iter__() and next() methods.


-- Gerhard

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


Re: Slow comparison between two lists

2008-10-23 Thread Hrvoje Niksic
[EMAIL PROTECTED] writes:

>> internal = set(list_internal)
> ...
>
> To do that the original poster may have to define a __hash__ and
> __eq__ methods in his/her class.

You're right.  The OP states he implements __eq__, so he also needs a
matching __hash__, such as:

def __hash__(self, other):
return (hash(self.xcoord) ^ hash(self.ycoord) ^
hash(self.streetname) ^ hash(self.streetno))
--
http://mail.python.org/mailman/listinfo/python-list


Re: why does math.pow yields OverflowError (while python itself can calculate that large number)

2008-10-23 Thread Marc 'BlackJack' Rintsch
On Thu, 23 Oct 2008 02:21:36 -0700, Tzury Bar Yochay wrote:

 eval(('100*'* 155)[:-1])
> 100
> 000
> 000
> 000
> 000
> L


This can be written more straigth forward as ``100**155`` or
``pow(100, 155)``.  No need for `eval()`\ing a string.

Ciao,
Marc 'BlackJack' Rintsch

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


Re: Possible read()/readline() bug?

2008-10-23 Thread Mike Kent
To followup on this:

Terry: Yes, I did in fact miss the 'buffer' parameter to open.
Setting the buffer parameter to 0 did in fact fix the test code that I
gave above, but oddly, did not fix my actual production code; it
continues to get the data as first read, rather than what is currently
on the disk.  I'm still investigating why.

Carl: I tried the above test code, without 'buffer=0' in the open, but
with a flush added before reads in the appropriate places. The flush
made no difference; readline continued to return the old data rather
than what was actually on the disk.  So, flush isn't the answer.  I
suppose that means that, when the document states it flushes the
buffer, it's referring to the output buffer, not the input buffer.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Slow comparison between two lists

2008-10-23 Thread bearophileHUGS
Hrvoje Niksic:
> You're right.  The OP states he implements __eq__, so he also needs a
> matching __hash__, such as:
>
>     def __hash__(self, other):
>         return (hash(self.xcoord) ^ hash(self.ycoord) ^
>                 hash(self.streetname) ^ hash(self.streetno))

The hash function by Otten is better because it considers the order of
the items too (while I think the xor doesn't):

return hash((self.xcoord, self.yccord, self.streetname,
self.streetno))

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Logger / I get all messages 2 times

2008-10-23 Thread ASh
Hi,

I have this source:

import logging
import logging.config

logging.config.fileConfig("logging.properties")
log = logging.getLogger("qname")
log.debug("message")

--- OUTPUT
DEBUG logger_test:8:  message
DEBUG logger_test:8:  message

--- FILE CONFIG
[formatters]
keys: detailed

[handlers]
keys: console

[loggers]
keys: root, engine

[formatter_detailed]
format: %(levelname)s %(module)s:%(lineno)d:  %(message)s

[handler_console]
class: StreamHandler
args: []
formatter: detailed

[logger_root]
level: ERROR
handlers: console

[logger_engine]
level: DEBUG
qualname: qname
handlers: console

---

Why do I get the log 2 times?

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


Re: f2py Error - module crashes after several iterations...

2008-10-23 Thread John [H2O]

I can try, would you mind giving very brief instructions on how to 'run it
under gdb'... thanks!

I'll post results over at numpy-discussions.


Robert Kern-2 wrote:
> 
> John [H2O] wrote:
>> Hello,
>> 
>> I have a module created from a Fortran file to read in unformatted binary
>> fortran output. It works fine for some datasets, but crashes with others.
>> The strange thing is it will loop through several files before it
>> crashes,
>> then suddently giving me this output:
> 
> Can you run it under gdb to get a more complete backtrace? Please join us
> on 
> numpy-discussion.
> 
>  http://www.scipy.org/Mailing_Lists
> 
> -- 
> 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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/f2py-Error---module-crashes-after-several-iterations...-tp20128015p20131768.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Logger / I get all messages 2 times

2008-10-23 Thread Diez B. Roggisch
ASh wrote:

> Hi,
> 
> I have this source:
> 
> import logging
> import logging.config
> 
> logging.config.fileConfig("logging.properties")
> log = logging.getLogger("qname")
> log.debug("message")
> 
> --- OUTPUT
> DEBUG logger_test:8:  message
> DEBUG logger_test:8:  message
> 
> --- FILE CONFIG
> [formatters]
> keys: detailed
> 
> [handlers]
> keys: console
> 
> [loggers]
> keys: root, engine
> 
> [formatter_detailed]
> format: %(levelname)s %(module)s:%(lineno)d:  %(message)s
> 
> [handler_console]
> class: StreamHandler
> args: []
> formatter: detailed
> 
> [logger_root]
> level: ERROR
> handlers: console
> 
> [logger_engine]
> level: DEBUG
> qualname: qname
> handlers: console
> 
> ---
> 
> Why do I get the log 2 times?

Because you add the handler "console" two times, to logger_engine and
logger_root. You should only add it to root, or set propagate to false.

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


Re: Passing a memory address (pointer) to an extension?

2008-10-23 Thread Philip Semanchuk

On Oct 22, 2008, at 8:33 PM, Robert Kern wrote:



Philip Semanchuk wrote:
I'm writing a Python extension in C that wraps a function which  
takes a void * as a parameter. (The function is shmat() which  
attaches a chunk of shared memory to the process at the address  
supplied by the caller.) I would like to expose this function to  
Python, but I don't know how to define the interface.
Specifically, when calling PyArg_ParseTuple(), what letter should I  
use to represent the pointer in the format string? The best idea I  
can come up with is to use a long and then cast it to a void *, but  
assuming that a long is big enough to store a void * is a shaky  
assumption. I could use a long long (technically still risky, but  
practically probably OK) but I'm not sure how widespread long longs  
are.


I recommend not giving the user access to that argument. Just use  
NULL and let shmat() pick a starting address. I don't think it's  
really safe to let the user pick, even in C. Perhaps if you're doing  
*really* low level stuff. Of course, being that low level seems to  
be the point of posix_ipc, so maybe I should let you get on with it.


I agree. To deny users of this module access to this param of shmat()  
would be design arrogance on my part. To do so would be to claim that  
I know better than everyone who might want to use my module. Using  
values other than NULL might be unwise (the man page I'm looking at  
states that clearly) but isn't one of the core design philosophies of  
Python "we're all consenting adults"?


Anyways, the format "n" in Python >= 2.5 will correspond to a  
Py_ssize_t integer, which will always be the size of a pointer.


Thanks, I had looked at that but rejected it for two reasons. First,  
it requires Python 2.5. (But I could make that a minimum requirement  
if necessary.) Second, PEP 353 says this:


"Conceptually, Py_intptr_t and Py_ssize_t are different things:  
Py_intptr_t needs to be the same size as void*, and Py_ssize_t the  
same size as size_t. These could differ, e.g. on machines where  
pointers have segment and offset. On current flat-address space  
machines, there is no difference, so for all practical purposes,  
Py_intptr_t would have worked as well."


I guess what they're saying is that presently there's no practical  
difference between the size of a Py_intptr_t (which seems to be what I  
need) and a Py_ssize_t. I can go with that, but to me it still smacks  
of the cowboy coding I did on 16-bit platforms that assumed that longs  
and pointers were the same size and happily cast between them. It  
works *now*, but...


Thanks also to Gabriel Genellina who wrote much the same.


Thomas Heller's suggestion of using PyLong_AsVoidPtr() is perfect; I  
was not aware of that function before.



You can return the void* that you get from shmat() with a PyCPointer  
object or make a new, small type that encapsulates a pointer  
attached via shmat(). The benefit of a real type is that you can  
type-check the input to shmdt() for safety. I strongly recommend  
either of those approaches over returning an integer.


Fortunately shmdt() will be wrapped inside detach() which is a method  
object so I can use the pointer stored inside my internal C data  
structure. But you're right, I will need to expose the attached  
address to the caller as an attribute if nothing else. That's been a  
feature request for this module.


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


Re: Passing a memory address (pointer) to an extension?

2008-10-23 Thread Philip Semanchuk


On Oct 23, 2008, at 2:13 AM, Thomas Heller wrote:


Philip Semanchuk schrieb:

I'm writing a Python extension in C that wraps a function which takes
a void * as a parameter. (The function is shmat() which attaches a
chunk of shared memory to the process at the address supplied by the
caller.) I would like to expose this function to Python, but I don't
know how to define the interface.

Specifically, when calling PyArg_ParseTuple(), what letter should I
use to represent the pointer in the format string? The best idea I  
can

come up with is to use a long and then cast it to a void *, but
assuming that a long is big enough to store a void * is a shaky
assumption. I could use a long long (technically still risky, but
practically probably OK) but I'm not sure how widespread long longs  
are.


I suggest "O!" and a converter function calling PyLong_AsVoidPtr().



Thomas, this sounds perfect, thank you.


bye
Philip

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


Re: f2py Error - module crashes after several iterations...

2008-10-23 Thread Robert Kern

John [H2O] wrote:

I can try, would you mind giving very brief instructions on how to 'run it
under gdb'... thanks!


Sure. It goes something like this:

$ gdb python
GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct  2 04:07:49 UTC 2007)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared 
libraries .. done


(gdb) run my_crashing_script.py
... output from gdb
(gdb) bt
... this is the backtrace



If your program doesn't start running immediately after the run command, but 
instead tells you something like this:


  Program received signal SIGTRAP, Trace/breakpoint trap.

do this:

  (gdb) continue

It depends on your platform, and how gdb is configured whether or not you get 
this, I think. That's what I get on OS X.


--
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


Re: Function to Add List Elements?

2008-10-23 Thread Boris Borcic

Chris Rebert wrote:

On Wed, Oct 22, 2008 at 12:59 PM, Henry Chang <[EMAIL PROTECTED]> wrote:

This seems like a simple problem, but I can't find a simple solution.

Suppose I have two lists of integers.

List A = [A1, A2, A3]
List B = [B1, B2, B3]

I just simply want a new list, such as:

List C = [C1, C2, C3]

where:

C1 = A1 + B1
C2 = A2 + B2
C3 = A3 + B3

Is there a simple function to do this?


A one-liner in fact:

summed = [sum(pair) for pair in zip(listA, listB)]


or a two-liner :

from operator import add
summed = map(add,listA,listB)

or a hybrid :

summed = map(sum,zip(listA,listB))

Cheers, BB

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


Re: Possible read()/readline() bug?

2008-10-23 Thread pruebauno
On Oct 23, 9:48 am, Mike Kent <[EMAIL PROTECTED]> wrote:
> To followup on this:
>
> Terry: Yes, I did in fact miss the 'buffer' parameter to open.
> Setting the buffer parameter to 0 did in fact fix the test code that I
> gave above, but oddly, did not fix my actual production code; it
> continues to get the data as first read, rather than what is currently
> on the disk.  I'm still investigating why.
>
> Carl: I tried the above test code, without 'buffer=0' in the open, but
> with a flush added before reads in the appropriate places. The flush
> made no difference; readline continued to return the old data rather
> than what was actually on the disk.  So, flush isn't the answer.  I
> suppose that means that, when the document states it flushes the
> buffer, it's referring to the output buffer, not the input buffer.

Something odd is going on for sure. I had a couple of theories but
then I tested it on both Windows XP and AIX and could not reproduce
the problem even using the default buffer setting. As soon as I do a
seek and read it gives me the new data. I wonder if other people can
test this out on different operating systems and file systems and
detect a pattern.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library Question

2008-10-23 Thread Thomas Guettler
Marek Kralewski schrieb:
> Hi,
> 
> I am writing a script to convert EPS to PNG images. I need to set the
> resolution (and geometry accordingly), since the rendered images are to
> small. The resolution and geometry must be given as switches to the gs
> command. Is there a way to overload the Ghostcript function in the
> EpsImagePlugin.py file or to overload the plugin or to write a custom
> plugin without interfering with the PIL?
> The question hopefully seems trivial to a python programmer..

Hi,

you can call gs yourself with e.g. the module subprocess.

  Thomas



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Perl/Python regular expressions vs. Boost.regex?

2008-10-23 Thread skip
A colleague wrote a C++ library here at work which uses the Boost.regex
library.  I quickly discovered an apparent problem with how it searches.
Unlike re.match the regex_match function in that library effectively anchors
the match at both the start and the end.  Can other people confirm this?

Thx,

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


Re: f2py Error - module crashes after several iterations...

2008-10-23 Thread John [H2O]

There's a lot of greek for me here  ... should I post to numpy-discussions as
well???

The backtrace is at the bottom  Thanks!


GNU gdb Fedora (6.8-21.fc9)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
Missing separate debuginfo for /usr/local/bin/python
Try: yum --enablerepo='*-debuginfo' install
/usr/lib/debug/.build-id/0c/81115ef93a220ed16b0c9a30ded18b41a09a83.debug
(no debugging symbols found)
(gdb) run PyFlex_test.py
Starting program: /usr/local/bin/python PyFlex_test.py
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
loading modules...
[New Thread 0xb802a6c0 (LWP 12858)]
(no debugging symbols found)
(no debugging symbols found)
[snip ...]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Missing separate debuginfos, use: debuginfo-install e2fsprogs.i386
glibc.i686 keyutils.i386 krb5.i386 libselinux.i386 numpy.i386 openssl.i686
python.i386 zlib.i386
---Type  to continue, or q  to quit---
(no debugging symbols found)
[snip ...]
(no debugging symbols found)
*** glibc detected *** /usr/local/bin/python: munmap_chunk(): invalid
pointer: 0xb388d008 ***
=== Backtrace: =
/lib/libc.so.6[0x7b0874]
/usr/lib/python2.5/site-packages/numpy/core/multiarray.so[0x44a24b]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalFrameEx+0xbe7)[0x56303f7]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x695)[0x5636d75]
/usr/lib/libpython2.5.so.1.0[0x55d0eb2]
/usr/lib/libpython2.5.so.1.0(PyObject_Call+0x37)[0x55b10b7]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalFrameEx+0x466f)[0x5633e7f]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x695)[0x5636d75]
/usr/lib/libpython2.5.so.1.0(PyEval_EvalCode+0x63)[0x5636fd3]
/usr/lib/libpython2.5.so.1.0[0x5652542]
/usr/lib/libpython2.5.so.1.0(PyRun_FileExFlags+0x92)[0x5652602]
/usr/lib/libpython2.5.so.1.0(PyRun_SimpleFileExFlags+0x1bc)[0x5653d8c]
/usr/lib/libpython2.5.so.1.0(PyRun_AnyFileExFlags+0x7a)[0x56544fa]
/usr/lib/libpython2.5.so.1.0(Py_Main+0xc4f)[0x565e3df]
/usr/local/bin/python(main+0x32)[0x80485d2]
/lib/libc.so.6(__libc_start_main+0xe6)[0x7595d6]
/usr/local/bin/python[0x8048501]
=== Memory map: 
0011-00111000 r-xp 0011 00:00 0  [vdso]
00111000-00115000 r-xp  fd:00 1835759   
/usr/lib/python2.5/lib-dynload/stropmodule.so
00115000-00117000 rw-p 4000 fd:00 1835759   
/usr/lib/python2.5/lib-dynload/stropmodule.so
00117000-0011a000 r-xp  fd:00 1835717   
/usr/lib/python2.5/lib-dynload/_localemodule.so
0011a000-0011b000 rw-p 3000 fd:00 1835717   
/usr/lib/python2.5/lib-dynload/_localemodule.so
0011b000-00121000 r-xp  fd:00 1835750   
/usr/lib/python2.5/lib-dynload/operator.so
00121000-00122000 rw-p 6000 fd:00 1835750   
/usr/lib/python2.5/lib-dynload/operator.so
00122000-00128000 r-xp  fd:00 1835727   
/usr/lib/python2.5/lib-dynload/_struct.so
00128000-00129000 rw-p 6000 fd:00 1835727   
/usr/lib/python2.5/lib-dynload/_struct.so
00129000-0012c000 r-xp  fd:00 1835762   
/usr/lib/python2.5/lib-dynload/timemodule.so
0012c000-0012e000 rw-p 2000 fd:00 1835762   
/usr/lib/python2.5/lib-dynload/timemodule.so
0012e000-0013 r-xp  fd:00 1835714   
/usr/lib/python2.5/lib-dynload/_hashlib.so
0013-00131000 rw-p 2000 fd:00 1835714   
/usr/lib/python2.5/lib-dynload/_hashlib.so
00131000-00134000 r-xp  fd:00 1835747   
/usr/lib/python2.5/lib-dynload/mathmodule.so
00134000-00135000 rw-p 2000 fd:00 1835747   
/usr/lib/python2.5/lib-dynload/mathmodule.so
00135000-00139000 r-xp  fd:00 1835731   
/usr/lib/python2.5/lib-dynload/binascii.so
00139000-0013a000 rw-p 3000 fd:00 1835731   
/usr/lib/python2.5/lib-dynload/binascii.so
0013a000-0013c000 r-xp  fd:00 1835721   
/usr/lib/python2.5/lib-dynload/_randommodule.so
0013c000-0013d000 rw-p 2000 fd:00 1835721   
/usr/lib/python2.5/lib-dynload/_randommodule.so
0013d000-0013f000 r-xp  fd:00 1835741   
/usr/lib/python2.5/lib-dynload/fcntlmodule.so
0013f000-0014 rw-p 2000 fd:00 1835741   
/usr/lib/python2.5/lib-dynload/fcntlmodule.so
0014-00141000 r-xp  fd:00 1835728   
/usr/lib/python2.5/lib-dynload/_weakref.so
00141000-00142000 rw-p  fd:00 1835728   
/usr/lib/python2.5/lib-dynload/_weakref.so
00142000-0014c000 r-xp  fd:00 1835723   
/usr/lib/python2.5/lib-dynload/_socketmodule.so
0014c000-0014f000 rw-p a000 fd:00 1835723   
/usr/lib/python2.5/lib-dynload/_socketmodule.so
0014f000-00152000 r-xp  fd:

logging module

2008-10-23 Thread Werner F. Bruhin

I am starting to use the logging module.

Simple log to file and/or console work very nicely.

Even managed to get TimedRotatingFileHandler to work.

The problem I am trying to solve.

1. I would like to have a "log viewer" a wxPython based app to be able 
to look at a log generated by another script.


Did a little test for this.
- log_testing.py attached is generating the log entries
- log_viewerConsole.py is trying to attach to the same logger (would 
convert/change this to a wxPython app)


The log_viewerConsole script only sees the logs it generates.  Does this 
script have to be started by the first one to get the same logger?


Any hints on how to solve my problem would be very appreciated.

Werner


[formatters]
keys=simple
 
[handlers]
keys=consoleHandler,fileRollOver,ntEventLog
 
[loggers]
keys=root,frollover
 
[formatter_simple]
format=%(name)s:%(levelname)s %(module)s: %(lineno)d: %(asctime)s: %(message)s
 
[handler_consoleHandler]
class=StreamHandler
args=[]
formatter=simple

[handler_fileRollOver]
class=handlers.TimedRotatingFileHandler
args=['./logs/pyg_log.txt', 'M', 30, 5]
formatter=simple

[handler_ntEventLog]
class=handlers.SysLogHandler
args=[("localhost",handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_USER]
formatter=simple

[logger_root]
level=DEBUG
handlers=ntEventLog

[logger_frollover]
level=DEBUG
handlers=fileRollOver
qualname=loggerFRO

import logging, logging.config, logging.handlers

import time
# setup logging
logging.config.fileConfig('pyg_log.cfg')

# create logger
logger = logging.getLogger("loggerFRO")

while 1:
#"application" code
logger.debug("debug message")
logger.info("info message")
logger.warn("warn message")
logger.error("error message")
logger.critical("critical message")

try:
x = 1 / 0
except:
logger.exception('exception')

logger.info("sleeping")
time.sleep(5)
logger.info("done sleeping")import logging, logging.config
import time

logging.config.fileConfig('pyg_log.cfg')

# create logger
logger = logging.getLogger("loggerFRO")

# handler
streamHandler = logging.StreamHandler()

# formater
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
streamHandler.setFormatter(formatter)

logger.addHandler(streamHandler)

logger.info('just a test message')

while 1:
time.sleep(1)
logger.info('slept 1')
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible read()/readline() bug?

2008-10-23 Thread M.-A. Lemburg
On 2008-10-22 23:00, kdwyer wrote:
> On 22 Oct, 19:54, Mike Kent <[EMAIL PROTECTED]> wrote:
>> Before I file a bug report against Python 2.5.2, I want to run this by
>> the newsgroup to make sure I'm not being stupid.
>>
>> I have a text file of fixed-length records I want to read in random
>> order.  That file is being changed in real-time by another process,
>> and my process want to see the changes to the file.  What I'm seeing
>> is that, once I've opened the file and read a record, all subsequent
>> seeks to and reads of that same record will return the same data as
>> the first read of the record, so long as I don't close and reopen the
>> file.  This indicates some sort of buffering and caching is going on.

The C lib uses a buffer for reading files and you are seeing the
affects of this.

Try using f = open('foo.txt', 'r', 0)

http://www.python.org/doc/2.5.2/lib/built-in-funcs.html#l2h-54

>> Consider the following:
>>
>> $ echo "hi" >foo.txt  # Create my test file
>> $ python2.5  # Run Python
>> Python 2.5.2 (r252:60911, Sep 22 2008, 16:13:07)
>> [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>
> f = open('foo.txt')  # Open my test file
> f.seek(0)# Seek to the beginning of the file
> f.readline() # Read the line, I get the data I expected
>> 'hi\n'
> # At this point, in another shell I execute 'echo "bye" >foo.txt'.  
> 'foo.txt' now has been changed
> # on the disk, and now contains 'bye\n'.
> f.seek(0)# Seek to the beginning of the still-open file
> f.readline() # Read the line, I don't get 'bye\n', I get the 
> original data, which is no longer there.
>> 'hi\n'
> f.close() # Now I close the file...
> f = open('foo.txt') # ... and reopen it
> f.seek(0)   # Seek to the beginning of the file
> f.readline()# Read the line, I get the expected 'bye\n'
>> 'bye\n'
>>
>> It seems pretty clear to me that this is wrong.  If there is any
>> caching going on, it should clearly be discarded if I do a seek.  Note
>> that it's not just readline() that's returning me the wrong, cached
>> data, as I've also tried this with read(), and I get the same
>> results.  It's not acceptable that I have to close and reopen the file
>> before every read when I'm doing random record access.
>>
>> So, is this a bug, or am I being stupid?
> 
> Hello Mike,
> 
> I'm guessing that this is not a bug.  I'm no expert, but I'd guess
> that the open(file, mode) function simply loads the file into memory,
> and that further operations (such as seek or read) are performed on
> the in-memory data rather than the data on disk.  Thus changes to the
> file are only observed after a fresh open operation.
> 
> This behaviour is probably enforced by the C library on the machine
> that you are using.  If you want to be able to pick up data changes
> like this then you're better off using a database package that has
> support for concurrent access, locking and transactions.
> 
> Cheers,
> 
> Kev
> --
> http://mail.python.org/mailman/listinfo/python-list

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 23 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread M.-A. Lemburg
On 2008-10-23 09:26, Gilles Ganault wrote:
> On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina"
> <[EMAIL PROTECTED]> wrote:
>> In case you didn't notice, B.D. already provided the answer you're after -  
>> reread his 3rd paragraph from the end.
> 
> Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):

APSW doesn't implement the DB-API and as a result, you'll run
into all sorts of problem when trying to use DB-API examples
with it.

I'd suggest that you try pysqlite instead which does implement
the DB-API and also works around a couple of gotchas you find
with SQLite when using APSW that have to do with the way SQLite
manages transactions.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 23 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN]pygccxml - 1.0

2008-10-23 Thread M.-A. Lemburg
On 2008-10-23 09:20, Matthieu Brucher wrote:
> Hi,
> 
> I'm trying to use your package, but the gccxml installer is not
> available from your website anymore. Is it possible for you to upload
> it again ?

Works for me:

https://sourceforge.net/project/showfiles.php?group_id=118209&package_id=146545&release_id=634581

> Thanks,
> 
> Matthieu
> 
> 2008/10/20 Roman Yakovenko <[EMAIL PROTECTED]>:
>> Hello!
>>
>> I'm pleased to announce the 1.0 release of pygccxml.
>>
>> What is pygccxml?
>> ===
>>
>> "...The purpose of the GCC-XML extension is to generate an XML description 
>> of a
>> C++ program from GCC's internal representation. "
>>
>> -- Introduction to GCC-XML
>>
>> The purpose of pygccxml is to read a generated file and provide a simple
>> framework to navigate C++ declarations, using Python classes.
>>
>> Where is pygccxml?
>> 
>>
>> Site: http://language-binding.net/pygccxml/pygccxml.html
>>
>> Download: http://language-binding.net/pygccxml/download.html
>>
>> What's new?
>> ===
>>
>> Features
>> -
>>
>> * Support for ellipsis was added.
>>
>> * New experimental back-end, based on ``.pdb`` (progam database file),
>> was added.
>>
>> * New high-level API wrapper for ``.bsc`` (browse source code file) was 
>> added.
>>
>>
>> Bug fixes
>> -
>>
>> * Search algorithm, for template instantiated classes, was improved.
>>
>>
>> For a more complete list, please see the news:
>> http://language-binding.net/pygccxml/history/history.html
>>
>>
>> --
>> Roman Yakovenko
>> C++ Python language binding
>> http://www.language-binding.net/
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> 
> 
> 

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 23 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: f2py Error - module crashes after several iterations...

2008-10-23 Thread Robert Kern

John [H2O] wrote:

There's a lot of greek for me here  ... should I post to numpy-discussions as
well???


Yes, please.

--
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


python extensions: including project local headers

2008-10-23 Thread J Kenneth King

Hey everyone,

I'm working on a python extension wrapper around Rob Hess'
implementation of a SIFT feature detector. I'm working on a
computer-vision based project that requires interfacing with Python at
the higher layers, so I figured the best way to handle this would be in
C (since my initial implementation in python was ungodly and slow). 

I can get distutils to compile the extension and install it in the
python path, but when I go to import it I get the wonderful exception:

ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
symbol: _sift_features

Of course, _sift_features is a function defined in his header that I'm
#including in my extension.

His sources are sitting in my project root under sift/ while my source
is under src/ -- My setup.py is as follows:

[code]

from distutils.core import setup, Extension

pysift = Extension('pysift',
   include_dirs = ['sift/include'],
   sources = ['src/pysift.c'],
   extra_link_args = ['-lm', '-lcv', '-lcxcore',
  '-lhighgui', '-lcvaux'])

setup(name = 'pysift',
  version = '0.0',
  description = 'A SIFT feature detection package',
  author = 'James Kenneth King',
  author_email = "[EMAIL PROTECTED]",
  url = "http://agentultra.com/";,
  long_description = """
  A python extension package for detecting SIFT
  features using Rob Hess' C implementation.

  http://web.engr.oregonstate.edu/~hess/

  Original SIFT feature descriptors by David Lowe
  and patented by the University of British Columbia.
  """,
  ext_modules = [pysift])

[/code]

And the include to Rob's header file is on the second line of pysift.c:

#include "sift.h"

The weird thing (to me in my somewhat hackish knowledge of C) is that I
can use all the #defines from sift.h with no complaints from the
preprocessor (in fact, there are no complaints at all from the compiler
when compiling the extension module).

Once I get this bugger working, I'll be setting up a project page to
share sources and will also be releasing extension wrappers to the
OpenCV libraries.

I've never released any code before so any help getting this right and
proper for the community would be greatly appreciated.

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


Re: python extensions: including project local headers

2008-10-23 Thread Philip Semanchuk


On Oct 23, 2008, at 11:36 AM, J Kenneth King wrote:



Hey everyone,

I'm working on a python extension wrapper around Rob Hess'
implementation of a SIFT feature detector. I'm working on a
computer-vision based project that requires interfacing with Python at
the higher layers, so I figured the best way to handle this would be  
in

C (since my initial implementation in python was ungodly and slow).

I can get distutils to compile the extension and install it in the
python path, but when I go to import it I get the wonderful exception:

ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
symbol: _sift_features



Kenneth,
You're close but not interpreting the error quite correctly. This  
isn't an error from the compiler or preprocessor, it's a library  
error. Assuming this is dynamically linked, your OS is reporting that,  
at runtime, it can't find the library that contains _sift_features.  
Make sure that it's somewhere where your OS can find it.


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


OS 10.5 build 64 bits

2008-10-23 Thread Robin Becker
I'm trying to build Python from the unix sources on an OS 10.5 machine. This is 
because we're getting strange faults  when using the built in python 2.5 
together with some precompiled versions of MySQLdb PIL etc etc.


The build works if I use python2.6 and with one minor fix I can get all the 
extensions built and apparently working. However, there are some minor problems 
with deprecated code inside the version of django we're using.


I then tried to build against Python2.5. All the extensions build cleanly except 
for MySQLdb. I'm now getting




In file included from /Users/rptlab/PYTHON/include/python2.5/Python.h:57,
 from pymemcompat.h:10,
 from _mysql.c:29:
/Users/rptlab/PYTHON/include/python2.5/pyport.h:761:2: error: #error "LONG_BIT 
definition appears wrong for platform (bad gcc/glibc config?)."


and related


In file included from _mysql.c:35:
/usr/local/mysql/include/mysql/my_config.h:1095:1: warning: "SIZEOF_LONG" 
redefined
In file included from /Users/rptlab/PYTHON/include/python2.5/Python.h:8,
 from pymemcompat.h:10,
 from _mysql.c:29:
/Users/rptlab/PYTHON/include/python2.5/pyconfig.h:814:1: warning: this is the 
location of the previous definition


I assume that's because MySQLdb wants to get settings from the mysql_config file 
and the database is compiled in 64 bit mode whilst by default python seems to be 
building 32 bit.


Is there some magic I can try to make the OS 10.5 build as 64 bits? I don't see 
any options to do that in the configure script.


Also is it reasonable to expect MySQLdb to operate in both camps ie 32 bit on 
the python side and 64 bit on the mysql side. We didn't see any obvious errors 
with the 2.6 build, but our testing was not extensive.

--
Robin Becker

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


Re: python extensions: including project local headers

2008-10-23 Thread Robert Kern

Philip Semanchuk wrote:


On Oct 23, 2008, at 11:36 AM, J Kenneth King wrote:



Hey everyone,

I'm working on a python extension wrapper around Rob Hess'
implementation of a SIFT feature detector. I'm working on a
computer-vision based project that requires interfacing with Python at
the higher layers, so I figured the best way to handle this would be in
C (since my initial implementation in python was ungodly and slow).

I can get distutils to compile the extension and install it in the
python path, but when I go to import it I get the wonderful exception:

ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
symbol: _sift_features



Kenneth,
You're close but not interpreting the error quite correctly. This isn't 
an error from the compiler or preprocessor, it's a library error. 
Assuming this is dynamically linked, your OS is reporting that, at 
runtime, it can't find the library that contains _sift_features. Make 
sure that it's somewhere where your OS can find it.


It looks like the library implementing it was not linked into the extension. 
sift_features() is not part of OpenCV.


James, are you including the source of Rob Hess's implementation with your 
extension, or are you trying to link against an already installed version of the 
library? If the former, you need to add the C sources to the pysift Extension(). 
If the latter, you need to add the name of the library to the list of libraries.


Also, you don't want to pass the list of libraries with extra_link_args. 
Instead, use libraries=.


pysift = Extension('pysift',
   include_dirs = ['sift/include'],
   sources = ['src/pysift.c'],
   libraries = ['feat', 'cv', 'cxcore', 'highgui',
'cvaux', 'm'])

--
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


Do a Gnuplot of a file in python

2008-10-23 Thread Santix

I am doing a python program that save the data in a text file in columns and
I want to do a gnuplot to plot the results.
But I want the program in python to show the result with gnuplot.
I have tried this:

g.load(power.p)

but it gives me this error:

Traceback (most recent call last):
  File "./spectrum_output.py", line 310, in 
main_loop(tb)
  File "./spectrum_output.py", line 289, in main_loop
g.load(power.p)
AttributeError: 'file' object has no attribute 'p'

On power.p I have this:

set autoscale
unset logscale
unset label
set xtic auto
set ytic auto
set title "Spectrum Analyzer"
set xlabel "Frecuency"
set ylabel "Power (dB)"
plot "power.dat" using 1:2 title 'm.data[0]' with linespoints

And in power.dat:
223150.018.2582263947
223450.017.0396003723
...  ...
with more data

It goes ok when I load it in gnuplot, but not when I execute the python
program in the Terminal.

Thanks in advance!

Regards,

Santiago Ortega. 
-- 
View this message in context: 
http://www.nabble.com/Do-a-Gnuplot-of-a-file-in-python-tp20134007p20134007.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: crossplatform standalone python apps

2008-10-23 Thread Martin v. Löwis
> yes, I know that :-), I ment everything that can be, my problem is more
> with PYTHONPATH and stuff like that.

Then I don't understand what you meant. What is it (specifically!) that
you do, what happens, what do you want to happen instead?

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


Re: python extensions: including project local headers

2008-10-23 Thread J Kenneth King
Robert Kern <[EMAIL PROTECTED]> writes:

> Philip Semanchuk wrote:
>>
>> On Oct 23, 2008, at 11:36 AM, J Kenneth King wrote:
>>
>>>
>>> Hey everyone,
>>>
>>> I'm working on a python extension wrapper around Rob Hess'
>>> implementation of a SIFT feature detector. I'm working on a
>>> computer-vision based project that requires interfacing with Python at
>>> the higher layers, so I figured the best way to handle this would be in
>>> C (since my initial implementation in python was ungodly and slow).
>>>
>>> I can get distutils to compile the extension and install it in the
>>> python path, but when I go to import it I get the wonderful exception:
>>>
>>> ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
>>> symbol: _sift_features
>>
>>
>> Kenneth,
>> You're close but not interpreting the error quite correctly. This
>> isn't an error from the compiler or preprocessor, it's a library
>> error. Assuming this is dynamically linked, your OS is reporting
>> that, at runtime, it can't find the library that contains
>> _sift_features. Make sure that it's somewhere where your OS can find
>> it.
>
> It looks like the library implementing it was not linked into the
> extension. sift_features() is not part of OpenCV.
>
> James, are you including the source of Rob Hess's implementation with
> your extension, or are you trying to link against an already installed
> version of the library? If the former, you need to add the C sources
> to the pysift Extension(). If the latter, you need to add the name of
> the library to the list of libraries.

I'm including Rob Hess' sources with the extension.

Would that mean I should add library_dirs to Extension() to point to the
sources in the project's path?

> Also, you don't want to pass the list of libraries with
> extra_link_args. Instead, use libraries=.
>
> pysift = Extension('pysift',
>include_dirs = ['sift/include'],
>sources = ['src/pysift.c'],
>libraries = ['feat', 'cv', 'cxcore', 'highgui',
> 'cvaux', 'm'])

Thanks for taking a moment to help me out. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: OS 10.5 build 64 bits

2008-10-23 Thread M.-A. Lemburg
Hi Robin,

On 2008-10-23 17:55, Robin Becker wrote:
> I'm trying to build Python from the unix sources on an OS 10.5 machine.
> This is because we're getting strange faults  when using the built in
> python 2.5 together with some precompiled versions of MySQLdb PIL etc etc.
> 
> The build works if I use python2.6 and with one minor fix I can get all
> the extensions built and apparently working. However, there are some
> minor problems with deprecated code inside the version of django we're
> using.
> 
> I then tried to build against Python2.5. All the extensions build
> cleanly except for MySQLdb. I'm now getting
> 
> 
>> In file included from /Users/rptlab/PYTHON/include/python2.5/Python.h:57,
>>  from pymemcompat.h:10,
>>  from _mysql.c:29:
>> /Users/rptlab/PYTHON/include/python2.5/pyport.h:761:2: error: #error
>> "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
> 
> and related
> 
>> In file included from _mysql.c:35:
>> /usr/local/mysql/include/mysql/my_config.h:1095:1: warning:
>> "SIZEOF_LONG" redefined
>> In file included from /Users/rptlab/PYTHON/include/python2.5/Python.h:8,
>>  from pymemcompat.h:10,
>>  from _mysql.c:29:
>> /Users/rptlab/PYTHON/include/python2.5/pyconfig.h:814:1: warning: this
>> is the location of the previous definition

That looks like a classical name clash between C header files.
It also suggests that you have 64-bit client libs of MySQL
installed.

> I assume that's because MySQLdb wants to get settings from the
> mysql_config file and the database is compiled in 64 bit mode whilst by
> default python seems to be building 32 bit.

As long as the MySQL client lib is built as 32-bit lib, you shouldn't
have a problem.

> Is there some magic I can try to make the OS 10.5 build as 64 bits? I
> don't see any options to do that in the configure script.

The config options --with-universal-archs is used for this. In theory
you could build a 4-way binary for Intel,PPC/32-bit,64-bit.
Default is 32-bit only.

> Also is it reasonable to expect MySQLdb to operate in both camps ie 32
> bit on the python side and 64 bit on the mysql side. We didn't see any
> obvious errors with the 2.6 build, but our testing was not extensive.

As long as the MySQL wire protocol doesn't get in the way, this
should be possible - again, provided you compile the MySQL client
libs as 32-bit.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 23 2008)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to do_size_allocate properly in a gtk.Viewport subclass

2008-10-23 Thread Joel Hedlund

Joel Hedlund wrote:
And another relevant question: am I overcomplicating this? 


Yes. :-)

The proper way of doing this is to pack the widget in a container, and 
then add the container (with viewport) to a scrolledwindow.


For example, for a centered widget choose a 1x1 gtk.Table and attach the 
widget using xoptions = yoptions = gtk.EXPAND (and not gtk.FILL). For a 
widget glued to the upper left corner choose a gtk.Alignment().


Thanks John Finlay at [EMAIL PROTECTED]

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


Re: Question about scope

2008-10-23 Thread Bruno Desthuilliers

Pat a écrit :

I have a Globals class.


Not sure it's such a great idea, but anyway... What's the use case for 
this class ? There are perhaps better (or at least more idiomatic) 
solutions...



In it, I have a variable defined something like this:

remote_device_enabled = bool


Could you show actual code ? It would really help. But it seems your 
'Globals' class is mostly 1/ a singleton and 2/ used for application 
wide settings. Is that right ?


In one module, I assign True/False to Globals.remote_device_enabled. 


Directly to the class ?

Please, once again, provide real code. Well... not necessarily your 
whole code, but at least minimal working code that reproduces the problem.



Once set, this value never changes.

In another module, at the top after the imports statements, I tried this:

from Globals import *



The convention is to use lower case names for modules (and MixedCase 
names for classes). This avoids confusion between synonym classes and 
modules...




RDE = Globals.remote_device_enabled

This way, I thought that I could just use 'if RDE:'

Within the functions, however, I get a different value.  What am I 
misunderstanding?


Not enough informations, and my crystal ball is out for repair. Sorry. 
Perhaps some actual code may help ?-)



I tried this at the top of the module (but it didn't word):

global RDE


Outside a function body, the 'global' statement is a no-op. In Python, 
'global' really means 'module-level', so anything defined at the module 
level is already as global as it can be.



RDE =  Globals.remote_device_enabled

Of course, within a function, the variable using the same two lines of 
code assigns the correct value to RDE.


Sorry Pat, but there's just not enough context for us to guess what's 
wrong. It's easy enough to get it wrong with real code, so trying to 
guess is just a waste of time.

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


Re: Perl/Python regular expressions vs. Boost.regex?

2008-10-23 Thread tomohiro kusumi
I was confused when I first used Boost regualr expressions,
but I got used to it now. Aside from it, I think Boost regular expression
makes you write too much code just to do a simple pattern matching.

Tomohiro Kusumi

2008/10/23 <[EMAIL PROTECTED]>

> A colleague wrote a C++ library here at work which uses the Boost.regex
> library.  I quickly discovered an apparent problem with how it searches.
> Unlike re.match the regex_match function in that library effectively
> anchors
> the match at both the start and the end.  Can other people confirm this?
>
> Thx,
>
> Skip Montanaro
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: re.search over a list

2008-10-23 Thread Bruno Desthuilliers

Steve Holden a écrit :

Pat wrote:

Bruno Desthuilliers wrote:

(snip)

words = ['foo', 'bar', 'somestring', 'baaz']
re.search(r"^somestring$", "\n".join(words), re.MULTILINE)

(snip)



I suspect that

any(re.match(pat, word) for word in words)

might be a more efficient way to do this.


Indeed. I'm not yet used to have all and any builtins, thanks for the 
reminder.

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


Re: python extensions: including project local headers

2008-10-23 Thread Robert Kern

J Kenneth King wrote:

Robert Kern <[EMAIL PROTECTED]> writes:


Philip Semanchuk wrote:

On Oct 23, 2008, at 11:36 AM, J Kenneth King wrote:


Hey everyone,

I'm working on a python extension wrapper around Rob Hess'
implementation of a SIFT feature detector. I'm working on a
computer-vision based project that requires interfacing with Python at
the higher layers, so I figured the best way to handle this would be in
C (since my initial implementation in python was ungodly and slow).

I can get distutils to compile the extension and install it in the
python path, but when I go to import it I get the wonderful exception:

ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
symbol: _sift_features


Kenneth,
You're close but not interpreting the error quite correctly. This
isn't an error from the compiler or preprocessor, it's a library
error. Assuming this is dynamically linked, your OS is reporting
that, at runtime, it can't find the library that contains
_sift_features. Make sure that it's somewhere where your OS can find
it.

It looks like the library implementing it was not linked into the
extension. sift_features() is not part of OpenCV.

James, are you including the source of Rob Hess's implementation with
your extension, or are you trying to link against an already installed
version of the library? If the former, you need to add the C sources
to the pysift Extension(). If the latter, you need to add the name of
the library to the list of libraries.


I'm including Rob Hess' sources with the extension.

Would that mean I should add library_dirs to Extension() to point to the
sources in the project's path?


No, you would add the source file names to the sources= list.

--
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


Re: logging module

2008-10-23 Thread Matimus
On Oct 23, 7:58 am, "Werner F. Bruhin" <[EMAIL PROTECTED]> wrote:
> I am starting to use the logging module.
>
> Simple log to file and/or console work very nicely.
>
> Even managed to get TimedRotatingFileHandler to work.
>
> The problem I am trying to solve.
>
> 1. I would like to have a "log viewer" a wxPython based app to be able
> to look at a log generated by another script.

Running in a separate process? That isn't possible. Okay, well, it
isn't possible without doing a fair amount of work on your own. You
would probably need to create a handler that writes everything to a
pipe or a socket, and then have your second application read from the
pipe/socket and display it. I don't think that feature exists right
now though.

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


Python26 compilation problem

2008-10-23 Thread Mathew

I am getting
Modules/config.c:39: error: expected declaration specifiers or '...' 
before numeric constant


because of
extern void initsocket(2)(void);

in config.c

What is this? How do I fix it?


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


Re: [ANN]pygccxml - 1.0

2008-10-23 Thread Matthieu Brucher
2008/10/23 M.-A. Lemburg <[EMAIL PROTECTED]>:
> On 2008-10-23 09:20, Matthieu Brucher wrote:
>> Hi,
>>
>> I'm trying to use your package, but the gccxml installer is not
>> available from your website anymore. Is it possible for you to upload
>> it again ?
>
> Works for me:
>
> https://sourceforge.net/project/showfiles.php?group_id=118209&package_id=146545&release_id=634581

Still does not ;) Only the pygccxml zip is available.

Matthieu
-- 
Information System Engineer, Ph.D.
Website: http://matthieu-brucher.developpez.com/
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn: http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list


[email protected]

2008-10-23 Thread www.maidi2008.com
Reply to: [EMAIL PROTECTED]
MSN:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


www.maidi2008.com supply good business partner

2008-10-23 Thread www.maidi2008.com
Reply to: [EMAIL PROTECTED]
MSN:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


sneaker wholesale from China www.maidi2008.com

2008-10-23 Thread www.maidi2008.com
Reply to: [EMAIL PROTECTED]
MSN:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


shinning sports shoes suitable clothes accessories www.maidi2008.com

2008-10-23 Thread www.maidi2008.com
Reply to: [EMAIL PROTECTED]
MSN:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


sneaker's house www.maidi2008.com

2008-10-23 Thread www.maidi2008.com
Reply to: [EMAIL PROTECTED]
MSN:[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


ANN: gui_support, a convenience library for wxPython

2008-10-23 Thread Stef Mientki

hello,

gui_support is library for easy creation of GUI designs in wxPython.
Although it's quit stable, it's part of a larger project and therefor 
has a lot of dependencies, but these can easily be removed.


Warning:
Although this library might be very attractive to newbies,
the use of this library will prevent you from learning some of the 
basics of GUI,

specially of containers / sizers in wxPython.

Brief documentation can be found here
http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_gui_support.html
( as this website will soon be moved,
this docpage can always be found through the redirector
http://pic.flappie.nl
look under paragraph PyLab_Works | GUI_support )

Download:
http://pylab-works.googlecode.com/files/Data_Python_Test.zip

cheers,
Stef

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


Re: Possible read()/readline() bug?

2008-10-23 Thread Joshua Kugler
Mike Kent wrote:

> To followup on this:
> 
> Terry: Yes, I did in fact miss the 'buffer' parameter to open.
> Setting the buffer parameter to 0 did in fact fix the test code that I
> gave above, but oddly, did not fix my actual production code; it
> continues to get the data as first read, rather than what is currently
> on the disk.  I'm still investigating why.

What OS is your test code one? What OS is your production code on?  As
mentioned read{line} will mirror the OS's underlying stdio.

j

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


  1   2   >