Re: open a file in python

2009-07-29 Thread jayshree
On Jul 27, 2:55 pm, "Diez B. Roggisch"  wrote:
> jayshree wrote:
> > On Jul 27, 1:09 pm, Kushal Kumaran 
> > wrote:
> >> On Mon, Jul 27, 2009 at 12:58 PM, jayshree
> >> wrote:
> >> > pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
>
> >> > Please tell me how to open a file placed in any directory or in same
> >> > directory.
>
> >> > After opening this file i want to use the contain (public key ) for
> >> > encryption
>
> >> Does the code you've put into your message not read that file?  If you
> >> get an exception, copy-paste in the traceback message you get into
> >> your mail.
>
> >> --
> >> kushal
>
> >     try:
> >         pk = open('/home/jayshree/my_key.public.pem' , 'rb').read()
> >     except IOError:
> >         print "Error: can\'t find file or read data"
> >     else:
> >         print "reading from file successfully"
>
> >>Still no error it gives .what to do?
>
> Erm - so it doesn't give an error - which means you have successfully opened
> a file, and read it's contents.
>
> So what exactly is your problem?
>
> Diez- Hide quoted text -
>
> - Show quoted text -

> The Exact Problem is how to use the key containing by .pem file for 
> 'encryption' .
>can i print the contents of the .pem file

see http://stackoverflow.com/questions/1176864/problem-with-the-pem-file
-- 
http://mail.python.org/mailman/listinfo/python-list


[no subject]

2009-07-29 Thread hch
Hi, everyone

Is there a python script can get a list of how much stack space each
function in your program uses? ( the program is compiled by gcc)

Any advice will be appreciate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Deprecated sets module" with Python 2.6

2009-07-29 Thread Virgil Stokes

Diez B. Roggisch wrote:

Virgil Stokes schrieb:
I would appreciate help on correcting a problem when trying to create 
an *.exe file using py2exe via GUI2exe with Python 2.6.2.


When using GUI2exe to create an *.exe I always get the following 
warning during the compile process:


C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
DeprecationWarning: the sets module is deprecated
import sets

and this results in the creation of an *.exe file that can not be 
executed.


On the other hand, if I use the same procedure (on the same Python 
code) with

Python 2.5, there are no warnings and the *.exe works fine.

The procedure used is that given in the example "Less simpler one" at

 http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin

Any suggestions, help, ... would be greatly appreciated.


If you don't need your app running on python2.3 and earlier, just 
remove the sets-module and replace it with the builtin "set".
Of course Diez, this is a good suggestion. However, in this case the 
Python code that I am trying to convert into an *.exe file does not 
refer to sets directly; i.e, the use of this module is buried within a 
package that is imported (wxPython) which is not under my control.


--V


Diez



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


about analyze object's stack usage

2009-07-29 Thread hch
Hi, everyone

Is there a python script can get a list of how much stack space each
function in your program uses? ( the program is compiled by gcc)

Any advice will be appreciate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Deprecated sets module" with Python 2.6

2009-07-29 Thread Virgil Stokes

Virgil Stokes wrote:

Diez B. Roggisch wrote:

Virgil Stokes schrieb:
I would appreciate help on correcting a problem when trying to 
create an *.exe file using py2exe via GUI2exe with Python 2.6.2.


When using GUI2exe to create an *.exe I always get the following 
warning during the compile process:


C:\Python26\lib\site-packages\py2exe\build_exe.py:16:
DeprecationWarning: the sets module is deprecated
import sets

and this results in the creation of an *.exe file that can not be 
executed.


On the other hand, if I use the same procedure (on the same Python 
code) with

Python 2.5, there are no warnings and the *.exe works fine.

The procedure used is that given in the example "Less simpler one" at

 http://code.google.com/p/gui2exe/wiki/GUI2ExeExamplesin

Any suggestions, help, ... would be greatly appreciated.


If you don't need your app running on python2.3 and earlier, just 
remove the sets-module and replace it with the builtin "set".
Of course Diez, this is a good suggestion. However, in this case the 
Python code that I am trying to convert into an *.exe file does not 
refer to sets directly; i.e, the use of this module is buried within a 
package that is imported (wxPython) which is not under my control.


--V


Diez




Whoops, the reference to the module sets is in py2exe not wxPython.

--V

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


Re: If Scheme is so good why MIT drops it?

2009-07-29 Thread Hendrik van Rooyen
On Tuesday 28 July 2009 17:11:02 MRAB wrote:

> If you were a "COBOL" programmer, would you want to shout about it? :-)

Hey don't knock it! - at the time, it was either COBOL or FORTRAN
or some assembler or coding in hex or octal.

And if code is data, where is Pythons ALTER statement?

*Ducks*

:-)Hendrik




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


Re: python 3 and stringio.seek

2009-07-29 Thread Miles Kaufmann


On Jul 28, 2009, at 6:30 AM, Michele Petrazzo wrote:


Hi list,
I'm trying to port a my library to python 3, but I have a problem  
with a

the stringio.seek:
the method not accept anymore a value like pos=-6 mode=1, but the  
"old"

(2.X) version yes...

The error:
 File "/home/devel/Py3/lib/python3.0/io.py", line 2031, in seek
   return self._seek(pos, whence)
IOError: Can't do nonzero cur-relative seeks


How solve this?


In Python 2, StringIO is a stream of bytes (non-Unicode characters).   
In Python 3, StringIO is a stream of text (Unicode characters).  In  
the early development of Python 3 (and 3.1's _pyio), it was  
implemented as a TextIOWrapper over a BytesIO buffer.  TextIOWrapper  
does not support relative seeks because it is difficult to map the  
concept of a "current position" between bytes and the text that it  
encodes, especially with variable-width encodings and other  
considerations.  Furthermore, the value returned from  
TextIOWrapper.tell isn't just a file position but a "cookie" that  
contains other data necessary to restore the decoding mechanism to the  
same state.  However, for the default encoding (utf-8), the current  
position is equivalent to that of the underlying bytes buffer.


In Python 3, StringIO is implemented using an internal buffer of  
Unicode characters.  There is no technical reason why it can't support  
relative seeks; I assume it does not for compatibility with the  
original Python TextIOWrapper implementation (which is present in  
3.1's _pyio, but not in 3.0).


Note that because of the different implementations, StringIO.tell()  
(and seek) behaves differently for the C and Python implementations:


$ python3.1
>>> import io, _pyio
>>> s = io.StringIO('\u263A'); s.read(1), s.tell()
('☺', 1)
>>> s = _pyio.StringIO('\u263A'); s.read(1), s.tell()
('☺', 3)

The end result seems to be that, for text streams (including  
StreamIO), you *should* treat the value returned by tell() as an  
opaque magic cookie, and *only* pass values to seek() that you have  
obtained from a previous tell() call.  However, in practice, it  
appears that you *may* seek StringIO objects relatively by characters  
using s.seek(s.tell() + n), so long as you do not use the  
_pyio.StringIO implementation.


If what you actually want is a stream of bytes, use BytesIO, which may  
be seeked (sought?) however you please.


I'm basing this all on my reading of the Python source (and svn  
history), since it doesn't seem to be documented, so take it with a  
grain of salt.


-Miles

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


fast video encoding

2009-07-29 Thread gregorth
Hi all,

for a scientific application I need to save a video stream to disc for
further post processing. My cam can deliver 8bit grayscale images with
resolution 640x480 with a framerate up to 100Hz, this is a data rate
of 30MB/s. Writing the data uncompressed to disc hits the data
transfer limits of my current system and creates huge files. Therefore
I would like to use video compression, preferably fast and high
quality to lossless encoding. Final file size is not that important.
Because of the hardware I am bound to WinXP.

I already tried pymedia for encoding to mpeg2, however I only managed
to get a framerate of about 30-40fps (on a 1.8GHz dual core). There is
still room for improvements in my code, but before trying hard I want
to ask for advices or other possibilities. I also found gstreamer with
pygst python bindings, which seems to be more modern (and performant?)
package than pymedia. I did not yet try it, especially since I didn't
find a simple code example of how to use it for my use case. Can
somebody give me a hint?

I also found huffyuv or lagarith which is provided as a directshow
codec for Windows. Can somebody give me a hint how to use a directshow
codec with python?

I am a novice with video encoding. I found that few codecs support
gray scale images. Any hints to take advantage of the fact that I only
have gray scale images?

Thanks for any help

Gregor

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


Re: instead of depending on data = array('h') .. write samples 1 by 1 to w = wave.open("wav.wav", "w")

2009-07-29 Thread Peter Otten
'2+ wrote:

> it says
> Wave_write.writeframes(data)
> will that mean
> "from array import array"
> is a must?
> 
> this does the job:
> 
> import oil
> import wave
> from array import array
> 
> a = oil.Sa()
> 
> w = wave.open("current.wav", "w")
> w.setnchannels(2)
> w.setsampwidth(2)
> w.setframerate(44100)
> 
> data = array('h')
> 
> for gas in range(44100 * 5):
> a.breath()
> r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
> l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
> data.append(r)
> data.append(l)
> 
> w.writeframes(data.tostring())
> w.close()
> 
> don't like array becoming so huge so tested this and it was also okay:
> 
> for gas in range(44100 * 5):
> a.breath()
> data = array('h')
> r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
> l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
> data.append(r)
> data.append(l)
> w.writeframes(data.tostring())
> 
> but without array .. it becomes 15secs(3 times longer than was
> intended to be) of wav file:
> 
> for gas in range(44100 * 5):
> a.breath()
> r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
> l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
> w.writeframes(hex(r))
> w.writeframes(hex(l))

Doesn't it sound strange, too? You are writing bogus bytes to the file. 
Compare:
 
>>> import array
>>> array.array("h", [42]).tostring()
'*\x00'
>>> hex(42)
'0x2a'

Not only do they differ in length, the contents are different, too. If 
you're unfamiliar with string escape codes, here's a way to see the bytes:

>>> map(ord, array.array("h", [42]).tostring())
[42, 0]
>>> map(ord, hex(42))
[48, 120, 50, 97]

> should i just be happy with depennding on using array?
> or is there a solution to make the last one work properly?

There is a way to make the last one work: use struct.pack("h", r) instead of 
hex(r). I'm of course assuming that the first version does give you the 
desired result. You should not continue before you have verified that.

I still recommend array for performance reasons. If memory usage is an issue 
you can adopt a hybrid approach:

# untested
from itertools import islice
from array import array

def gen_data():
for gas in xrange(44100 * 5): # range --> xrange
a.breath()
r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
yield r
yield l

data = gen_data()
N = 2**20
while True:
chunk = array('h')
chunk.extend(islice(data, N))
if not chunk:
break
w.writeframes(chunk.tostring())

This will limit the array size to 4N bytes.

Peter

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


64-bit issues with dictionaries in Python 2.6

2009-07-29 Thread Michael Ströder
HI!

Are there any known issues with dictionaries in Python 2.6 (not 2.6.2)
when running on a 64-bit platform?

A friend of mine experiences various strange problems with my web2ldap
running with Python 2.6 shipped with openSUSE 11.1 x64. For me it seems
some dictionary-based internal registries of web2ldap are not working.
Yes, the next test would be to compile Python 2.6.2 from source...

Any hint is appreciated.

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


idiom for list looping

2009-07-29 Thread superpollo

hi clp.

i want to get from here:

nomi = ["one", "two", "three"]

to here:

0 - one
1 - two
2 - three

i found two ways:

first way:

for i in range(len(nomi)):
print i, "-", nomi[i]

or second way:

for (i, e) in enumerate(nomi):
print i, "-", e

which one is "better"? is there a more pythonic way to do it?

bye

ps:

m...@192.168.1.102:~/test$ python -V
Python 2.3.4
m...@192.168.1.102:~/test$ uname -a
Linux fisso 2.4.24 #1 Thu Feb 12 19:49:02 CET 2004 i686 GNU/Linux
m...@192.168.1.102:~/test$
--
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread David Roberts
To the best of my knowledge the second way is more pythonic - the
first is a little too reminiscent of C. A couple of notes:
- you don't need the parentheses around "i, e"
- if you were going to use the first way it's better to use xrange
instead of range for iteration

--
David Roberts
http://da.vidr.cc/



On Wed, Jul 29, 2009 at 19:02, superpollo wrote:
> hi clp.
>
> i want to get from here:
>
> nomi = ["one", "two", "three"]
>
> to here:
>
> 0 - one
> 1 - two
> 2 - three
>
> i found two ways:
>
> first way:
>
> for i in range(len(nomi)):
>    print i, "-", nomi[i]
>
> or second way:
>
> for (i, e) in enumerate(nomi):
>    print i, "-", e
>
> which one is "better"? is there a more pythonic way to do it?
>
> bye
>
> ps:
>
> m...@192.168.1.102:~/test$ python -V
> Python 2.3.4
> m...@192.168.1.102:~/test$ uname -a
> Linux fisso 2.4.24 #1 Thu Feb 12 19:49:02 CET 2004 i686 GNU/Linux
> m...@192.168.1.102:~/test$
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread MRAB

superpollo wrote:

hi clp.

i want to get from here:

nomi = ["one", "two", "three"]

to here:

0 - one
1 - two
2 - three

i found two ways:

first way:

for i in range(len(nomi)):
print i, "-", nomi[i]

or second way:

for (i, e) in enumerate(nomi):
print i, "-", e

which one is "better"? is there a more pythonic way to do it?


'enumerate' is the Pythonic solution.
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Deprecated sets module" with Python 2.6

2009-07-29 Thread Giampaolo Rodola'
What about this?

import warnings
warnings.simplefilter('ignore', DeprecationWarning)
import the_module_causing_the_warning
warnings.resetwarnings()


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread Xavier Ho
>
> superpollo wrote:
>
>>
>> for (i, e) in enumerate(nomi):
>>print i, "-", e
>>
>> Just to be random:

print '\n'.join(["%s - %s" % (i, e) for i, e in enumerate(nomi)])

This has one advantage: only print once. So it's slightly faster if you have
a list of a large amount.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread MRAB

Xavier Ho wrote:

superpollo wrote:


for (i, e) in enumerate(nomi):
   print i, "-", e

Just to be random:

print '\n'.join(["%s - %s" % (i, e) for i, e in enumerate(nomi)])

This has one advantage: only print once. So it's slightly faster if you 
have a list of a large amount.



Slightly shorter:

print '\n'.join("%s - %s" % p for p in enumerate(nomi))

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


Re: idiom for list looping

2009-07-29 Thread Xavier Ho
On Wed, Jul 29, 2009 at 8:52 PM, MRAB  wrote:

> Slightly shorter:
>
> print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>
> :-)
>
That's cool. Does that make the "list" a tuple? (not that it matters, I'm
just curious!)

I just tested for a list of 1000 elements (number in letters from 1 to 1000
code I wrote for doing project euler problem 17), and the join method is 0.1
seconds faster than the for loop! Woo!? ;p
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread superpollo

MRAB wrote:

Xavier Ho wrote:


superpollo wrote:


for (i, e) in enumerate(nomi):
   print i, "-", e

Just to be random:

print '\n'.join(["%s - %s" % (i, e) for i, e in enumerate(nomi)])

This has one advantage: only print once. So it's slightly faster if 
you have a list of a large amount.



Slightly shorter:

print '\n'.join("%s - %s" % p for p in enumerate(nomi))

:-)


>>> print '\n'.join("%s - %s" % p for p in enumerate(nomi))
  File "", line 1
print '\n'.join("%s - %s" % p for p in enumerate(nomi))
^
SyntaxError: invalid syntax
>>> print '\n'.join(["%s - %s" % p for p in enumerate(nomi)])
0 - one
1 - two
2 - three
>>> help()

Welcome to Python 2.3!  This is the online help utility.
...
>>>

;-)

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


idiom for list looping

2009-07-29 Thread Xavier Ho
Ack, sent to the wrong email again.

On Wed, Jul 29, 2009 at 9:02 PM, superpollo  wrote:

>
> >>> print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>  File "", line 1
>print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>^
> SyntaxError: invalid syntax


lol, I knew I shouldn't have trusted untested code!


> >>> print '\n'.join(["%s - %s" % p for p in enumerate(nomi)])
> 0 - one
> 1 - two
> 2 - three
>

Yup.. but using a variable for the tuple itself was a good move though =P.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for list looping

2009-07-29 Thread MRAB

Xavier Ho wrote:
On Wed, Jul 29, 2009 at 8:52 PM, MRAB > wrote:


Slightly shorter:

print '\n'.join("%s - %s" % p for p in enumerate(nomi))

:-)

That's cool. Does that make the "list" a tuple? (not that it matters, 
I'm just curious!)



I've just replaced the list comprehension with a generator expression.

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


Re: idiom for list looping

2009-07-29 Thread Xavier Ho
On Wed, Jul 29, 2009 at 9:17 PM, MRAB  wrote:


> I've just replaced the list comprehension with a generator expression.
>
>
Oh, and that isn't in Python 2.3 I see. Generators are slightly newer,
eh.

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


Re: Semaphore Techniques

2009-07-29 Thread Nick Craig-Wood
John D Giotta  wrote:
>  I'm looking to run a process with a limit of 3 instances, but each
>  execution is over a crontab interval. I've been investigating the
>  threading module and using daemons to limit active thread objects, but
>  I'm not very successful at grasping the documentation.
> 
>  Is it possible to do what I'm trying to do and if so anyone know of a
>  useful example to get started?

If you want a simple, cross platform way of doing it, then bind each
process to a different local tcp port.

Make a list of 3 ports, and try binding to each port in turn.  If you
can't find a port to bind to then there are already 3 instances
running.

Something like this

import socket
PORTS = range(1,10003)
lock_sock = None

def lock_process(_locks = []):
for port in PORTS:
sock = socket.socket()
try:
sock.bind(("localhost", port))
except socket.error, e:
sock = None
else:
_locks.append(sock)
break
else:
raise Exception("Too many instances of me running")

for i in range(5):
print "Trying",i+1
lock_process()


Which prints

Trying 1
Trying 2
Trying 3
Trying 4
Traceback (most recent call last):
  File "", line 20, in 
  File "", line 16, in lock_process
Exception: Too many instances of me running

You could do the same thing with lock files also very easily...


-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


QFileDialog setFileMode blues

2009-07-29 Thread Rincewind
Heya,

I am fairly new to Python and even newer to Qt.
The problem is opening a Qt file dialog to select folders only.
QFileDialog has a nice and dandy setFileMode() function just for that.
The only trouble is that I cannot make it work.
Last thing I've tried was something like this:

self.fd = QtGui.QFileDialog()
self.fd.setFileMode(self.fd.FileMode(4))
filename = self.fd.getOpenFileName()

..but it was fruitless.

Any help? Tons of internets in return!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QFileDialog setFileMode blues

2009-07-29 Thread Phil Thompson
On Wed, 29 Jul 2009 04:35:42 -0700 (PDT), Rincewind 
wrote:
> Heya,
> 
> I am fairly new to Python and even newer to Qt.
> The problem is opening a Qt file dialog to select folders only.
> QFileDialog has a nice and dandy setFileMode() function just for that.
> The only trouble is that I cannot make it work.
> Last thing I've tried was something like this:
> 
> self.fd = QtGui.QFileDialog()
> self.fd.setFileMode(self.fd.FileMode(4))
> filename = self.fd.getOpenFileName()
> 
> ..but it was fruitless.
> 
> Any help? Tons of internets in return!

QFileDialog.getOpenFileName() is a static method that creates its own
QFileDialog internally. It's not using the one you have created and
configured.

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


Run pyc file without specifying python path ?

2009-07-29 Thread Barak, Ron

Hi,

I wanted to make a python byte-code file executable, expecting to be able to 
run it without specifying "python" on the (Linux bash) command line.

So, I wrote the following:

[r...@vmlinux1 python]# cat test_pyc.py
#!/usr/bin/env python

print "hello"
[r...@vmlinux1 python]#

and made its pyc file executable:

[r...@vmlinux1 python]# ls -ls test_pyc.pyc
4 -rwxr-xr-x  1 root root 106 Jul 29 14:22 test_pyc.pyc
[r...@vmlinux1 python]#

So, I see:

[r...@vmlinux1 python]# file test_pyc.py*
test_pyc.py:  a python script text executable
test_pyc.pyc: python 2.3 byte-compiled
[r...@vmlinux1 python]#

If I try to do the following, no problem:

[r...@vmlinux1 python]# python test_pyc.pyc
hello
[r...@vmlinux1 python]#

However, the following fails:

[r...@vmlinux1 python]# ./test_pyc.pyc
-bash: ./test_pyc.pyc: cannot execute binary file
[r...@vmlinux1 python]#

Is there a way to run a pyc file without specifying the python path ?

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


Re: fast video encoding

2009-07-29 Thread Marcus Wanner

On 7/29/2009 4:14 AM, gregorth wrote:

Hi all,

for a scientific application I need to save a video stream to disc for
further post processing. My cam can deliver 8bit grayscale images with
resolution 640x480 with a framerate up to 100Hz, this is a data rate
of 30MB/s. Writing the data uncompressed to disc hits the data
transfer limits of my current system and creates huge files. Therefore
I would like to use video compression, preferably fast and high
quality to lossless encoding. Final file size is not that important.

Try googling realtime greyscale video codec...

Because of the hardware I am bound to WinXP.

There's always a way to run linux :p


I already tried pymedia for encoding to mpeg2, however I only managed
to get a framerate of about 30-40fps (on a 1.8GHz dual core). There is
still room for improvements in my code, but before trying hard I want
to ask for advices or other possibilities. I also found gstreamer with
pygst python bindings, which seems to be more modern (and performant?)
package than pymedia. I did not yet try it, especially since I didn't
find a simple code example of how to use it for my use case. Can
somebody give me a hint?
Video encoding is not my specialty, but my recommendation here is to 
drop python because of its slow speed and work in c as much as possible.


I also found huffyuv or lagarith which is provided as a directshow
codec for Windows. Can somebody give me a hint how to use a directshow
codec with python?

Not me, sorry :(
Never worked directly with directshow (no pun intended).


I am a novice with video encoding. I found that few codecs support
gray scale images. Any hints to take advantage of the fact that I only
have gray scale images?

Greyscale PNG or BMP compression.


Thanks for any help

Don't know if this counts as help, but you're welcome!


Gregor


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


Re: simple splash screen?

2009-07-29 Thread Marcus Wanner

On 7/28/2009 11:58 PM, NighterNet wrote:

I am trying to make a simple splash screen from python 3.1.Not sure
where to start looking for it. Can any one help?

Trying to make a splash screen for python?
Or trying to do image processing in python?

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


Re: Need help in passing a "-c command" argument to the interactive shell.

2009-07-29 Thread Duncan Booth
Bill  wrote:

> On my windows box I type => c:\x>python -c "import re"
> 
> The result is => c:\x>
> 
> In other words, the Python interactive shell doesn't even open. What
> am I doing wrong?
> 
> I did RTFM at http://www.python.org/doc/1.5.2p2/tut/node4.html on
> argument passing, but to no avail.

Why are you reading documentation for Python 1.5? There have been just a 
few releases since then.

Try reading http://docs.python.org/using/cmdline.html instead, specifically 
the part about the -i command line option. Or you could just try "python 
-?" at a command prompt.

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


Re: about analyze object's stack usage

2009-07-29 Thread Marcus Wanner

On 7/29/2009 3:51 AM, hch wrote:

Is there a python script can get a list of how much stack space each
function in your program uses?

I don't think so.
You could try raw reading of the memory from another thread using ctypes
and pointers, but that would be madness.

( the program is compiled by gcc)
If you're talking about a c program, almost certainly not. What you 
should do is just use gdb and disas each function and look at what it 
subtracts off of %esp at the third instruction in the function.
I can explain it to you if you are not very experienced in gdb and 
assembly...


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


Particle research opens door for new technology

2009-07-29 Thread Rashid Ali Soomro
Big uses for small particles will be explored at the annual Particle
Technology Research Centre Conference at The University of Western
Ontario July 9 and 10.more http://0nanotechnology0.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with sql and python

2009-07-29 Thread catalinf...@gmail.com
Hello !

I have accont on myphpadmin on my server.
I want to create one script in python.
This script manage sql task from my sql server .
How i make this in a simple way ?

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


Re: Particle research opens door for new technology

2009-07-29 Thread Xavier Ho
Is this a spam? Why did you have to send it 4 times, and it's already in the
past (July 9 and 10) ?

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Working with platform.system()

2009-07-29 Thread v1d4l0k4
Hi!

I want to know how I can get different expected return values by
platform.system() method. I want to sniff some systems (Linux, Windows, Mac,
BSD, Solaris) and I don't know how I can check them correctly. Could you
give me some expected return values that you know?

Thanks in advance,
Paulo Ricardo
-- 
http://mail.python.org/mailman/listinfo/python-list


escaping characters in filenames

2009-07-29 Thread J Kenneth King

I wrote a script to process some files using another program.  One thing
I noticed was that both os.listdir() and os.path.walk() will return
unescaped file names (ie: "My File With Spaces & Stuff" instead of "My\
File\ With\ Spaces\ \&\ Stuff").  I haven't had much success finding a
module or recipe that escapes file names and was wondering if anyone
could point me in the right direction.

As an aside, the script is using subprocess.call() with the "shell=True"
parameter.  There isn't really a reason for doing it this way (was just
the fastest way to write it and get a prototype working).  I was
wondering if Popen objects were sensitive to unescaped names like the
shell.  I intend to refactor the function to use Popen objects at some
point and thought perhaps escaping file names may not be entirely
necessary.

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


how to embed the python interpreter into web App

2009-07-29 Thread Mehndi, Sibtey
Hi All
I am trying to embed the python interpreter in to a web app but could not get 
the way, any one can suggest me how to do this.

Thanks,
Sibtey Mehdi


This e-mail (and any attachments), is confidential and may be privileged. It 
may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and 
disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended 
recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or 
disclosing it to a third person.

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


Re: Semaphore Techniques

2009-07-29 Thread Piet van Oostrum
> Carl Banks  (CB) wrote:

>CB> On Jul 28, 3:15 pm, John D Giotta  wrote:
>>> I'm looking to run a process with a limit of 3 instances, but each
>>> execution is over a crontab interval. I've been investigating the
>>> threading module and using daemons to limit active thread objects, but
>>> I'm not very successful at grasping the documentation.
>>> 
>>> Is it possible to do what I'm trying to do and if so anyone know of a
>>> useful example to get started?

>CB> It seems like you want to limit the number of processes to three; the
>CB> threading module won't help you there because it deals with threads
>CB> within a single process.

>CB> What I'd do is to simply run the system ps to see how many processes
>CB> are running (ps is pretty versatile on most systems and can find
>CB> specifically targeted processes like you program), and exit if there
>CB> are already three.

That will surely run into some race conditions. If the limit of 3
processes is soft then that wouldn't be a big deal, however.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QFileDialog setFileMode blues

2009-07-29 Thread Rincewind
On Jul 29, 12:45 pm, Phil Thompson 
wrote:
> On Wed, 29 Jul 2009 04:35:42 -0700 (PDT), Rincewind 
> wrote:
>
> > Heya,
>
> > I am fairly new to Python and even newer to Qt.
> > The problem is opening a Qt file dialog to select folders only.
> > QFileDialog has a nice and dandy setFileMode() function just for that.
> > The only trouble is that I cannot make it work.
> > Last thing I've tried was something like this:
>
> > self.fd = QtGui.QFileDialog()
> > self.fd.setFileMode(self.fd.FileMode(4))
> > filename = self.fd.getOpenFileName()
>
> > ..but it was fruitless.
>
> > Any help? Tons of internets in return!
>
> QFileDialog.getOpenFileName() is a static method that creates its own
> QFileDialog internally. It's not using the one you have created and
> configured.
>
> Phil

You are awesome, thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escaping characters in filenames

2009-07-29 Thread MRAB

J Kenneth King wrote:

I wrote a script to process some files using another program.  One thing
I noticed was that both os.listdir() and os.path.walk() will return
unescaped file names (ie: "My File With Spaces & Stuff" instead of "My\
File\ With\ Spaces\ \&\ Stuff").  I haven't had much success finding a
module or recipe that escapes file names and was wondering if anyone
could point me in the right direction.


That's only necessary if you're building a command line and passing it
as a string.


As an aside, the script is using subprocess.call() with the "shell=True"
parameter.  There isn't really a reason for doing it this way (was just
the fastest way to write it and get a prototype working).  I was
wondering if Popen objects were sensitive to unescaped names like the
shell.  I intend to refactor the function to use Popen objects at some
point and thought perhaps escaping file names may not be entirely
necessary.


Pass the command line to Popen as a list of strings.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python for uCLinux appliance?

2009-07-29 Thread Diez B. Roggisch
Gilles Ganault wrote:

> Hello
> 
> I just got a small appliance based on a Blackfin CPU with 64MB RAM and
> 258MB NAND flash. Using the stock software, there's about 30MB of RAM
> left.
> 
> Besides C/C++ and shel scripts, I was wondering if it were realistic
> to upload a few Python scripts in such a small appliance?

Try & check out the gumstix software repo. It comes with python, and thus
some crosscompiling/build-instructions should be in there.

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


Re: bad certificate error

2009-07-29 Thread jakecjacobson
On Jul 29, 2:08 am, "Gabriel Genellina" 
wrote:
> En Tue, 28 Jul 2009 09:02:40 -0300, Steven D'Aprano  
>  escribió:
>
>
>
> > On Mon, 27 Jul 2009 23:16:39 -0300, Gabriel Genellina wrote:
>
> >> I don't see the point on "fixing" either the Python script or httplib to
> >> accomodate for an invalid server certificate... If it's just for
> >> internal testing, I'd use HTTP instead (at least until the certificate
> >> is fixed).
>
> > In real life, sometimes you need to drive with bad brakes on your car,
> > walk down dark alleys in the bad part of town, climb a tree without a
> > safety line, and use a hammer without wearing goggles. We can do all
> > these things.
>
> > The OP has said that, for whatever reason, he needs to ignore a bad
> > server certificate when connecting to HTTPS. Python is a language where
> > developers are allowed to shoot themselves in the foot, so long as they
> > do so in full knowledge of what they're doing.
>
> > So, putting aside all the millions of reasons why the OP shouldn't accept
> > an invalid certificate, how can he accept an invalid certificate?
>
> Yes, I understand the situation, but I'm afraid there is no way (that I  
> know of). At least not without patching _ssl.c; all the SSL negotiation is  
> handled by the OpenSSL library itself.
>
> I vaguely remember a pure Python SSL implementation somewhere that perhaps  
> could be hacked to bypass all controls. But making it work properly will  
> probably require a lot more effort than installing a self signed  
> certificate in the server...
>
> --
> Gabriel Genellina

I have it working and I want to thank everyone for their efforts and
very helpful hints.  The error was with me and not understanding the
documentation about the cert_file & key_file.  After using openssl to
divide up my p12 file into a cert file and a key file using the
instructions 
http://security.ncsa.uiuc.edu/research/grid-howtos/usefulopenssl.php.
I got everything working.

Again, much thanks.

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


Re: simple splash screen?

2009-07-29 Thread NighterNet
On Jul 29, 5:24 am, Marcus Wanner  wrote:
> On 7/28/2009 11:58 PM, NighterNet wrote:> I am trying to make a simple splash 
> screen from python 3.1.Not sure
> > where to start looking for it. Can any one help?
>
> Trying to make a splash screen for python?
> Or trying to do image processing in python?
>
> Marcus

trying to use jpg,gif,png for the splash screen
-- 
http://mail.python.org/mailman/listinfo/python-list


Clearing an array

2009-07-29 Thread WilsonOfCanada
Hellos,

I was wondering if there is any built-in function that clears the
array.  I was also wondering if this works:

arrMoo = ['33', '342',  '342']
arrMoo = []
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New implementation of re module

2009-07-29 Thread Mike
On Jul 27, 11:34 am, MRAB  wrote:
> I've been working on a new implementation of the re module.

Fabulous!

If you're extending/changing the interface, there are a couple of sore
points in the current implementation I'd love to see addressed:

- findall/finditer doesn't find overlapping matches.  Sometimes you
really *do* want to know all possible matches, even if they overlap.
This comes up in bioinformatics, for example.

- split won't split on empty patterns, e.g. empty lookahead patterns.
This means that it can't be used for a whole class of interesting
cases.  This has been discussed previously:

http://bugs.python.org/issue3262
http://bugs.python.org/issue852532
http://bugs.python.org/issue988761

- It'd be nice to have a version of split that generates the parts
(one by one) rather than returning the whole list.

- Repeated subgroup match information is not available.  That is, for
a match like this

re.match('(.){3}', 'xyz')

there's no way to discover that the subgroup first matched 'x', then
matched 'y', and finally matched 'z'.  Here is one past proposal
(mine), perhaps over-complex, to address this problem:

http://mail.python.org/pipermail/python-dev/2004-August/047238.html

Mike

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


Very Strange Problem

2009-07-29 Thread Omer Khalid
Hi,

I am having a very strange problem with modifying a variable in a list in my
program. Here is the code:

# a list that contains dictionary objects
jobs = []

index=5
for each in range(index):
 jobs.append({'v':0})

some_function(index):
   if jobs[index]['v'] == 0:
   # set it to 1
   jobs[index]['v'] = 1
   print "Set to 1"
  else:
   print "Already set to 1"

loop():
index=0
for each in range(len(jobs)):
 some_function(index)
 index +=1


Apparently, the jobs[index]['v'] never get updated in the some_function but
the print statement afterwards get printed...

What's really surprising is that there are no errors or exceptions and my my
program runs in a single thread...so i have been unable to explain this
behavior.

Any insight would be much appreciated!

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


Re: Clearing an array

2009-07-29 Thread Diez B. Roggisch
WilsonOfCanada wrote:

> Hellos,
> 
> I was wondering if there is any built-in function that clears the
> array.  I was also wondering if this works:
> 
> arrMoo = ['33', '342',  '342']
> arrMoo = []

Most of the time, yes. Unless you have something like this, then it won't
work:


foo = [10]

bar = foo # an alias

foo = []

assert foo == bar

Then what you need to to is this:

foo[:] = []


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


Re: Clearing an array

2009-07-29 Thread Jason Tackaberry
On Wed, 2009-07-29 at 08:24 -0700, WilsonOfCanada wrote:
> I was wondering if there is any built-in function that clears the
> array.

The proper python term would be "list."  You can remove all elements of
a list 'l' like so:

   del l[:]


>   I was also wondering if this works:
> 
> arrMoo = ['33', '342',  '342']
> arrMoo = []

That doesn't clear the list as such, but rather creates a new list, and
reassigns the new list to the 'arrMoo' name in the local scope.
Consider:

>>> l1 = [1,2,3]
>>> l2 = l1
>>> l1 = []
>>> print l2
[1, 2, 3]

So the original list 'l1' lives on.  However:

>>> l1 = [1,2,3]
>>> l2 = l1
>>> del l1[:]
>>> print l1, l2
[] []

Cheers,
Jason.

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


Re: python 3 and stringio.seek

2009-07-29 Thread Terry Reedy

Miles Kaufmann wrote:


On Jul 28, 2009, at 6:30 AM, Michele Petrazzo wrote:


Hi list,
I'm trying to port a my library to python 3, but I have a problem with a
the stringio.seek:
the method not accept anymore a value like pos=-6 mode=1, but the "old"
(2.X) version yes...

The error:
 File "/home/devel/Py3/lib/python3.0/io.py", line 2031, in seek
   return self._seek(pos, whence)
IOError: Can't do nonzero cur-relative seeks


How solve this?


In Python 2, StringIO is a stream of bytes (non-Unicode characters).  In 
Python 3, StringIO is a stream of text (Unicode characters).  In the 
early development of Python 3 (and 3.1's _pyio), it was implemented as a 
TextIOWrapper over a BytesIO buffer.  TextIOWrapper does not support 
relative seeks because it is difficult to map the concept of a "current 
position" between bytes and the text that it encodes, especially with 
variable-width encodings and other considerations.  Furthermore, the 
value returned from TextIOWrapper.tell isn't just a file position but a 
"cookie" that contains other data necessary to restore the decoding 
mechanism to the same state.  However, for the default encoding (utf-8), 
the current position is equivalent to that of the underlying bytes buffer.


In Python 3, StringIO is implemented using an internal buffer of Unicode 
characters.  There is no technical reason why it can't support relative 
seeks; I assume it does not for compatibility with the original Python 
TextIOWrapper implementation (which is present in 3.1's _pyio, but not 
in 3.0).


Note that because of the different implementations, StringIO.tell() (and 
seek) behaves differently for the C and Python implementations:


$ python3.1
 >>> import io, _pyio
 >>> s = io.StringIO('\u263A'); s.read(1), s.tell()
('☺', 1)
 >>> s = _pyio.StringIO('\u263A'); s.read(1), s.tell()
('☺', 3)


It seems to me that this discrepancy might be worth a tracker item.
I wonder why the second implementation is even there if not used.
Two different commiters?

The end result seems to be that, for text streams (including StreamIO), 
you *should* treat the value returned by tell() as an opaque magic 
cookie, and *only* pass values to seek() that you have obtained from a 
previous tell() call.  However, in practice, it appears that you *may* 
seek StringIO objects relatively by characters using s.seek(s.tell() + 
n), so long as you do not use the _pyio.StringIO implementation.


A tracker item could include a request that relative seek be restored if 
possible.


tjr

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


Re: New implementation of re module

2009-07-29 Thread MRAB

Mike wrote:

On Jul 27, 11:34 am, MRAB  wrote:

I've been working on a new implementation of the re module.


Fabulous!

If you're extending/changing the interface, there are a couple of sore
points in the current implementation I'd love to see addressed:

- findall/finditer doesn't find overlapping matches.  Sometimes you
really *do* want to know all possible matches, even if they overlap.
This comes up in bioinformatics, for example.


Perhaps by adding "overlapped=True"?


- split won't split on empty patterns, e.g. empty lookahead patterns.
This means that it can't be used for a whole class of interesting
cases.  This has been discussed previously:

http://bugs.python.org/issue3262
http://bugs.python.org/issue852532
http://bugs.python.org/issue988761


Already addressed (see issue2636 for the full details).


- It'd be nice to have a version of split that generates the parts
(one by one) rather than returning the whole list.


Hmm, re.splititer() perhaps.


- Repeated subgroup match information is not available.  That is, for
a match like this

re.match('(.){3}', 'xyz')

there's no way to discover that the subgroup first matched 'x', then
matched 'y', and finally matched 'z'.  Here is one past proposal
(mine), perhaps over-complex, to address this problem:

http://mail.python.org/pipermail/python-dev/2004-August/047238.html


Yikes! I think I'll let you code that... :-)
--
http://mail.python.org/mailman/listinfo/python-list


SEC forms parsing

2009-07-29 Thread mpython
I am looking for any python examples that have written to parse SEC
filings (Security Exchange Commission's EDGAR system),or just a
pointer to best modules to use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very Strange Problem

2009-07-29 Thread MRAB

Omer Khalid wrote:

Hi,

I am having a very strange problem with modifying a variable in a list 
in my program. Here is the code:


# a list that contains dictionary objects
jobs = []

index=5
for each in range(index):
 jobs.append({'v':0})

some_function(index):
   if jobs[index]['v'] == 0:
   # set it to 1
   jobs[index]['v'] = 1
   print "Set to 1"
  else:
   print "Already set to 1"

loop():
index=0
for each in range(len(jobs)):
 some_function(index)
 index +=1


Apparently, the jobs[index]['v'] never get updated in the some_function 
but the print statement afterwards get printed...


What's really surprising is that there are no errors or exceptions and 
my my program runs in a single thread...so i have been unable to explain 
this behavior.


Any insight would be much appreciated!


Well, when I insert the missing 'def's in the function definitions, it
works for me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python for uCLinux appliance?

2009-07-29 Thread Grant Edwards
On 2009-07-29, Diez B. Roggisch  wrote:
> Gilles Ganault wrote:
>
>> Hello
>> 
>> I just got a small appliance based on a Blackfin CPU with 64MB RAM and
>> 258MB NAND flash. Using the stock software, there's about 30MB of RAM
>> left.
>> 
>> Besides C/C++ and shel scripts, I was wondering if it were realistic
>> to upload a few Python scripts in such a small appliance?

The standard uclinux-dist comes with python, so it's pretty
much just a question of memory.  Asking on the uclinux mailing
list will probably be more useful, but I would guess that 64MB
would be plenty -- especially if use JFFS to put your root
filesystem in flash instead of in RAM.  Of course it depends
entirely on what else you want to do with that RAM at the same
time...

> Try & check out the gumstix software repo. It comes with
> python, and thus some crosscompiling/build-instructions should
> be in there.

IIRC, all you have to do is "make menuconfig", go to the user
apps page and check the "Python" box, and then "make".  It
should "just work".

-- 
Grant Edwards   grante Yow! I haven't been married
  at   in over six years, but we
   visi.comhad sexual counseling every
   day from Oral Roberts!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to embed the python interpreter into web App (Mehndi, Sibtey)

2009-07-29 Thread Ryniek90



Hi All

I am trying to embed the python interpreter in to a web app but could 
not get the way, any one can suggest me how to do this.


 


Thanks,

Sibtey Mehdi

 


This e-mail (and any attachments), is confidential and may be privileged. It 
may be read, copied and used only
by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its 
contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately 
by e-mail/phone & delete it from their system without making any copies or disclosing it to a third person.



  


Here's example: http://try-python.mired.org/

Contact with author of that website/webapp.

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


Re: Very Strange Problem

2009-07-29 Thread MRAB

Ricardo Aráoz wrote:

MRAB wrote:

Omer Khalid wrote:

Hi,

I am having a very strange problem with modifying a variable in a 
list in my program. Here is the code:


# a list that contains dictionary objects
jobs = []

index=5
for each in range(index):
 jobs.append({'v':0})

some_function(index):
   if jobs[index]['v'] == 0:
   # set it to 1
   jobs[index]['v'] = 1
   print "Set to 1"
  else:
   print "Already set to 1"

loop():
index=0
for each in range(len(jobs)):
 some_function(index)
 index +=1


Apparently, the jobs[index]['v'] never get updated in the 
some_function but the print statement afterwards get printed...


What's really surprising is that there are no errors or exceptions 
and my my program runs in a single thread...so i have been unable to 
explain this behavior.


Any insight would be much appreciated!


Well, when I insert the missing 'def's in the function definitions, it
works for me.
Hi Omer, what he is trying to convey in his rude manner is that you are 
missing "def" in your function definitions. It is probably a beginners 
mistake.


That is :
from "some_function(index): "
to "def some_function(index): "

from "loop(): "
to "def loop(): "

I have not tried your code so you should believe him when he states he 
has actually run the code.

HTH


Omer says "the print statement afterwards get printed", but the code
provided would have raised a SyntaxError, so omitting the 'def's can't
be the cause of the actual problem reported.
--
http://mail.python.org/mailman/listinfo/python-list


Re: bad certificate error

2009-07-29 Thread John Nagle

jakecjacobson wrote:

Hi,

I am getting the following error when doing a post to REST API,

Enter PEM pass phrase:
Traceback (most recent call last):
  File "./ices_catalog_feeder.py", line 193, in ?
main(sys.argv[1])
  File "./ices_catalog_feeder.py", line 60, in main
post2Catalog(catalog_host, catalog_port, catalog_path, os.path.join
(input_dir, file), collection_name, key_file, cert_file)
  File "./ices_catalog_feeder.py", line 125, in post2Catalog
connection.request('POST', path, parameters, head)
  File "/usr/lib/python2.4/httplib.py", line 810, in request
self._send_request(method, url, body, headers)
  File "/usr/lib/python2.4/httplib.py", line 833, in _send_request
self.endheaders()
  File "/usr/lib/python2.4/httplib.py", line 804, in endheaders
self._send_output()
  File "/usr/lib/python2.4/httplib.py", line 685, in _send_output
self.send(msg)
  File "/usr/lib/python2.4/httplib.py", line 652, in send
self.connect()
  File "/usr/lib/python2.4/httplib.py", line 1079, in connect
ssl = socket.ssl(sock, self.key_file, self.cert_file)
  File "/usr/lib/python2.4/socket.py", line 74, in ssl
return _realssl(sock, keyfile, certfile)
socket.sslerror: (1, 'error:14094412:SSL
routines:SSL3_READ_BYTES:sslv3 alert bad certificate')


   What SSL implementation are you using?  The old one from Python 2.4
doesn't even check the certificate chain.  M2Crypto does, and the new
SSL module does, but in each case you have to provide a root certificate
file.  (The one from Mozilla is available.)

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


Re: SEC forms parsing

2009-07-29 Thread John Nagle

mpython wrote:

I am looking for any python examples that have written to parse SEC
filings (Security Exchange Commission's EDGAR system),or just a
pointer to best modules to use.


   I've been doing that in Perl for years.  See "www.downside.com".

   Actually extracting financial statements is possible, but you
run into a patent problem with a Price-Waterhouse patent if you try
to do a good job.

   What are you trying to do?

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


Re: Help with sql and python

2009-07-29 Thread Piet van Oostrum
> "catalinf...@gmail.com"  (cc) wrote:

>cc> Hello !
>cc> I have accont on myphpadmin on my server.
>cc> I want to create one script in python.
>cc> This script manage sql task from my sql server .
>cc> How i make this in a simple way ?

See http://mysql-python.sourceforge.net/MySQLdb.html

This really has nothing to do with myphpadmin (you probably mean
phpMyAdmin but even then it has nothing to do with it except that both
acess a MySQL database).

And if you give yourself a name than we might have an idea if we are
talking to a human being or a robot.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New implementation of re module

2009-07-29 Thread Mike
On Jul 29, 10:45 am, MRAB  wrote:
> Mike wrote:
> > - findall/finditer doesn't find overlapping matches.  Sometimes you
> > really *do* want to know all possible matches, even if they overlap.
>
> Perhaps by adding "overlapped=True"?

Something like that would be great, yes.


> > - split won't split on empty patterns, e.g. empty lookahead patterns.

> Already addressed (see issue2636 for the full details).

Glad to hear it.


> > - Repeated subgroup match information is not available.  That is, for
> > a match like this
>
> >     re.match('(.){3}', 'xyz')
>
> > there's no way to discover that the subgroup first matched 'x', then
> > matched 'y', and finally matched 'z'.  Here is one past proposal
> > (mine), perhaps over-complex, to address this problem:
>
> >    http://mail.python.org/pipermail/python-dev/2004-August/047238.html
>
> Yikes! I think I'll let you code that... :-)

I agree that that document looks a little scary--maybe I was trying to
bite off too much at once.

My intuition, though, is that the basic idea should be fairly simple
to implement, at least for a depth-first matcher.  The repeated match
subgroups are already being discovered, it's just that they're not
being saved, so there's no way to report them out once a complete
match is found.  If some trail of breadcrumbs were pushed onto a stack
during the DFS, it could be traced at the end.  And the whole thing
might not even been that expensive to do.

The hardest parts about this, in my mind, are figuring out how to
report the repeated matches out in a useful form (hence all that
detail in the proposal), and getting users to understand that using
this feature *could* suck up a lot of memory, if they're not careful.

As always, it's possible that my intuition is totally wrong.  Plus I'm
not sure how this would work out in the breadth-first case.

Details aside, I would really, really, really like to have a way to
get at the repeated subgroup matches.  I write a lot of code that
would be one-liners if this capability existed.  Plus, it just plain
burns me that Python is discovering this information but impudently
refuses to tell me what it's found!  ;-)


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


Re: open a file in python

2009-07-29 Thread Piet van Oostrum
> jayshree  (j) wrote:

>>> The Exact Problem is how to use the key containing by .pem file for
>>> 'encryption' . can i print the contents of the .pem file

I have already answered this question in a previous thread. It is not
very helpful if you repeat asking the same or similar questions in
different threads, especially if you don't take notice of the answers
given. I will repeat it once here:

load_pub_key requires a file name, not the contents of the file.
So use rsa = M2Crypto.RSA.load_pub_key('my_key.public.pem') and leave
the open line out.

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread dandi kain
Hello everybody,
I have just started learning Python.I heard its simple so I pick a
presentation [1] and tried to work on it.But when it comes to
underscores leading and trailing an object I dont understand any.I
look through the python manual also but that was not helping .I
searched some forums and I still dont have a clear picture.

What is the functionality of __ or _ , leading or trailing an object ,
class ot function ? Is it just a naming convention to note special
functions and objects , or it really mean someting to Python ?

Thanks ahead ,

[1] http://www.aleax.it/goo_py4prog.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Print value CLOB via cx_Oracle

2009-07-29 Thread Vincent Vega
On 28 Lip, 20:02, Vincent Vega  wrote:
> Hi,
>
> I call function in Oracle database use cx_Oracle.
> In standard I define:
>
> db       = cx_Oracle.connect(username, password, tnsentry)
> cursor  = db.cursor()
>
> I create variable 'y' (result function 'fun_name') and call function
> 'fun_name':
>
> y   = cursor.var(cx_Oracle.CLOB)
> cursor.callfunc(fun_name, cx_Oracle.CLOB, y)
>
> When I print variable 'y' I receive:
> >
>
> How can I get value variable 'y'???
> How read ???
>
> Vincent Vega
>
> Note:
> Off course y.read() does not work, cause 'y'is CLOB not LOB.
> (see datatypes table in 
> site:http://www.oracle.com/technology/pub/articles/prez-python-queries.html)

The solution is simple:

print y.getvalue()

(see: http://cx-oracle.sourceforge.net/html/variable.html)

Thanks! :)

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


Re: Run pyc file without specifying python path ?

2009-07-29 Thread Dave Angel

Barak, Ron wrote:

Hi,

I wanted to make a python byte-code file executable, expecting to be able to run it 
without specifying "python" on the (Linux bash) command line.

So, I wrote the following:

[r...@vmlinux1 python]# cat test_pyc.py
#!/usr/bin/env python

print "hello"
[r...@vmlinux1 python]#

and made its pyc file executable:

[r...@vmlinux1 python]# ls -ls test_pyc.pyc
4 -rwxr-xr-x  1 root root 106 Jul 29 14:22 test_pyc.pyc
[r...@vmlinux1 python]#

So, I see:

[r...@vmlinux1 python]# file test_pyc.py*
test_pyc.py:  a python script text executable
test_pyc.pyc: python 2.3 byte-compiled
[r...@vmlinux1 python]#

If I try to do the following, no problem:

[r...@vmlinux1 python]# python test_pyc.pyc
hello
[r...@vmlinux1 python]#

However, the following fails:

[r...@vmlinux1 python]# ./test_pyc.pyc
-bash: ./test_pyc.pyc: cannot execute binary file
[r...@vmlinux1 python]#

Is there a way to run a pyc file without specifying the python path ?

Bye,
Ron.

  

I don't currently run Unix, but I think I know the problem.

In a text file, the shell examines the first line, and if it begins #! 
it's assumed to point to the executable of an interpreter for that text 
file.  Presumably the same trick doesn't work for a .pyc file.


Why not write a trivial wrapper.py file, don't compile it, and let that 
invoke the main code in the .pyc file?


Then make wrapper.py executable, and you're ready to go.

DaveA

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


Re: Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread Benjamin Kaplan
On Wed, Jul 29, 2009 at 1:59 PM, dandi kain  wrote:
>
> Hello everybody,
> I have just started learning Python.I heard its simple so I pick a
> presentation [1] and tried to work on it.But when it comes to
> underscores leading and trailing an object I dont understand any.I
> look through the python manual also but that was not helping .I
> searched some forums and I still dont have a clear picture.
>
> What is the functionality of __ or _ , leading or trailing an object ,
> class ot function ? Is it just a naming convention to note special
> functions and objects , or it really mean someting to Python ?

It's just a convention for the most part. A single leading underscore
is used for "private" attributes. Two leading underscores will affect
the code- it mangles the variable name so that you don't have to worry
about the value being overwritten by a subclass. For instance
"""
class Foo(object) :
   def __init__(self) :
   self.__bar = ''

foo = Foo()
""
will store the attribute as foo._Foo__bar.

Also, the "magic methods"- the ones that are used for operations and
built-in stuff, all have two leading and two trailing underscores.
These are things like __add__ (+), __eq__ (=), __cmp__ (old way for
comparisons), __len__ (len), __str__ (str), and so on.


>
> Thanks ahead ,
>
> [1] http://www.aleax.it/goo_py4prog.pdf
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with sql and python

2009-07-29 Thread Dave Angel

catalinf...@gmail.com wrote:

Hello !

I have accont on myphpadmin on my server.
I want to create one script in python.
This script manage sql task from my sql server .
How i make this in a simple way ?

Thank you !

  

It's seldom simple.

I'm guessing it's not your server, but is actually a webserver, located 
remotely, and to which you have only ftp access.


Next questions are do you have access to the admins of the machine, what 
kind of machine is it, what OS is it running, does it have Python 
installed, what version(s)?


Next questions are dependent on the answers to those questions.  For 
example, on Unix systems you'll generally need to be able to chmod the file.


But before you ask your admins those questions, you need to ask how you 
*want* to run the script.  Creating it isn't enough, if you don't run 
it.  You might be running it over the web, via URL, perhaps using CGI.  
You might be activating it via some remote console, or rsh.  Or it might 
be a cron job.  It might need various privileges to do what you expect.  
And if it's going to run continuously, or if it uses lots of resources, 
the admins may refuse it entirely.


DaveA

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


Re: simple splash screen?

2009-07-29 Thread Martin P. Hellwig

NighterNet wrote:

I am trying to make a simple splash screen from python 3.1.Not sure
where to start looking for it. Can any one help?


Sure, almost the same as with Python 2 :-)
But to be a bit more specific:

"""Only works if you got Python 3 installed with tkinter"""
import tkinter

IMAGE_PATH = "/path/to/image"

class Splash(object):
"Splash Screen GUI"
def __init__(self, root):
self.root = root
# No window borders and decoration
self.root.overrideredirect(True)
# Get the size of the screen
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
# Full screen
geometry_text = "%dx%d+0+0" % (screen_width, screen_height)
self.root.geometry(geometry_text)
# Display an image
self.label = tkinter.Label(self.root)
# Only GIF and PGM/PPM supported, for more information see:
self.label._image = tkinter.PhotoImage(file=IMAGE_PATH)
# http://effbot.org/tkinterbook/photoimage.htm
self.label.configure(image = self.label._image)
self.label.pack()
# This will quit the screen after about 5 seconds
self.root.after(5000, self.root.quit)

if __name__ == '__main__':
ROOT = tkinter.Tk()
APPL = Splash(ROOT)
ROOT.mainloop()


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: instead of depending on data = array('h') .. write samples 1 by 1 to w = wave.open("wav.wav", "w")

2009-07-29 Thread '2+
o wow .. there's still a lot to learn ..
okay .. if i get stucked with the memory usage issue
will try this hybrid .. thanx for the example!!

it took about 40 min to render 1min of wav
so i'll just keep this project like 15 sec oriented
and maybe that'll keep me away from the mem trouble

and my oil.py is still so cheap..
sad thing is that "the result sound strange" is true to
all versions :s

thanx again anyway!


On Wed, Jul 29, 2009 at 5:21 PM, Peter Otten<__pete...@web.de> wrote:
> '2+ wrote:
>
>> it says
>> Wave_write.writeframes(data)
>> will that mean
>> "from array import array"
>> is a must?
>>
>> this does the job:
>>
>> import oil
>> import wave
>> from array import array
>>
>> a = oil.Sa()
>>
>> w = wave.open("current.wav", "w")
>> w.setnchannels(2)
>> w.setsampwidth(2)
>> w.setframerate(44100)
>>
>> data = array('h')
>>
>> for gas in range(44100 * 5):
>>     a.breath()
>>     r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
>>     l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
>>     data.append(r)
>>     data.append(l)
>>
>> w.writeframes(data.tostring())
>> w.close()
>>
>> don't like array becoming so huge so tested this and it was also okay:
>>
>> for gas in range(44100 * 5):
>>     a.breath()
>>     data = array('h')
>>     r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
>>     l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
>>     data.append(r)
>>     data.append(l)
>>     w.writeframes(data.tostring())
>>
>> but without array .. it becomes 15secs(3 times longer than was
>> intended to be) of wav file:
>>
>> for gas in range(44100 * 5):
>>     a.breath()
>>     r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
>>     l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
>>     w.writeframes(hex(r))
>>     w.writeframes(hex(l))
>
> Doesn't it sound strange, too? You are writing bogus bytes to the file.
> Compare:
>
 import array
 array.array("h", [42]).tostring()
> '*\x00'
 hex(42)
> '0x2a'
>
> Not only do they differ in length, the contents are different, too. If
> you're unfamiliar with string escape codes, here's a way to see the bytes:
>
 map(ord, array.array("h", [42]).tostring())
> [42, 0]
 map(ord, hex(42))
> [48, 120, 50, 97]
>
>> should i just be happy with depennding on using array?
>> or is there a solution to make the last one work properly?
>
> There is a way to make the last one work: use struct.pack("h", r) instead of
> hex(r). I'm of course assuming that the first version does give you the
> desired result. You should not continue before you have verified that.
>
> I still recommend array for performance reasons. If memory usage is an issue
> you can adopt a hybrid approach:
>
> # untested
> from itertools import islice
> from array import array
>
> def gen_data():
>    for gas in xrange(44100 * 5): # range --> xrange
>        a.breath()
>        r = int(32767 * (a.pulse(1) + a.pulse(2) + a.pulse(3)) / 3.0)
>        l = int(32767 * (a.pulse(4) + a.pulse(5) + a.pulse(6)) / 3.0)
>        yield r
>        yield l
>
> data = gen_data()
> N = 2**20
> while True:
>    chunk = array('h')
>    chunk.extend(islice(data, N))
>    if not chunk:
>        break
>    w.writeframes(chunk.tostring())
>
> This will limit the array size to 4N bytes.
>
> Peter
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
SaRiGaMa's Oil Vending Orchestra
is podcasting:
http://sarigama.namaste.jp/podcast/rss.xml
and supplying oil.py for free:
http://oilpy.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escaping characters in filenames

2009-07-29 Thread Dave Angel

J Kenneth King wrote:

I wrote a script to process some files using another program.  One thing
I noticed was that both os.listdir() and os.path.walk() will return
unescaped file names (ie: "My File With Spaces & Stuff" instead of "My\
File\ With\ Spaces\ \&\ Stuff").  I haven't had much success finding a
module or recipe that escapes file names and was wondering if anyone
could point me in the right direction.

As an aside, the script is using subprocess.call() with the "shell=True"
parameter.  There isn't really a reason for doing it this way (was just
the fastest way to write it and get a prototype working).  I was
wondering if Popen objects were sensitive to unescaped names like the
shell.  I intend to refactor the function to use Popen objects at some
point and thought perhaps escaping file names may not be entirely
necessary.

Cheers

  
There are dozens of meanings for escaping characters in strings.  
Without some context, we're wasting our time.


For example, if the filename is to be interpreted as part of a URL, then 
spaces are escaped by using %20.   Exactly who is going to be using this 
string you think you have to modify?  I don't know of any environment 
which expects spaces to be escaped with backslashes.


Be very specific.  For example, if a Windows application is parsing its 
own command line, you need to know what that particular application is 
expecting -- Windows passes the entire command line as a single string.  
But of course you may be invoking that application using 
subprocess.Popen(), in which case some transformations happen to your 
arguments before the single string is built.  Then some more 
transformations may happen in the shell.  Then some more in the C 
runtime library of the new process (if it happens to be in C, and if it 
happens to use those libraries).


I'm probably not the one with the answer.  But until you narrow down 
your case, you probably won't attract the attention of whichever person 
has the particular combination of experience that you're hoping for.


DaveA

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


Re: Semaphore Techniques

2009-07-29 Thread John D Giotta
I'm working with up to 3 process "session" per server, each process
running three threads.
I was wishing to tie back the 3 "session"/server to a semaphore, but
everything (and everyone) say semaphores are only good per process.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semaphore Techniques

2009-07-29 Thread John D Giotta
That was my original idea. Restricting each process by pid:

#bash
procs=`ps aux | grep script.pl | grep -v grep | wc -l`

if [ $procs -lt 3 ]; then
python2.4 script.py config.xml
else
exit 0
fi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Semaphore Techniques

2009-07-29 Thread Christian Heimes
John D Giotta schrieb:
> I'm working with up to 3 process "session" per server, each process
> running three threads.
> I was wishing to tie back the 3 "session"/server to a semaphore, but
> everything (and everyone) say semaphores are only good per process.

That's not true. Named semaphores are the best solution for your problem
and I said so yesterday.

Christian

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


Re: Very Strange Problem

2009-07-29 Thread Dave Angel

Omer Khalid wrote:

Hi,

I am having a very strange problem with modifying a variable in a list in my
program. Here is the code:

# a list that contains dictionary objects
jobs = []

index=5
for each in range(index):
 jobs.append({'v':0})

some_function(index):
   if jobs[index]['v'] == 0:
   # set it to 1
   jobs[index]['v'] = 1
   print "Set to 1"
  else:
   print "Already set to 1"

loop():
index=0
for each in range(len(jobs)):
 some_function(index)
 index +=1


Apparently, the jobs[index]['v'] never get updated in the some_function but
the print statement afterwards get printed...

What's really surprising is that there are no errors or exceptions and my my
program runs in a single thread...so i have been unable to explain this
behavior.

Any insight would be much appreciated!

Cheers
Omer

  
There are four things to fix before the program does anything much at 
all.  Two places you're missing the def, indentation is inconsistent, 
and you never actually call either of the functions.   The first three 
are syntax errors, so presumably your cut/paste in your computer is broken.


Once I make those four corrections, I get the following output:

Set to 1
Set to 1
Set to 1
Set to 1
Set to 1

But you never said what you got, nor what you expected.  That's 
certainly what I'd expect.  And if you make a second call to loop() in 
your outer code, you get five copies of "Already set to 1"


BTW, there are a number of things that could be done better.  The main 
one I'll point out is that you shouldn't re-use a global variable 
'index' as a local with different meaning.  As someone else pointed out, 
since the global is a constant, making it all uppercase is the convention.


DaveA

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


Re: escaping characters in filenames

2009-07-29 Thread Nobody
On Wed, 29 Jul 2009 09:29:55 -0400, J Kenneth King wrote:

> I wrote a script to process some files using another program.  One thing
> I noticed was that both os.listdir() and os.path.walk() will return
> unescaped file names (ie: "My File With Spaces & Stuff" instead of "My\
> File\ With\ Spaces\ \&\ Stuff").  I haven't had much success finding a
> module or recipe that escapes file names and was wondering if anyone
> could point me in the right direction.
> 
> As an aside, the script is using subprocess.call() with the "shell=True"
> parameter.  There isn't really a reason for doing it this way (was just
> the fastest way to write it and get a prototype working).  I was
> wondering if Popen objects were sensitive to unescaped names like the
> shell.  I intend to refactor the function to use Popen objects at some
> point and thought perhaps escaping file names may not be entirely
> necessary.

Note that subprocess.call() is nothing more than:

def call(*popenargs, **kwargs):
return Popen(*popenargs, **kwargs).wait()

plus a docstring. It accepts exactly the same arguments as Popen(), with
the same semantics.

If you want to run a command given a program and arguments, you
should pass the command and arguments as a list, rather than trying to
construct a string.

On Windows the value of shell= is unrelated to whether the command is
a list or a string; a list is always converted to string using the
list2cmdline() function. Using shell=True simply prepends "cmd.exe /c " to
the string (this allows you to omit the .exe/.bat/etc extension for
extensions which are in %PATHEXT%).

On Unix, a string is first converted to a single-element list, so if you
use a string with shell=False, it will be treated as the name of an
executable to be run without arguments, even if contains spaces, shell
metacharacters etc.

The most portable approach seems to be to always pass the command as a
list, and to set shell=True on Windows and shell=False on Unix.

The only reason to pass a command as a string is if you're getting a
string from the user and you want it to be interpreted using the
platform's standard shell (i.e. cmd.exe or /bin/sh). If you want it to be
interpreted the same way regardless of platform, parse it into a
list using shlex.split().

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


set variable to looping index?

2009-07-29 Thread Martin
Hi,

I am trying to set the return value from a function to a name which I
grab from the for loop. I can't work out how I can do this without
using an if statement...

for f in var1_fn, var2_fn, var3_fn:
if f.split('.')[0] == 'var1':
var1 = call_some_function(f)
.
.
.
  etc

 Really I would like to remove the need for this if loop and I am sure
there is a simple way I am missing?

Many thanks

Martin

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


Re: 64-bit issues with dictionaries in Python 2.6

2009-07-29 Thread Martin v. Löwis
> Are there any known issues with dictionaries in Python 2.6 (not 2.6.2)
> when running on a 64-bit platform?

No, none.

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


Re: Very Strange Problem

2009-07-29 Thread Omer Khalid
Hi Dave,

Thanks for your reply. I actually didn't cut and paste my code as it was
dispersed in different places, i typed the logic behind my code in the email
(and obiviously made some typos, indentations is some thing else) but my
real code does not have these problems as my application runs fine with out
errors...

Except that the line where i want to update the value doesn't get updated
and no exception is thrown. What's surprising for me is that i am doing the
same thing in hundreds of places in my 3k+ line code but by some reason this
part doesn't work...

As far as the global variables are concerned, i am using them in other
places too and didn't see any problems.

I think some thing else is going on here as the statement above and below my
modified lines get executed.

Is there a way in Python to debug memory address or to see where in memory
this object is stored, and is there a lock on it or else?

Thanks,
Omer


**


On Wed, Jul 29, 2009 at 8:56 PM, Dave Angel  wrote:

> Omer Khalid wrote:
>
>> Hi,
>>
>> I am having a very strange problem with modifying a variable in a list in
>> my
>> program. Here is the code:
>>
>> # a list that contains dictionary objects
>> jobs = []
>>
>> index=5
>> for each in range(index):
>> jobs.append({'v':0})
>>
>> some_function(index):
>>   if jobs[index]['v'] == 0:
>>   # set it to 1
>>   jobs[index]['v'] = 1
>>   print "Set to 1"
>>  else:
>>   print "Already set to 1"
>>
>> loop():
>>index=0
>>for each in range(len(jobs)):
>> some_function(index)
>> index +=1
>>
>>
>> Apparently, the jobs[index]['v'] never get updated in the some_function
>> but
>> the print statement afterwards get printed...
>>
>> What's really surprising is that there are no errors or exceptions and my
>> my
>> program runs in a single thread...so i have been unable to explain this
>> behavior.
>>
>> Any insight would be much appreciated!
>>
>> Cheers
>> Omer
>>
>>
>>
> There are four things to fix before the program does anything much at all.
>  Two places you're missing the def, indentation is inconsistent, and you
> never actually call either of the functions.   The first three are syntax
> errors, so presumably your cut/paste in your computer is broken.
>
> Once I make those four corrections, I get the following output:
>
> Set to 1
> Set to 1
> Set to 1
> Set to 1
> Set to 1
>
> But you never said what you got, nor what you expected.  That's certainly
> what I'd expect.  And if you make a second call to loop() in your outer
> code, you get five copies of "Already set to 1"
>
> BTW, there are a number of things that could be done better.  The main one
> I'll point out is that you shouldn't re-use a global variable 'index' as a
> local with different meaning.  As someone else pointed out, since the global
> is a constant, making it all uppercase is the convention.
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple splash screen?

2009-07-29 Thread NighterNet
On Jul 29, 11:16 am, "Martin P. Hellwig" 
wrote:
> NighterNet wrote:
> > I am trying to make a simple splash screen from python 3.1.Not sure
> > where to start looking for it. Can any one help?
>
> Sure, almost the same as with Python 2 :-)
> But to be a bit more specific:
> 
> """Only works if you got Python 3 installed with tkinter"""
> import tkinter
>
> IMAGE_PATH = "/path/to/image"
>
> class Splash(object):
>      "Splash Screen GUI"
>      def __init__(self, root):
>          self.root = root
>          # No window borders and decoration
>          self.root.overrideredirect(True)
>          # Get the size of the screen
>          screen_width = self.root.winfo_screenwidth()
>          screen_height = self.root.winfo_screenheight()
>          # Full screen
>          geometry_text = "%dx%d+0+0" % (screen_width, screen_height)
>          self.root.geometry(geometry_text)
>          # Display an image
>          self.label = tkinter.Label(self.root)
>          # Only GIF and PGM/PPM supported, for more information see:
>          self.label._image = tkinter.PhotoImage(file=IMAGE_PATH)
>          #http://effbot.org/tkinterbook/photoimage.htm
>          self.label.configure(image = self.label._image)
>          self.label.pack()
>          # This will quit the screen after about 5 seconds
>          self.root.after(5000, self.root.quit)
>
> if __name__ == '__main__':
>      ROOT = tkinter.Tk()
>      APPL = Splash(ROOT)
>      ROOT.mainloop()
> 
>
> --
> MPHhttp://blog.dcuktec.com
> 'If consumed, best digested with added seasoning to own preference.'

Thanks it help. Sorry about that, I was just wander what kind of
answer and if there are other methods to learn it.

Is there a way to position image to the center screen?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very Strange Problem

2009-07-29 Thread Terry Reedy

Omer Khalid wrote:

Hi,

I am having a very strange problem with modifying a variable in a list 
in my program. Here is the code:


To me, this sentence clearly implies that the code that follows is the 
code that had the problem. Since the posted code cannot run, it clearly 
is not. People should test code to be posted before posting unless they 
clearly label it as 'untested'. Original posters, of course, should run 
the code first.


tjr

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


Re: Very Strange Problem

2009-07-29 Thread Dave Angel

Omer Khalid wrote:

Hi Dave,

Thanks for your reply. I actually didn't cut and paste my code as it was
dispersed in different places, i typed the logic behind my code in the email
(and obiviously made some typos, indentations is some thing else) but my
real code does not have these problems as my application runs fine with out
errors...

Except that the line where i want to update the value doesn't get updated
and no exception is thrown. What's surprising for me is that i am doing the
same thing in hundreds of places in my 3k+ line code but by some reason this
part doesn't work...

As far as the global variables are concerned, i am using them in other
places too and didn't see any problems.

I think some thing else is going on here as the statement above and below my
modified lines get executed.

Is there a way in Python to debug memory address or to see where in memory
this object is stored, and is there a lock on it or else?

Thanks,
Omer


**


On Wed, Jul 29, 2009 at 8:56 PM, Dave Angel  wrote:

  

Omer Khalid wrote:



Hi,

I am having a very strange problem with modifying a variable in a list in
my
program. Here is the code:

# a list that contains dictionary objects
jobs = []

index=5
for each in range(index):
jobs.append({'v':0})

some_function(index):
  if jobs[index]['v'] == 0:
  # set it to 1
  jobs[index]['v'] = 1
  print "Set to 1"
 else:
  print "Already set to 1"

loop():
   index=0
   for each in range(len(jobs)):
some_function(index)
index +=1


Apparently, the jobs[index]['v'] never get updated in the some_function
but
the print statement afterwards get printed...

What's really surprising is that there are no errors or exceptions and my
my
program runs in a single thread...so i have been unable to explain this
behavior.

Any insight would be much appreciated!

Cheers
Omer



  

There are four things to fix before the program does anything much at all.
 Two places you're missing the def, indentation is inconsistent, and you
never actually call either of the functions.   The first three are syntax
errors, so presumably your cut/paste in your computer is broken.

Once I make those four corrections, I get the following output:

Set to 1
Set to 1
Set to 1
Set to 1
Set to 1

But you never said what you got, nor what you expected.  That's certainly
what I'd expect.  And if you make a second call to loop() in your outer
code, you get five copies of "Already set to 1"

BTW, there are a number of things that could be done better.  The main one
I'll point out is that you shouldn't re-use a global variable 'index' as a
local with different meaning.  As someone else pointed out, since the global
is a constant, making it all uppercase is the convention.

DaveA


(You top-posted, so your ,message is out of sequence.  More and more 
people are doing that in this list.)



  ...Except that the line where i want to update the value doesn't 
get updated...


And what makes you think that?  You never answered my question.  What did you 
expect for output, and what did you get?  I got exactly what I expected, when I 
ran it.

 ...  Is there a way in Python to debug memory address or
  to see where in memory this object is stored, and
  is there a lock on it or else?

If there really were a bug in the language, you might need such a tool.  
I use Komodo IDE as a debugger, but there was no need in this case.  
Adding a few print statements might clear up your confusion, but since 
you haven't spelled out what it is, I can't suggest where.  How about if 
you just add aprint jobsat the beginning of some_function() ?  
Then you could see things getting updated perfectly.


DaveA

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


Re: Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread Jan Kaliszewski

29-07-2009 Benjamin Kaplan  wrote:


On Wed, Jul 29, 2009 at 1:59 PM, dandi kain  wrote:

[snip

What is the functionality of __ or _ , leading or trailing an object ,
class ot function ? Is it just a naming convention to note special
functions and objects , or it really mean someting to Python ?


It's just a convention for the most part. A single leading underscore
is used for "private" attributes. Two leading underscores will affect
the code-


Single leading underscore in some situations also affect the code...

See:

*  
http://docs.python.org/reference/lexical_analysis.html#reserved-classes-of-identifiers


* http://docs.python.org/reference/datamodel.html#object.__del__
  (in the the red "Warning" frame)

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread Terry Reedy

Benjamin Kaplan wrote:

On Wed, Jul 29, 2009 at 1:59 PM, dandi kain  wrote:

Hello everybody,
I have just started learning Python.I heard its simple so I pick a
presentation [1] and tried to work on it.But when it comes to
underscores leading and trailing an object I dont understand any.I
look through the python manual also but that was not helping .I
searched some forums and I still dont have a clear picture.

What is the functionality of __ or _ , leading or trailing an object ,
class ot function ? Is it just a naming convention to note special
functions and objects , or it really mean someting to Python ?


It's just a convention for the most part. A single leading underscore
is used for "private" attributes. Two leading underscores will affect
the code- it mangles the variable name so that you don't have to worry
about the value being overwritten by a subclass. For instance
"""
class Foo(object) :
   def __init__(self) :
   self.__bar = ''

foo = Foo()
""
will store the attribute as foo._Foo__bar.

Also, the "magic methods"- the ones that are used for operations and
built-in stuff, all have two leading and two trailing underscores.
These are things like __add__ (+), __eq__ (=), __cmp__ (old way for
comparisons), __len__ (len), __str__ (str), and so on.


For this last, see
http://docs.python.org/dev/py3k/reference/datamodel.html#special-method-names

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


How to "gunzip-iterate" over a file?

2009-07-29 Thread kj



I need to iterate over the lines of *very* large (>1 GB) gzipped
files.  I would like to do this without having to read the full
compressed contents into memory so that I can apply zlib.decompress
to these contents.  I also would like to avoid having to gunzip
the file (i.e. creating an uncompressed version of the file in the
filesystem) prior to iterating over it.

Basically I'm looking for something that will give me the same
functionality as Perl's gzip IO layer, which looks like this (from
the documentation):

 use PerlIO::gzip;
 open FOO, "<:gzip", "file.gz" or die $!;
 print while ; # And it will be uncompressed...

What's the best way to achieve the same functionality in Python?

TIA!

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


Re: How to "gunzip-iterate" over a file?

2009-07-29 Thread Robert Kern

On 2009-07-29 15:05, kj wrote:



I need to iterate over the lines of *very* large (>1 GB) gzipped
files.  I would like to do this without having to read the full
compressed contents into memory so that I can apply zlib.decompress
to these contents.  I also would like to avoid having to gunzip
the file (i.e. creating an uncompressed version of the file in the
filesystem) prior to iterating over it.

Basically I'm looking for something that will give me the same
functionality as Perl's gzip IO layer, which looks like this (from
the documentation):

  use PerlIO::gzip;
  open FOO, "<:gzip", "file.gz" or die $!;
  print while; # And it will be uncompressed...

What's the best way to achieve the same functionality in Python?


http://docs.python.org/library/gzip

import gzip

f = gzip.open('filename.gz')
for line in f:
print line
f.close()

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


Differences Between Arrays and Matrices in Numpy

2009-07-29 Thread Nanime Puloski
What are some differences between arrays and matrices using the Numpy
library? When would I want to use arrays instead of matrices and vice
versa?
-- 
http://mail.python.org/mailman/listinfo/python-list


Does python have the capability for driver development ?

2009-07-29 Thread MalC0de
hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .

thanks

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


delayed sys.exit?

2009-07-29 Thread Dr. Phillip M. Feldman

In the attached  http://www.nabble.com/file/p24726902/test.py test.py code,
it appears that additional statements execute after the call to sys.exit(0). 
I'll be grateful if anyone can shed light on why this is happening.  Below
is a copy of some sample I/O.  Note that in the last case I get additional
output after what should be the final error message.

In [126]: run test
Input a string: 1,2
[1, 2]

In [127]: run test
Input a string: 1-3
[1, 2, 3]

In [128]: run test
Input a string: 1,4,5-12
[1, 4, 5, 6, 7, 8, 9, 10, 11, 12]

In [129]: run test
Input a string: 0
ERROR: 0 is invalid; run numbers must be positive.
ERROR: '0' is not a valid run number.


-- 
View this message in context: 
http://www.nabble.com/delayed-sys.exit--tp24726902p24726902.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: escaping characters in filenames

2009-07-29 Thread J Kenneth King
Nobody  writes:

> On Wed, 29 Jul 2009 09:29:55 -0400, J Kenneth King wrote:
>
>> I wrote a script to process some files using another program.  One thing
>> I noticed was that both os.listdir() and os.path.walk() will return
>> unescaped file names (ie: "My File With Spaces & Stuff" instead of "My\
>> File\ With\ Spaces\ \&\ Stuff").  I haven't had much success finding a
>> module or recipe that escapes file names and was wondering if anyone
>> could point me in the right direction.
>> 
>> As an aside, the script is using subprocess.call() with the "shell=True"
>> parameter.  There isn't really a reason for doing it this way (was just
>> the fastest way to write it and get a prototype working).  I was
>> wondering if Popen objects were sensitive to unescaped names like the
>> shell.  I intend to refactor the function to use Popen objects at some
>> point and thought perhaps escaping file names may not be entirely
>> necessary.
>
> Note that subprocess.call() is nothing more than:
>
>   def call(*popenargs, **kwargs):
>   return Popen(*popenargs, **kwargs).wait()
>
> plus a docstring. It accepts exactly the same arguments as Popen(), with
> the same semantics.
>
> If you want to run a command given a program and arguments, you
> should pass the command and arguments as a list, rather than trying to
> construct a string.
>
> On Windows the value of shell= is unrelated to whether the command is
> a list or a string; a list is always converted to string using the
> list2cmdline() function. Using shell=True simply prepends "cmd.exe /c " to
> the string (this allows you to omit the .exe/.bat/etc extension for
> extensions which are in %PATHEXT%).
>
> On Unix, a string is first converted to a single-element list, so if you
> use a string with shell=False, it will be treated as the name of an
> executable to be run without arguments, even if contains spaces, shell
> metacharacters etc.
>
> The most portable approach seems to be to always pass the command as a
> list, and to set shell=True on Windows and shell=False on Unix.
>
> The only reason to pass a command as a string is if you're getting a
> string from the user and you want it to be interpreted using the
> platform's standard shell (i.e. cmd.exe or /bin/sh). If you want it to be
> interpreted the same way regardless of platform, parse it into a
> list using shlex.split().

I understand; I think I was headed towards subprocess.Popen() either
way.  It seems to handle the problem I posted about.  And I got to learn
a little something on the way.  Thanks!

Only now there's a new problem in that the output of the program is
different if I run it from Popen than if I run it from the command line.
The program in question is 'pdftotext'.  More investigation to ensue.

Thanks again for the helpful post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Differences Between Arrays and Matrices in Numpy

2009-07-29 Thread Robert Kern

On 2009-07-29 15:23, Nanime Puloski wrote:

What are some differences between arrays and matrices using the Numpy
library? When would I want to use arrays instead of matrices and vice
versa?


You will want to ask numpy questions on the numpy mailing list:

  http://www.scipy.org/Mailing_Lists

An overview of how the matrix subclass differs from ndarray, see the 
documentation:

  http://docs.scipy.org/doc/numpy/reference/arrays.classes.html#matrix-objects

Basically, I suggest that you just use regular arrays always. There is a 
syntactical convenience to matrix objects, but it does cause incompatibilities 
with the majority of code that is written for regular arrays. The convenience is 
usually not worth the cost.


--
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: delayed sys.exit?

2009-07-29 Thread Stephen Hansen
>
> In the attached  http://www.nabble.com/file/p24726902/test.py test.py
> code,
> it appears that additional statements execute after the call to
> sys.exit(0).
> I'll be grateful if anyone can shed light on why this is happening.  Below
> is a copy of some sample I/O.  Note that in the last case I get additional
> output after what should be the final error message.
>

A bare "except:" catches ALL exceptions; including SystemExit which is
generated by
sys.exit. And KeyboardInterrupt, too. That's why its basically a bad
idea to use bare excepts unless you really, really, really need to.
Try 'except Exception' instead. SystemExit and such do not inherit
from Exception.

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


Re: delayed sys.exit?

2009-07-29 Thread MRAB

Dr. Phillip M. Feldman wrote:

In the attached  http://www.nabble.com/file/p24726902/test.py test.py code,
it appears that additional statements execute after the call to sys.exit(0). 
I'll be grateful if anyone can shed light on why this is happening.  Below

is a copy of some sample I/O.  Note that in the last case I get additional
output after what should be the final error message.

In [126]: run test
Input a string: 1,2
[1, 2]

In [127]: run test
Input a string: 1-3
[1, 2, 3]

In [128]: run test
Input a string: 1,4,5-12
[1, 4, 5, 6, 7, 8, 9, 10, 11, 12]

In [129]: run test
Input a string: 0
ERROR: 0 is invalid; run numbers must be positive.
ERROR: '0' is not a valid run number.


sys.exit raises an SystemExit exception, which then gets caught by the
bare 'except' of the enclosing try...except... statement.

A lot of things can raise an exception, which is why bare 'except's are
a bad idea; catch only those you expect.
--
http://mail.python.org/mailman/listinfo/python-list


Re: delayed sys.exit?

2009-07-29 Thread Peter Otten
Dr. Phillip M. Feldman wrote:

> In the attached  http://www.nabble.com/file/p24726902/test.py test.py
> code, it appears that additional statements execute after the call to
> sys.exit(0).

>try:
>   # If the conversion to int fails, nothing is appended to the list:
>   Runs.append(int(strs[i]))
>   if Runs[-1] <= 0:
>  print 'ERROR: ' + str(Runs[-i]) + \
>' is invalid; run numbers must be positive.'
>  sys.exit(0)
>except:

sys.exit() works by raising a SystemExit exception which is caught by the 
bare except.

http://docs.python.org/library/sys.html#sys.exit
http://docs.python.org/library/exceptions.html#exceptions.SystemExit

As a general rule try to be as specific as possible when catching 
exceptions.

Peter

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


Re: set variable to looping index?

2009-07-29 Thread Peter Otten
Martin wrote:

> I am trying to set the return value from a function to a name which I
> grab from the for loop. I can't work out how I can do this without
> using an if statement...
> 
> for f in var1_fn, var2_fn, var3_fn:
> if f.split('.')[0] == 'var1':
> var1 = call_some_function(f)
> .
> .
> .
>   etc
> 
>  Really I would like to remove the need for this if loop and I am sure
> there is a simple way I am missing?

Use dictionaries:

functions = {"var1": some_function, "var2": some_other_function, ...} 
return_values = {}

for arg in var1_fn, var2_fn, var3_fn:
key = arg.split(".")[0]
return_values[key] = functions[key](arg)

Peter

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


Re: Does python have the capability for driver development ?

2009-07-29 Thread Diez B. Roggisch

MalC0de schrieb:

hello there, I've a question :
I want to know does python have any capability for using Ring0 and
kernel functions for driver and device development stuff .
if there's such a feature it is very good, and if there something for
this kind that you know please refer me to some reference and show me
some snippet .


No, it can't do such things. At least it isn't embedded in the kernel - 
in theory that might be possible, but given the timing-constraints and 
concurrency-requirements, it's not really feasible.


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


Re: simple splash screen?

2009-07-29 Thread Martin P. Hellwig

NighterNet wrote:


Thanks it help. Sorry about that, I was just wander what kind of
answer and if there are other methods to learn it.

Is there a way to position image to the center screen?


Yes there is, just start reading from here:
http://effbot.org/tkinterbook/

Though because Python 3 has done some module reorganisation/renaming, 
Tkinter is now called tkinter.


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to embed the python interpreter into web App (Mehndi, Sibtey)

2009-07-29 Thread André
On Jul 29, 1:11 pm, Ryniek90  wrote:
> > Hi All
>
> > I am trying to embed the python interpreter in to a web app but could
> > not get the way, any one can suggest me how to do this.
>
> > Thanks,
>
> > Sibtey Mehdi
>
> > This e-mail (and any attachments), is confidential and may be privileged. 
> > It may be read, copied and used only
> > by intended recipients. Unauthorized access to this e-mail (or attachments) 
> > and disclosure or copying of its
> > contents or any action taken in reliance on it is unlawful. Unintended 
> > recipients must notify the sender immediately
> > by e-mail/phone & delete it from their system without making any copies or 
> > disclosing it to a third person.
>
> Here's example:http://try-python.mired.org/
>
> Contact with author of that website/webapp.
>
> Good luck.

Or you can look at the code for Crunchy: http://code.google.com/p/crunchy

Note however that this will result in something that is not secure...
To quote the try-python site:

"My ISP (idiom.com) provides a sandbox inside a FreeBSD Jail..."

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


IDLE Config Problems

2009-07-29 Thread Russ Davis
I am just getting started with Python and have installed v. 2.5.4  Idle version 
1.2.4  I can't seem to get the idle to display text.  It seems as if the 
install went fine.  I start up the idle and the screen is blank.  No text.  It 
seems as if I can type on the screen but I just can't see the characters.   I 
go to the config menu and it bombs and brings up the Visual Studio debugger.  
The computer that I am trying to install it on is a windows xp laptop serv pack 
2.   I have a workstation here that I am using also with the same os and the 
idle works fine.  Any hints as to what might be interfering with the idle 
config.

Thanks

Russ

Russell Davis PP, AICP, GISP
GIS Administrator
State of New Jersey Pinelands Commission
Office of Land Use and Technology
GIS Laboratory
Po Box 7
New Lisbon, NJ 08064
Phone 609-894-7300
Fax 609-894-7330
russ.da...@njpines.state.nj.us

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


Re: set variable to looping index?

2009-07-29 Thread Dave Angel

Martin wrote:

Hi,

I am trying to set the return value from a function to a name which I
grab from the for loop. I can't work out how I can do this without
using an if statement...

for f in var1_fn, var2_fn, var3_fn:
if f.split('.')[0] == 'var1':
var1 = call_some_function(f)
.
.
.
  etc

 Really I would like to remove the need for this if loop and I am sure
there is a simple way I am missing?

Many thanks

Martin

  


Is this a real problem, or is it a "programming puzzle"?   If it's the 
latter, maybe someone else can help.


But if it's a real problem, give us some context, and maybe we can 
figure out how to help.


If I took this fragment at face value, I'd simply replace it by:

var1 = call_some_function(var1_fn)
var2 = call_some_function(var2_fn)
var3 = call_some_function(var3_fn)


Is this fragment part of a function definition, or is it top-level?  Are 
there really exactly three var*_fn objects, or might there be an 
arbitrary number of them?   Do you want to tell us the types of these 
three objects?  Is there content really tied directly to their name?  
Did they get their values from literals, or were they computed at some 
other point?



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


Re: set variable to looping index?

2009-07-29 Thread Rhodri James

On Wed, 29 Jul 2009 19:56:28 +0100, Martin  wrote:


Hi,

I am trying to set the return value from a function to a name which I
grab from the for loop. I can't work out how I can do this without
using an if statement...

for f in var1_fn, var2_fn, var3_fn:
if f.split('.')[0] == 'var1':
var1 = call_some_function(f)
.
.
.
  etc

 Really I would like to remove the need for this if loop and I am sure
there is a simple way I am missing?


It's a little hard to tell what you actually want from your description,
but it looks like you're fighting the language unnecessarily here.  If
you have a sequence of functions that you want a sequence of results
out of, you should be thinking in terms of a sequence type.  A list,
in other words.

results = []
for f in fn1, fn2, fn3:
results.append(f())


--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Differences Between Arrays and Matrices in Numpy

2009-07-29 Thread Nobody
On Wed, 29 Jul 2009 16:23:33 -0400, Nanime Puloski wrote:

> What are some differences between arrays and matrices using the Numpy
> library?

Matrices are always two-dimensional, as are slices of them. Matrices
override mulitplication and exponentiation to use matrix multiplication
rather than element-wise multiplication.

> When would I want to use arrays instead of matrices and vice
> versa?

Use a matrix if you want a matrix, i.e. a linear transformation.
Otherwise, use an array.

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


Re: set variable to looping index?

2009-07-29 Thread Martin
On Jul 29, 11:02 pm, "Rhodri James" 
wrote:
> On Wed, 29 Jul 2009 19:56:28 +0100, Martin  wrote:
> > Hi,
>
> > I am trying to set the return value from a function to a name which I
> > grab from the for loop. I can't work out how I can do this without
> > using an if statement...
>
> > for f in var1_fn, var2_fn, var3_fn:
> >     if f.split('.')[0] == 'var1':
> >         var1 = call_some_function(f)
> >    .
> >         .
> >         .
> >       etc
>
> >  Really I would like to remove the need for this if loop and I am sure
> > there is a simple way I am missing?
>
> It's a little hard to tell what you actually want from your description,
> but it looks like you're fighting the language unnecessarily here.  If
> you have a sequence of functions that you want a sequence of results
> out of, you should be thinking in terms of a sequence type.  A list,
> in other words.
>
> results = []
> for f in fn1, fn2, fn3:
>      results.append(f())
>
> --
> Rhodri James *-* Wildebeest Herder to the Masses

Hi all,

Thanks and apologises I wasn't trying to be cryptic, like all things
when I wrote it I thought it was quite transparent.

All I was trying to do was call a function and return the result to an
a variable. I could admittedly of just done...

var1 = some_function(var1_fn)
var2 = some_function(var2_fn)
var3 = some_function(var3_fn)

where var1_fn, var2_fn, var3_fn are just filenames, e.g. var1_fn =
'x.txt'. But I figured I would try and make it slightly more generic
whilst I was at it, hence my attempt to use the filenames to create
the variable names (hence the loop). I will as suggested try the
dictionary option. I appreciate all the suggestions.

Thanks

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


Re: Does python have the capability for driver development ?

2009-07-29 Thread Nick Craig-Wood
Diez B. Roggisch  wrote:
>  MalC0de schrieb:
> > hello there, I've a question :
> > I want to know does python have any capability for using Ring0 and
> > kernel functions for driver and device development stuff .
> > if there's such a feature it is very good, and if there something for
> > this kind that you know please refer me to some reference and show me
> > some snippet .
> 
>  No, it can't do such things. At least it isn't embedded in the kernel - 
>  in theory that might be possible, but given the timing-constraints and 
>  concurrency-requirements, it's not really feasible.

You can write FUSE (file systems in userspace) drivers in python I believe.
Not the same as running in ring0 but in most senses a kernel driver...

-- 
Nick Craig-Wood  -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: set variable to looping index?

2009-07-29 Thread Jan Kaliszewski

30-07-2009  wrote:


All I was trying to do was call a function and return the result to an
a variable. I could admittedly of just done...

var1 = some_function(var1_fn)
var2 = some_function(var2_fn)
var3 = some_function(var3_fn)

where var1_fn, var2_fn, var3_fn are just filenames, e.g. var1_fn =
'x.txt'. But I figured I would try and make it slightly more generic
whilst I was at it, hence my attempt to use the filenames to create
the variable names (hence the loop).


Hi,

Then you could also consider using simply lists:

filenames = p'foo', 'bar', baz']
results = []
for name in filenames:
results.append(some_function(name))

If filenames were generated according to a particular pattern, you can
mimic that pattern and generate filenames list using
list-comprehension, e.g.:

filenames = ['file{nr}.txt'.format(nr=nr) for nr in range(13)]

Chreers,

*j

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >