Re: Convert to binary and convert back to strings

2007-02-22 Thread Jussi Salmela
Harlin Seritt kirjoitti:
> Hi...
> 
> I would like to take a string like 'supercalifragilisticexpialidocius'
> and write it to a file in binary forms -- this way a user cannot read
> the string in case they were try to open in something like ascii text
> editor. I'd also like to be able to read the binary formed data back
> into string format so that it shows the original value. Is there any
> way to do this in Python?
> 
> Thanks!
> 
> Harlin
> 

Here's my suggestion using compression. Seems to work, but a word of 
warning: I've never used the codecs explicitly before!

#==
# -*- coding: cp1252 -*-
import codecs

s = 'This is so secret that it must be hidden åäö€'
print s
f = codecs.open('secret.txt', 'wb', 'zlib_codec')
f.write(s)
f.close()

f = codecs.open('secret.txt', 'rb', 'zlib_codec')
s2 = f.read()
f.close()
print s2
if s == s2: print 'OK'
else: print '!"#¤%%'
#
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f---ing typechecking

2007-02-22 Thread greg
Hendrik van Rooyen wrote:

> I don't think its reasonable - its just an accident of implementation.

There's nothing accidental about the implementation of
the in-place operators. It was designed the way it is
so that it would work in a reasonable way with both
mutable and immutable objects.

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


Re: Convert to binary and convert back to strings

2007-02-22 Thread Paul Rubin
Grant Edwards <[EMAIL PROTECTED]> writes:
> > print base64.decodestring(open('sambleb.conf', 'r').read())
> It'll only remain obfuscated for about 30 seconds after even a
> mildly curious user looks at the file.

You could use the mult127 function, self-inverting like its better
known but more easily recognized rot13 relative:

def mult127(text):
return ''.join(map(chr, ((127*ord(c)) % 256 for c in text)))
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding a tuple in a tuple

2007-02-22 Thread bg_ie
Hi,

Lists say I have the following tuple -

t1 = ("ONE","THREE","SIX")

and then the following tuples -

t2 = ("ONE","TWO","THREE")

t3 = ("TWO","FOUR","FIVE","SIX")

t4 = ("TWO",)

t5 = ("TWO","FIVE")

What I want to do is return true if any member of tuple t1 is found in
the remaining tuples.

Therefore -

2) ("ONE","TWO","THREE") : TRUE

3) ("TWO","FOUR","FIVE","SIX") : TRUE

4) ("TWO",) FALSE

5) ("TWO","FIVE")

How do I do this?

Cheers,

Barry.

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


Re: outlook bar like widget

2007-02-22 Thread Mohammad Tayseer
I implemented this module using Tkinter

---
from Tkinter import *

class OutlookBar(Frame):
def __init__(self, *args, **options):
Frame.__init__(self, *args, **options)
self.panes = {}

def add_pane(self, name, pane):
self.panes[name] = pane
pane.pack(side=TOP, fill=X)

def get_frame(self, name):
return self.panes[name]

class OutlookPane(Frame):
def __init__(self, *args, **options):
if options.get('text'):
text = options['text']
del options['text']

Frame.__init__(self, *args, **options)
self.btn = Button(self, text=text, command=self.toggle_collapse)
self.btn.pack(side=TOP, fill=X)
self.child_frame = Frame(self)
self.child_frame.pack(side=TOP, fill=X)
if options.get('collapsed'):
self.collapsed = True
del options['collapsed']
else:
self.collapsed = False
self.child_frame.pack(side=TOP, fill=X)

def frame(self):
return self.child_frame

def toggle_collapse(self):
if self.collapsed:
self.child_frame.pack(side=TOP) # show
else:
self.child_frame.pack_forget()
self.collapsed = not self.collapsed

def add_widget(self, widget):
widget.pack(side=TOP)
if __name__ == '__main__':
#import bwidget as bw
root = Tk()
root.title('Outlook Bar Demo')
bar = OutlookBar(root)
bar.pack(expand=1, fill=BOTH)
bar.add_pane('pane1', OutlookPane(bar, text='Hello'))
pane1 = bar.get_frame('pane1')
pane1.add_widget(Button(pane1.frame(), text='Button 1'))
pane1.add_widget(Button(pane1.frame(), text='Button 2'))
pane1.add_widget(Button(pane1.frame(), text='Button 3'))

bar.add_pane('pane2', OutlookPane(bar, text='Zankalon'))
pane2 = bar.get_frame('pane2')
pane2.add_widget(Button(pane2.frame(), text='Button 1'))
pane2.add_widget(Button(pane2.frame(), text='Button 2'))
pane2.add_widget(Button(pane2.frame(), text='Button 3'))

mainloop()


-

Jaime Casanova <[EMAIL PROTECTED]> wrote: Hi,

i'm trying to make an outlook bar like widget basically buttons that
when pressed extends to lists...

any idea where to start?

-- 
regards,
Jaime Casanova



 
-
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: outlook bar like widget

2007-02-22 Thread Mohammad Tayseer
This is a module that does what you want using Tkinter


from Tkinter import *

class OutlookBar(Frame):
def __init__(self, *args, **options):
Frame.__init__(self, *args, **options)
self.panes = {}

def add_pane(self, name, pane):
self.panes[name] = pane
pane.pack(side=TOP, fill=X)

def get_frame(self, name):
return self.panes[name]

class OutlookPane(Frame):
def __init__(self, *args, **options):
if options.get('text'):
text = options['text']
del options['text']

Frame.__init__(self, *args, **options)
self.btn = Button(self, text=text, command=self.toggle_collapse)
self.btn.pack(side=TOP, fill=X)
self.child_frame = Frame(self)
self.child_frame.pack(side=TOP, fill=X)
if options.get('collapsed'):
self.collapsed = True
del options['collapsed']
else:
self.collapsed = False
self.child_frame.pack(side=TOP, fill=X)

def frame(self):
return self.child_frame

def toggle_collapse(self):
if self.collapsed:
self.child_frame.pack(side=TOP) # show
else:
self.child_frame.pack_forget()
self.collapsed = not self.collapsed

def add_widget(self, widget):
widget.pack(side=TOP)
if __name__ == '__main__':
root = Tk()
root.title('Outlook Bar Demo')
bar = OutlookBar(root)
bar.pack(expand=1, fill=BOTH)
bar.add_pane('pane1', OutlookPane(bar, text='Hello'))
pane1 = bar.get_frame('pane1')
pane1.add_widget(Button(pane1.frame(), text='Button 1'))
pane1.add_widget(Button(pane1.frame(), text='Button 2'))
pane1.add_widget(Button(pane1.frame(), text='Button 3'))

bar.add_pane('pane2', OutlookPane(bar, text='Zankalon'))
pane2 = bar.get_frame('pane2')
pane2.add_widget(Button(pane2.frame(), text='Button 1'))
pane2.add_widget(Button(pane2.frame(), text='Button 2'))
pane2.add_widget(Button(pane2.frame(), text='Button 3'))

mainloop()



 
-
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Finding a tuple in a tuple

2007-02-22 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Lists say I have the following tuple -
> t1 = ("ONE","THREE","SIX")
> t2 = ("ONE","TWO","THREE")
> t3 = ("TWO","FOUR","FIVE","SIX")
> t4 = ("TWO",)
> t5 = ("TWO","FIVE")
> 
> What I want to do is return true if any member of tuple t1 is found in
> the remaining tuples.

Convert them into sets and use the set intersection (&) operator,
then convert to bool to represent whether the intersection is empty.

print bool(set(t1) & set(t2))
print bool(set(t1) & set(t3))
print bool(set(t1) & set(t4))
print bool(set(t1) & set(t5))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert to binary and convert back to strings

2007-02-22 Thread Steven D'Aprano
On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote:

>> WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM.  It is just a
>> nuisance for someone that really wants to decrypt the string. But
>> it might work for your application.
>>
>> -Larry
> 
> Thanks Larry! I was looking for something more beautiful but what the
> hey, it works!


Is this beautiful enough?


>>> s = "Python"
>>> u = unicode(s, "ascii")
>>> u
u'Python'
>>> u.encode('rot13')
'Clguba'


For extra security, you can encode the string with rot13 twice.



-- 
Steven.

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


Re: Finding a tuple in a tuple

2007-02-22 Thread Paul McGuire
On Feb 22, 3:05 am, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > Lists say I have the following tuple -
> > t1 = ("ONE","THREE","SIX")
> > t2 = ("ONE","TWO","THREE")
> > t3 = ("TWO","FOUR","FIVE","SIX")
> > t4 = ("TWO",)
> > t5 = ("TWO","FIVE")
>
> > What I want to do is return true if any member of tuple t1 is found in
> > the remaining tuples.
>
> Convert them into sets and use the set intersection (&) operator,
> then convert to bool to represent whether the intersection is empty.
>
> print bool(set(t1) & set(t2))
> print bool(set(t1) & set(t3))
> print bool(set(t1) & set(t4))
> print bool(set(t1) & set(t5))

A step further: use union to make a superset of t2-tN, then use & on
this superset.

setlist = [t2,t3,t4,t5]
superset = reduce(set.union, map(set,setlist) )
print bool(t1 & superset)


-- Paul

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


Re: jython import search path

2007-02-22 Thread Diez B. Roggisch
Russ wrote:

> On Feb 21, 4:15 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
>> Russ wrote:
>> > I have a Python program that I want to run in Jython so I can get Java
>> > bytecode output. The program runs fine in Python, but when I change
>> > the first line of the main program to make it run in Jython, it fails
>> > to find some of the imported modules. These are just plain Python
>> > imports of code I wrote myself in another directory.
>>
>> > Apparently Jython does not use the PYTHONPATH environment variable. I
>> > created an environment variable called JYTHONPATH just to see what
>> > would happen, but it didn't work either. How am I supposed to tell
>> > Jython where to search for imported modules? Thanks.
>>
>> Maybe Jython expert has the perfect answer but til then.
>>
>> Did you try:
>>
>> sys.path.append('path to search')
>>
>> Usually this works if nothing else does.
>>
>> -Larry
> 
> Thanks. That's a good workaround, but I would like to know the
> "correct" way to do it too if anyone out there knows.

That is pretty much an accepted strategy. Another one is to alter the
registry file, which has a property python.path. It might even be possible
to use

java -Dpython.path=

to accomplish that - but I'm to lazy to toy around now.

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


Re: Pep 3105: the end of print?

2007-02-22 Thread Steven D'Aprano
On Thu, 22 Feb 2007 16:29:17 +1100, Peter Mayne wrote:

> Why use print in the interactive interpreter? Just type the expression.

Many reasons. Here are four:

>>> print None
None
>>> None
>>> print 0.1
0.1
>>> 0.1
0.10001
>>> print 'null = \0'
null =
>>> 'null = \0'
'null = \x00'
>>> print 1, 2, 3
1 2 3
>>> 1, 2, 3
(1, 2, 3)


I'm sure you can find your own examples.


-- 
Steven.

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


Re: Finding a tuple in a tuple

2007-02-22 Thread Paul Rubin
"Paul McGuire" <[EMAIL PROTECTED]> writes:
> A step further: use union to make a superset of t2-tN, then use & on
> this superset.
> 
> setlist = [t2,t3,t4,t5]
> superset = reduce(set.union, map(set,setlist) )
> print bool(t1 & superset)

Well you do have to convert them to sets.  Also I thought each
intersection was wanted separately.  Otherwise if we're getting this
fancy, I guess I'd use (untested, uses new 2.5 "any" function):

  s1 = set(t1)
  print any((s1 & set(tn)) for tn in (t2,t3,t4,t5))

which avoids creating a potentially big intermediate set, and which
short-circuits (exits early) as soon as a match is found.
-- 
http://mail.python.org/mailman/listinfo/python-list


Local class variables? (mod_python problem)

2007-02-22 Thread Rory Campbell-Lange
We have a set of classes using static methods to retain reference
variables between operations. The problem is that the static variables
are not reset between operations when used through mod_python.

Although it is possible to reset the class variables between invocations
of the system, this has the potential of 'wiping out' these variables
when another user is using the system.

Is there a way of getting the equivalent of 'local class variables'? In
other words, a way of making 'print a' and 'print b' below provide the
same output?

Regards
Rory


class TryMe(object):
x = 0
y = 0

def __init__(self):
self.a = 0, self.b = 0

@staticmethod
def incrementer():
TryMe.x += 1, TryMe.y += 1

def addone (self):
TryMe.x += 1, TryMe.y += 1
self.a , += 1 self.b += 1

def __repr__(self):
return """
TryMe.x = %d TryMe.y = %d self.a  = %d self.b  = %d
""" % (TryMe.x, TryMe.y, self.a, self.b)

if __name__ == '__main__':

a = TryMe()
a.incrementer()
a.addone()

b = TryMe()
b.incrementer()
b.addone()

print 'a:', a
print 'b:', b


-- 
Rory Campbell-Lange 
<[EMAIL PROTECTED]>

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


Re: PLY for standard library

2007-02-22 Thread Jakub Stolarski
On 21 Lut, 21:27, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
> Other candidates besides 
> PLY:http://www.nedbatchelder.com/text/python-parsers.htmlhttp://wiki.python.org/moin/LanguageParsing
>
> I'm not sure this is a "one size fits all" problem space.
>
> Personally I find PLY's use of docstrings for grammar definition a bit
> too clever (as I'm sure others have their own personal likes and
> dislikes on any of these packages, even (gasp) pyparsing).
>

I tried some other packages too. PLY was the most suitable for me, but
there are many much more powerful tools. If there will be any other
parsing tool in standard library that's OK. But I think that python
needs some standard parsing tool.

--
Jakub Stolarski

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


is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?

2007-02-22 Thread openopt
I don't know to which forum should I post the message
I hope someone related to the Python kernel development will read &
consider the idea
I'm (a former? meanwhile not sure) MATLAB user & it's very annoing
typing each time for example
while i:
 print i
 ...
instead of
while i
print i
...
of course if all is written in a single line ':' I guess should not be
omited

Thank you for you suggestions.
Sorry my bad English.

WBR, Dmitrey

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


Re: is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?

2007-02-22 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> I don't know to which forum should I post the message
> I hope someone related to the Python kernel development will read &
> consider the idea
> I'm (a former? meanwhile not sure) MATLAB user & it's very annoing
> typing each time for example
> while i:
>  print i
>  ...
> instead of
> while i
> print i
> ...
> of course if all is written in a single line ':' I guess should not be
> omited

Won't happen. There have been plenty of discussions about this, and while
technically not necessary, the colon is usually considered "optically
pleasing". So - it will stay. 

See - one of a bazillion - discussions here:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/d3784563657ad18b/35581ad9698e28f5?lnk=st&q=python+colon+remove&rnum=1#35581ad9698e28f5


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


Re: Convert to binary and convert back to strings

2007-02-22 Thread Jussi Salmela
Steven D'Aprano kirjoitti:
> On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote:
> 
>>> WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM.  It is just a
>>> nuisance for someone that really wants to decrypt the string. But
>>> it might work for your application.
>>>
>>> -Larry
>> Thanks Larry! I was looking for something more beautiful but what the
>> hey, it works!
> 
> 
> Is this beautiful enough?
> 
> 
 s = "Python"
 u = unicode(s, "ascii")
 u
> u'Python'
 u.encode('rot13')
> 'Clguba'
> 
> 
> For extra security, you can encode the string with rot13 twice.
> 
> 
> 

Like this? ;)

 >>> s = "Python" ; u = unicode(s, "ascii") ;  u
u'Python'
 >>> u.encode('rot13')
'Clguba'
 >>> u.encode('rot13').encode('rot13')
'Python'


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


Re: Finding a tuple in a tuple

2007-02-22 Thread Philipp Pagel
[EMAIL PROTECTED] wrote:

> t1 = ("ONE","THREE","SIX")
> t2 = ("ONE","TWO","THREE")
> t3 = ("TWO","FOUR","FIVE","SIX")
> t4 = ("TWO",)
> t5 = ("TWO","FIVE")

> What I want to do is return true if any member of tuple t1 is found in
> the remaining tuples.

Another way to go instead of using sets, although probably less elegant:

>>> True in [x in t1 for x in t2]
True
>>> True in [x in t1 for x in t3]
True
>>> True in [x in t1 for x in t4]
False
>>> True in [x in t1 for x in t5]
False

cu
Philipp

-- 
Dr. Philipp Pagel  Tel. +49-8161-71 2131
Dept. of Genome Oriented BioinformaticsFax. +49-8161-71 2186
Technical University of Munich
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Informations about other computers in the network

2007-02-22 Thread ChuehBueb

Hi all.

I search a way to get informations, like NetBios-Name, os,..., about other
workstations in my network.

I searched google and the documentation, but i found nothing... can you help
me?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Finding a tuple in a tuple

2007-02-22 Thread Jussi Salmela
[EMAIL PROTECTED] kirjoitti:
> Hi,
> 
> Lists say I have the following tuple -
> 
> t1 = ("ONE","THREE","SIX")
> 
> and then the following tuples -
> 
> t2 = ("ONE","TWO","THREE")
> 
> t3 = ("TWO","FOUR","FIVE","SIX")
> 
> t4 = ("TWO",)
> 
> t5 = ("TWO","FIVE")
> 
> What I want to do is return true if any member of tuple t1 is found in
> the remaining tuples.
> 
> Therefore -
> 
> 2) ("ONE","TWO","THREE") : TRUE
> 
> 3) ("TWO","FOUR","FIVE","SIX") : TRUE
> 
> 4) ("TWO",) FALSE
> 
> 5) ("TWO","FIVE")
> 
> How do I do this?
> 
> Cheers,
> 
> Barry.
> 

Another variation of the theme:

#
for t in (t2, t3, t4, t5):
 for x in t1:
 if x in t:
 print True
 break
 else: print False
#


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


Re: outlook bar like widget

2007-02-22 Thread Jaime Casanova
On 2/21/07, Mohammad Tayseer <[EMAIL PROTECTED]> wrote:
> I implemented this module using Tkinter
>

wow! i will try this, thanks

-- 
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
   Richard Cook
-- 
http://mail.python.org/mailman/listinfo/python-list


plugin development best practices

2007-02-22 Thread Flavio
Hi,

Nowadays the addition of functionality to programs by means  of
plugins is very frequent.

I want to know the opinions of experienced Python developers about the
best practices when it comes to developing a plugin system for a
Python package.

Should plugins be modules in a separate package?
Should there be a registry  of available plugins? how would such a
registry  be implemented? etc.

thanks,

Flávio

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


Re: plugin development best practices

2007-02-22 Thread Jean-Paul Calderone
On 22 Feb 2007 04:53:02 -0800, Flavio <[EMAIL PROTECTED]> wrote:
>Hi,
>
>Nowadays the addition of functionality to programs by means  of
>plugins is very frequent.
>
>I want to know the opinions of experienced Python developers about the
>best practices when it comes to developing a plugin system for a
>Python package.
>
>Should plugins be modules in a separate package?
>Should there be a registry  of available plugins? how would such a
>registry  be implemented? etc.
>
>thanks,
>

Best practice may be to not develop a new plugin system.  There are quite a
few available already.  Most likely, at least one of them is suitable for your
application.

Here are a couple starting points:

http://twistedmatrix.com/projects/core/documentation/howto/plugin.html

http://peak.telecommunity.com/DevCenter/setuptools#dynamic-discovery-of-services-and-plugins

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


Re: plugin development best practices

2007-02-22 Thread Diez B. Roggisch
Flavio wrote:

> Hi,
> 
> Nowadays the addition of functionality to programs by means  of
> plugins is very frequent.
> 
> I want to know the opinions of experienced Python developers about the
> best practices when it comes to developing a plugin system for a
> Python package.
> 
> Should plugins be modules in a separate package?
> Should there be a registry  of available plugins? how would such a
> registry  be implemented? etc.

There have been a gazillion discussions about this on this newsgroup/mailing
list. Searching the archives will get you to them.

The dynamic nature of python makes a whole range of options available.
Depending on what you want to do (how are the plugins made available and so
on), one or the other might be preferable.

One relatively current development is the usage of setuptools "entry-points"
feature, which is precisely made for discovering installed plugins:

http://peak.telecommunity.com/DevCenter/setuptools#dynamic-discovery-of-services-and-plugins


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


Re: is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?

2007-02-22 Thread Flavio
On Feb 22, 9:49 am, [EMAIL PROTECTED] wrote:
> I don't know to which forum should I post the message
> I hope someone related to the Python kernel development will read &
> consider the idea
> I'm (a former? meanwhile not sure) MATLAB user & it's very annoing
> typing each time for example
> while i:
>  print i
>  ...
> instead of
> while i
> print i
> ...
> of course if all is written in a single line ':' I guess should not be
> omited
>
> Thank you for you suggestions.
> Sorry my bad English.
>
> WBR, Dmitrey

Think on the bright side:

you have to type ":" at the beginning of loop and conditional blocks,
but you don't have to type "end"  at the end... you are still saving
two strokes...
;-))

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


Re: is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?

2007-02-22 Thread justme
On 22 Feb, 11:49, [EMAIL PROTECTED] wrote:
> I don't know to which forum should I post the message
> I hope someone related to the Python kernel development will read &
> consider the idea
> I'm (a former? meanwhile not sure) MATLAB user & it's very annoing
> typing each time for example
> while i:
>  print i
>  ...
> instead of
> while i
> print i
> ...
> of course if all is written in a single line ':' I guess should not be
> omited
>
> Thank you for you suggestions.
> Sorry my bad English.
>
> WBR, Dmitrey

Hi

Just a thought...
I've also just made the jump from Matlab to Python (or am straddling
the two at the moment!) and I find the ':' really useful for
delimiting blocks of code. Took a while to get used to it but I reckon
it helps me explain my code to non-programmers as they can see the
blocks I use.

Al

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


Re: Regex Speed

2007-02-22 Thread Szabolcs Nagy
> Well, just as an idea, there is a portable C library for this at
> http://laurikari.net/tre/ released under LGPL.  If one is willing to
> give up PCRE extensions for speed, it might be worth the work to
> wrap this library using SWIG.

actually there is a python binding in the tre source with an example
python script so it is already done.

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


Re: network simulator in Python ?

2007-02-22 Thread peter rabinovitch
Have a look at simpy.

Although it doesn't do the protocols you mention, it is a very good 
(imho)simulation toolkit in which it would be relatively easy to build 
whatever protocols you need.

I am using it for a traffic management simulation project, and have found it 
very easy to get going and be productive, and my one technical question to 
the simpy mail list was answered with three good suggestions in an hour.

The only drawback may be speed.



"DanielJohnson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I was wondering if anyblody can suggest me a network simulator written
> in python in which I can add on my own code and extend its
> functionality.
>
> I am looking for a simulator which will simualte TCP, UDP, RTP and
> most networking protocol. The learning curve for ns2 and other
> simulator is too high for me at this time and thats why I am
> considering Python for it.
>
> Every help will be appreciated.
>
> Thanks
> 


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


Re: plugin development best practices

2007-02-22 Thread Flavio
On Feb 22, 11:00 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Flavio wrote:
> > Hi,
>
> > Nowadays the addition of functionality to programs by means  of
> > plugins is very frequent.
>
> > I want to know the opinions of experienced Python developers about the
> > best practices when it comes to developing a plugin system for a
> > Python package.
>
> > Should plugins be modules in a separate package?
> > Should there be a registry  of available plugins? how would such a
> > registry  be implemented? etc.
>
> There have been a gazillion discussions about this on this newsgroup/mailing
> list. Searching the archives will get you to them.
>
> The dynamic nature of python makes a whole range of options available.
> Depending on what you want to do (how are the plugins made available and so
> on), one or the other might be preferable.
>
> One relatively current development is the usage of setuptools "entry-points"
> feature, which is precisely made for discovering installed plugins:
>
> http://peak.telecommunity.com/DevCenter/setuptools#dynamic-discovery-...
>
> Diez

Thanks Diez,

I will search the archives. I am aware of the setuptools feature It is
quite nice. But the documentation is not very clear on how to define
"entry point groups" on the importing end, i.e. how to prepare a an
application to accept plugins it doesn't even now exist.

Flavio

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


Re: Local class variables? (mod_python problem)

2007-02-22 Thread Piet van Oostrum
> Rory Campbell-Lange <[EMAIL PROTECTED]> (RC) wrote:

>RC> We have a set of classes using static methods to retain reference
>RC> variables between operations. The problem is that the static variables
>RC> are not reset between operations when used through mod_python.

>RC> Although it is possible to reset the class variables between invocations
>RC> of the system, this has the potential of 'wiping out' these variables
>RC> when another user is using the system.

>RC> Is there a way of getting the equivalent of 'local class variables'? In
>RC> other words, a way of making 'print a' and 'print b' below provide the
>RC> same output?

There are several errors in your python code: quite a number of comma's
have to be replaced by semicolons (or newlines), and there is a spurious
comma.

And a and b already print out the same, so it is not clear what you want.
Do you mean that the x and y of the a and b object should be independent?
In that case you should not use static variables but instance variables.
If they have to survive across different HTTP requests you should use
sessions. 
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plugin development best practices

2007-02-22 Thread Diez B. Roggisch
> 
> I will search the archives. I am aware of the setuptools feature It is
> quite nice. But the documentation is not very clear on how to define
> "entry point groups" on the importing end, i.e. how to prepare a an
> application to accept plugins it doesn't even now exist.

The entry-points are just a method of discovery. Writing a plugin by
itself - if that is what you are talking about here - is usually done by
exposing a certain interface, and invoking some registration
functionality - after the plugin is discovered, that is.


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


Re: Creating a daemon process in Python

2007-02-22 Thread [EMAIL PROTECTED]
Thanks all,

I understood there is no shortcut function like BSD daemon().  I'll do
it manually using examples from cookbook...



On 2月22日, 午前1:41, Benjamin Niemann <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Sakagami Hiroki wrote:
> > What is the easiest way to create a daemon process in Python?  Google
> > says I should call fork() and other system calls manually, but is
> > there no os.daemon() and the like?
>
> You could try
> 
>
> HTH
>
> --
> Benjamin Niemann
> Email: pink at odahoda dot de
> WWW:http://pink.odahoda.de/


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


Re: Local class variables? (mod_python problem)

2007-02-22 Thread Diez B. Roggisch
Rory Campbell-Lange wrote:

> We have a set of classes using static methods to retain reference
> variables between operations. The problem is that the static variables
> are not reset between operations when used through mod_python.
> 
> Although it is possible to reset the class variables between invocations
> of the system, this has the potential of 'wiping out' these variables
> when another user is using the system.
> 
> Is there a way of getting the equivalent of 'local class variables'? In
> other words, a way of making 'print a' and 'print b' below provide the
> same output?


It's very unclear what you mean here, and I'm additionally under the
impression that you are deep in the murky waters of accidential concurrent
access errors here. 

I suggest you explain better what these variables are supposed to contain,
for whom, and for how long, and then we might suggest a better solution.

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


Re: plugin development best practices

2007-02-22 Thread Flavio
On Feb 22, 11:01 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On 22 Feb 2007 04:53:02 -0800, Flavio <[EMAIL PROTECTED]> wrote:
>
> >Hi,
>
> >Nowadays the addition of functionality to programs by means  of
> >plugins is very frequent.
>
> >I want to know the opinions of experienced Python developers about the
> >best practices when it comes to developing a plugin system for a
> >Python package.
>
> >Should plugins be modules in a separate package?
> >Should there be a registry  of available plugins? how would such a
> >registry  be implemented? etc.
>
> >thanks,
>
> Best practice may be to not develop a new plugin system.  There are quite a
> few available already.  Most likely, at least one of them is suitable for your
> application.
>
> Here are a couple starting points:
>
> http://twistedmatrix.com/projects/core/documentation/howto/plugin.html
>
> http://peak.telecommunity.com/DevCenter/setuptools#dynamic-discovery-...
>
> Jean-Paul

The plugin system provided by twisted looks interesting (though not as
simple as it could be, IMHO). Its main problem is that it introduces
two dependencies : Twisted plugin and ZopeInterface. I think a
functional plugin system could(and should) be done using only the
standard library.

Flávio

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


Reading mails from Outlook

2007-02-22 Thread beeswax
Hi,

Does anyone knows how to read e-mails from a specific folders in
outlook?
I only found out how to read the mails from the inbox folder and how
to list all available folder.
I just don't found a way to access my mails from the other folders.

Can anyone help me?

Regards,

Sam

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


Re: plugin development best practices

2007-02-22 Thread Flavio
On Feb 22, 10:53 am, "Flavio" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Nowadays the addition of functionality to programs by means  of
> plugins is very frequent.
>
> I want to know the opinions of experienced Python developers about the
> best practices when it comes to developing apluginsystemfor a
> Python package.
>
> Should plugins be modules in a separate package?
> Should there be a registry  of available plugins? how would such a
> registry  be implemented? etc.
>
> thanks,
>
> Flávio

let me extend my original question with an example:

Simple plugin system proposal:

have a package (directory with __init__.py) called plugins where the
actual plugins are modules in this directory.

When the main script imports the plugins package, all plugin modules
would be available as plugins.pluginA, plugins.pluginB , etc.

A registry of available plugins would be available as a simple
dir(plugins).

code in the main script than wished to use a given plugin, would only
have to look in the registry  before calling any code from a given
plugin.

What is wrong/missing with this simple framework?

I'd appreciate any comments.

Flávio

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


How to test whether a host is reachable?

2007-02-22 Thread Fabian Steiner
Hello!

As the subject says I need to test whether a host computer in our 
network is reachable or not. At the moment I simply attempt to connect 
to a given port that is open when the machine is online:

[...]
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
 sock.connect(('192.168.0.100', 80))
except socket.error:
 print >>sys.stderr "Server offline"
sock.close()
[...]

Now I am wondering if there isn't any better method which would be more 
general. In fact, I think of something like a python version of ping 
which only tries to send ICMP packets. However, I don't know what the 
code has to look like then. Any ideas or suggestions?

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


Re: Convert to binary and convert back to strings

2007-02-22 Thread Neil Cerutti
On 2007-02-22, Jussi Salmela <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano kirjoitti:
>> On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote:
>> 
 WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM.  It is just a
 nuisance for someone that really wants to decrypt the string. But
 it might work for your application.

 -Larry
>>> Thanks Larry! I was looking for something more beautiful but what the
>>> hey, it works!
>> 
>> 
>> Is this beautiful enough?
>> 
>> 
> s = "Python"
> u = unicode(s, "ascii")
> u
>> u'Python'
> u.encode('rot13')
>> 'Clguba'
>> 
>> 
>> For extra security, you can encode the string with rot13 twice.
>> 
>> 
>> 
>
> Like this? ;)
>
> >>> s = "Python" ; u = unicode(s, "ascii") ;  u
> u'Python'
> >>> u.encode('rot13')
> 'Clguba'
> >>> u.encode('rot13').encode('rot13')
> 'Python'

Woah! You better quadruple it instead.

How about Double Pig Latin?

No, wait! Use the feared UDPLUD code.

You go Ubbi Dubbi to Pig Latin, and then Ubbi Dubbi again.

Let's see here... Ubububythubububonubpubay

That's what I call ubububeautubububifubububulbubay.

-- 
Neil Cerutti
This is not a book to be put down lightly. It should be thrown with great
force. --Dorothy Parker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test whether a host is reachable?

2007-02-22 Thread Chris Mellon
On 2/22/07, Fabian Steiner <[EMAIL PROTECTED]> wrote:
> Hello!
>
> As the subject says I need to test whether a host computer in our
> network is reachable or not. At the moment I simply attempt to connect
> to a given port that is open when the machine is online:
>
> [...]
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> try:
>  sock.connect(('192.168.0.100', 80))
> except socket.error:
>  print >>sys.stderr "Server offline"
> sock.close()
> [...]
>
> Now I am wondering if there isn't any better method which would be more
> general. In fact, I think of something like a python version of ping
> which only tries to send ICMP packets. However, I don't know what the
> code has to look like then. Any ideas or suggestions?
>

This is the only reliable way of telling if you can communicate with a
service on a machine. A ping will tell you if it's connected to the
network, but not if it is actually providing any services.

If you really want a ping, the common way is to just execute the systems ping.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plugin development best practices

2007-02-22 Thread Diez B. Roggisch
> Simple plugin system proposal:
> 
> have a package (directory with __init__.py) called plugins where the
> actual plugins are modules in this directory.
> 
> When the main script imports the plugins package, all plugin modules
> would be available as plugins.pluginA, plugins.pluginB , etc.
> 
> A registry of available plugins would be available as a simple
> dir(plugins).
> 
> code in the main script than wished to use a given plugin, would only
> have to look in the registry  before calling any code from a given
> plugin.
> 
> What is wrong/missing with this simple framework?

Nothing wrong. It's just one way of doing it. But it requires you to have
all plugins being part of one module, in one location. Depending on what
you want to do, this won't suffice. For example if your app is installed in
a system path you aren't supposed to write to - how do you install your
individual plugin? easy_install allows you to install to a folder that is
contained in the PYTHONPATH, and then you can discover entrypoints.

But please, do as we suggested: read the past discussions.

Depending on what _you_ actually want to accomplish, you're proposal is
enough. But don't expect it to become the "one plugin system to rule them
all"-solution.

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


Re: Reading mails from Outlook

2007-02-22 Thread Larry Bates
beeswax wrote:
> Hi,
> 
> Does anyone knows how to read e-mails from a specific folders in
> outlook?
> I only found out how to read the mails from the inbox folder and how
> to list all available folder.
> I just don't found a way to access my mails from the other folders.
> 
> Can anyone help me?
> 
> Regards,
> 
> Sam
> 

I'll bet that some of the best information you can get about interacting
with Outlook is going to be by looking at the sourcecode to SpamBayes
plug-in.  You can get it from here:

https://sourceforge.net/project/showfiles.php?group_id=61702&package_id=58141

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


Re: How to test whether a host is reachable?

2007-02-22 Thread Larry Bates
Fabian Steiner wrote:
> Hello!
> 
> As the subject says I need to test whether a host computer in our
> network is reachable or not. At the moment I simply attempt to connect
> to a given port that is open when the machine is online:
> 
> [...]
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> try:
> sock.connect(('192.168.0.100', 80))
> except socket.error:
> print >>sys.stderr "Server offline"
> sock.close()
> [...]
> 
> Now I am wondering if there isn't any better method which would be more
> general. In fact, I think of something like a python version of ping
> which only tries to send ICMP packets. However, I don't know what the
> code has to look like then. Any ideas or suggestions?
> 
> Thanks,
> Fabian

Just because you could ping with ICMP packets doesn't mean you could
do anything with the machine.  I assume that you are connecting to
do something on the machine.  Just wrap what you are trying to do
in try: block.  It will either succeed or fail.  Handle the exeption.

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


Re: plugin development best practices

2007-02-22 Thread Flavio
On Feb 22, 12:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Simple plugin system proposal:
>
> > have a package (directory with __init__.py) called plugins where the
> > actual plugins are modules in this directory.
>
> > When the main script imports the plugins package, all plugin modules
> > would be available as plugins.pluginA, plugins.pluginB , etc.
>
> > A registry of available plugins would be available as a simple
> > dir(plugins).
>
> > code in the main script than wished to use a given plugin, would only
> > have to look in the registry  before calling any code from a given
> > plugin.
>
> > What is wrong/missing with this simple framework?
>
> Nothing wrong. It's just one way of doing it. But it requires you to have
> all plugins being part of one module, in one location. Depending on what
> you want to do, this won't suffice. For example if your app is installed in
> a system path you aren't supposed to write to - how do you install your
> individual plugin? easy_install allows you to install to a folder that is
> contained in the PYTHONPATH, and then you can discover entrypoints.
>
> But please, do as we suggested: read the past discussions.
>
> Depending on what _you_ actually want to accomplish, you're proposal is
> enough. But don't expect it to become the "one plugin system to rule them
> all"-solution.
>
> diez

Oh, I have read all the links that have been suggested, but I am
looking for the simplest possible solution.

I have no intention to create the "next Plugin system" I am just
trying to solve my own problem and in the process leave a record of a
fruitfull discussion about plugin systems.

BTW I have yet to check TRAC's plugin system.

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


Re: Convert to binary and convert back to strings

2007-02-22 Thread Grant Edwards
On 2007-02-22, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-02-22, Ganesan Rajagopal <[EMAIL PROTECTED]> wrote:
>
>>> I am hoping to have it show up some weird un-readable text.
>>> And then of course be able to convert it right back to a
>>> string. Is this even possible?
>>
>> Looks like you just want to obfuscate the string. How about
>> this?
>>
>> import base64
>> text = 'supercalifragilisticexpialidocius'
>> open('sambleb.conf', 'w').write(base64.encodestring(text))
>>
>> print base64.decodestring(open('sambleb.conf', 'r').read())
>
> It'll only remain obfuscated for about 30 seconds after even a
> mildly curious user looks at the file.

I should add that even "strong" encryption will only slow down
a curious user by 10 minutes if the encryption/decryption key
is embedded in the program...

Trying to hide things from users is usually futile unless you
want put a lot of work into it...

-- 
Grant Edwards   grante Yow!  Do you have exactly
  at   what I want in a plaid
   visi.compoindexter bar bat??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a daemon process in Python

2007-02-22 Thread Grant Edwards
On 2007-02-22, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I understood there is no shortcut function like BSD daemon().  I'll do
> it manually using examples from cookbook...

Sure would be nice if somebody posted one. ;)

-- 
Grant Edwards   grante Yow!  Oh, I get it!! "The
  at   BEACH goes on", huh,
   visi.comSONNY??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plugin development best practices

2007-02-22 Thread Flavio
On Feb 22, 12:51 pm, "Flavio" <[EMAIL PROTECTED]> wrote:
> On Feb 22, 12:36 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
>
>
> > > Simple plugin system proposal:
>
> > > have a package (directory with __init__.py) called plugins where the
> > > actual plugins are modules in this directory.
>
> > > When the main script imports the plugins package, all plugin modules
> > > would be available as plugins.pluginA, plugins.pluginB , etc.
>
> > > A registry of available plugins would be available as a simple
> > > dir(plugins).
>
> > > code in the main script than wished to use a given plugin, would only
> > > have to look in the registry  before calling any code from a given
> > > plugin.
>
> > > What is wrong/missing with this simple framework?
>
> > Nothing wrong. It's just one way of doing it. But it requires you to have
> > all plugins being part of one module, in one location. Depending on what
> > you want to do, this won't suffice. For example if your app is installed in
> > a system path you aren't supposed to write to - how do you install your
> > individual plugin? easy_install allows you to install to a folder that is
> > contained in the PYTHONPATH, and then you can discover entrypoints.
>
> > But please, do as we suggested: read the past discussions.
>
> > Depending on what _you_ actually want to accomplish, you're proposal is
> > enough. But don't expect it to become the "one plugin system to rule them
> > all"-solution.
>
> > diez
>
> Oh, I have read all the links that have been suggested, but I am
> looking for the simplest possible solution.
>
> I have no intention to create the "next Plugin system" I am just
> trying to solve my own problem and in the process leave a record of a
> fruitfull discussion about plugin systems.
>
> BTW I have yet to check TRAC's plugin system.

I have look at Trac's component based pluging system and I liked it
very much. If external dependencies is not an issue I believe this is
the best solution.
http://trac.edgewall.org/wiki/TracPlugins

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


Re: plugin development best practices

2007-02-22 Thread Jean-Paul Calderone
On Thu, 22 Feb 2007 15:36:42 +0100, "Diez B. Roggisch" <[EMAIL PROTECTED]> 
wrote:
>> Simple plugin system proposal:
>>
>> have a package (directory with __init__.py) called plugins where the
>> actual plugins are modules in this directory.
>>
>> When the main script imports the plugins package, all plugin modules
>> would be available as plugins.pluginA, plugins.pluginB , etc.
>>
>> A registry of available plugins would be available as a simple
>> dir(plugins).
>>
>> code in the main script than wished to use a given plugin, would only
>> have to look in the registry  before calling any code from a given
>> plugin.
>>
>> What is wrong/missing with this simple framework?
>
>Nothing wrong.

Are you sure?

  [EMAIL PROTECTED]:~$ mkdir someplugins
  [EMAIL PROTECTED]:~$ touch someplugins/__init__.py
  [EMAIL PROTECTED]:~$ touch someplugins/a.py
  [EMAIL PROTECTED]:~$ python
  Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
  [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import someplugins
  >>> dir(someplugins)
  ['__builtins__', '__doc__', '__file__', '__name__', '__path__']
  >>>

Hey, where's my plugin?

This most trivial test would have demonstrated the problem with the proposed
plugin system.  But I suppose it was easier for Flavio to make someone else
find the defect in his new system than to either test it himself or to look
carefully at any of the existing systems.

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


Re: How to test whether a host is reachable?

2007-02-22 Thread Diez B. Roggisch
> Just because you could ping with ICMP packets doesn't mean you could
> do anything with the machine.  I assume that you are connecting to
> do something on the machine.  Just wrap what you are trying to do
> in try: block.  It will either succeed or fail.  Handle the exeption.

And the other way round: just because you can't ping a machine doesn't mean
you can't do anything with it - a Firewall might just have snipped away all
the ICMP-packets.

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


Re: plugin development best practices

2007-02-22 Thread Diez B. Roggisch
Jean-Paul Calderone wrote:

> On Thu, 22 Feb 2007 15:36:42 +0100, "Diez B. Roggisch"
> <[EMAIL PROTECTED]> wrote:
>>> Simple plugin system proposal:
>>>
>>> have a package (directory with __init__.py) called plugins where the
>>> actual plugins are modules in this directory.
>>>
>>> When the main script imports the plugins package, all plugin modules
>>> would be available as plugins.pluginA, plugins.pluginB , etc.
>>>
>>> A registry of available plugins would be available as a simple
>>> dir(plugins).
>>>
>>> code in the main script than wished to use a given plugin, would only
>>> have to look in the registry  before calling any code from a given
>>> plugin.
>>>
>>> What is wrong/missing with this simple framework?
>>
>>Nothing wrong.
> 
> Are you sure?

Darn. You're right of course - I just got the basic idea, and formed in my
mind the "get the modules filename, thus the path, glob over it for *py,
and thus get the subsequent module names"-pattern. Which is trivial of
course, but not as trivial as just dir(module)

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


list/get methods/attributes of a class?

2007-02-22 Thread bkamrani
Hello,
Sorry guys for this newbie questions. But I wonder if there is a
standard or build-in method to know the methods of a class?

I'm not originally a progrommer and I have worked with python/qt in a
basic level. Now I work a package which has many predefined classes
which I'm going to resue by importing them. I would like to know more
about each imported class, what methods exists and so on. Printing the
object or type(object) doesn't say so much.

Any hint or helps is really appreciated!
/Ben

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


Re: How to test whether a host is reachable?

2007-02-22 Thread Fabian Steiner
Hello!

Chris Mellon wrote:
> On 2/22/07, Fabian Steiner <[EMAIL PROTECTED]> wrote:
>> [...]
>> Now I am wondering if there isn't any better method which would be more
>> general. In fact, I think of something like a python version of ping
>> which only tries to send ICMP packets. However, I don't know what the
>> code has to look like then. Any ideas or suggestions?
>>
> 
> This is the only reliable way of telling if you can communicate with a
> service on a machine. A ping will tell you if it's connected to the
> network, but not if it is actually providing any services.
> 
> If you really want a ping, the common way is to just execute the systems 
> ping.

Ok, obviously, my approach was already the best way to achive this aim.

Thanks for you help,
Fabian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Local class variables? (mod_python problem)

2007-02-22 Thread Rory Campbell-Lange
Apologies to Piet and Diez for the lack of clarity in my previous post
(and the broken code).

In essence we use class variables as follows:

class Part (object):
totalgia = 0
def __init__(self, gia):
self.gia = gia  # gross internal area
self.giaratio = 0
Part.totalgia += self.gia
def addavgbm(self):
self.giaratio = float(self.gia)/float(Part.totalgia)
def __repr__(self):
return "gia: %0.1f giaratio: %0.2f" % (self.gia, self.giaratio)

if __name__ == '__main__':
p1 = Part(20)
p2 = Part(30)
for p in p1, p2:
p.addavgbm()
print p

totalgia keeps incrementing when this code is used under mod_python.

We most certainly are in 'murky waters of accidental concurrent access'.
A life vest would be gratefully received.

Kind regards
Rory


On 22/02/07, Rory Campbell-Lange ([EMAIL PROTECTED]) wrote:
> We have a set of classes using static methods to retain reference
> variables between operations. The problem is that the static variables
> are not reset between operations when used through mod_python.
> 
> Although it is possible to reset the class variables between invocations
> of the system, this has the potential of 'wiping out' these variables
> when another user is using the system.
> 
> Is there a way of getting the equivalent of 'local class variables'? In
> other words, a way of making 'print a' and 'print b' below provide the
> same output?

On 22/02/07, Piet van Oostrum ([EMAIL PROTECTED]) wrote:
> > Rory Campbell-Lange <[EMAIL PROTECTED]> (RC) wrote:

> There are several errors in your python code: quite a number of comma's
> have to be replaced by semicolons (or newlines), and there is a spurious
> comma.


On 22/02/07, Diez B. Roggisch ([EMAIL PROTECTED]) wrote:
> Rory Campbell-Lange wrote:

> It's very unclear what you mean here, and I'm additionally under the
> impression that you are deep in the murky waters of accidential
> concurrent access errors here. 


-- 
Rory Campbell-Lange 
<[EMAIL PROTECTED]>

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


Re: list/get methods/attributes of a class?

2007-02-22 Thread Thomas Nelson
Check out the dir() function.  It does what you want, I think.

Tom

On Feb 22, 9:27 am, [EMAIL PROTECTED] wrote:
> Hello,
> Sorry guys for this newbie questions. But I wonder if there is a
> standard or build-in method to know the methods of a class?
>
> I'm not originally a progrommer and I have worked with python/qt in a
> basic level. Now I work a package which has many predefined classes
> which I'm going to resue by importing them. I would like to know more
> about each imported class, what methods exists and so on. Printing the
> object or type(object) doesn't say so much.
>
> Any hint or helps is really appreciated!
> /Ben


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


Re: plugin development best practices

2007-02-22 Thread Paul Boddie
On 22 Feb, 16:13, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>
> Darn. You're right of course - I just got the basic idea, and formed in my
> mind the "get the modules filename, thus the path, glob over it for *py,
> and thus get the subsequent module names"-pattern. Which is trivial of
> course, but not as trivial as just dir(module)

The __init__.py file of a plugins package could contain something like
this:

# Start
def init():
import os
global __all__
this_dir = os.path.split(__file__)[0]
py_suffix = os.path.extsep + "py"
__all__ = []
for filename in os.listdir(this_dir):
if os.path.isdir(os.path.join(this_dir, filename)) and \
os.path.exists(os.path.join(this_dir, filename, "__init__"
+ py_suffix)):
__all__.append(filename)
else:
module, suffix = os.path.splitext(filename)
if suffix == py_suffix and module != "__init__":
__all__.append(module)
init()
del init
# End

This should populate the __all__ attribute of the package with then
names of any submodules or subpackages. Although that in itself won't
provide the names of the plugins via the dir function, the __all__
attribute is some kind of standard, and things like "from plugins
import *" will import all the known plugins. In fact, if you add such
an import statement to the end of the above code, you'll get all the
names of the plugins stored within the package (and thus returned by
the dir function) because the submodules and subpackages will actually
have been imported. Even reloading the plugins package will update the
__all__ attribute, although things like the unloading or removal of
plugins might be challenging in a solution where such things are
automatically imported.

Having a variation of the above function in the standard library could
be fairly useful, I suppose.

Paul

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


Re: Local class variables? (mod_python problem)

2007-02-22 Thread Piet van Oostrum
> Rory Campbell-Lange <[EMAIL PROTECTED]> (RC) wrote:

>RC> totalgia keeps incrementing when this code is used under mod_python.

And also when used outside of mod_python. It is because it is a class level
variable. In fact I think under certain circumstances in mod_python it will
not do that because different requests can run in different Apache
processes (on Linux, Unix, Mac OS X etc.). So it this desired behaviour or
not? Your post isn't clear about that. And if it isn't what is the desired
behaviour?

And you certainly should do something about the concurrent access. 
-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


paths in modules

2007-02-22 Thread Brandon Mintern
I am developing a project in Python which uses several external utilities.
For convenience, I am wrapping these accesses in a module. The problem is
that I cannot be sure where these modules are imported from, so I am
trying to figure out how to reliably execute e.g. a popen call.  Example
layout:

toplevel_dir
+-main script
+-wrapper_dir
  +-some_wrapper
  +-utility_dir
+-some_external_utility

So in my main script, I might say:

from wrapper_dir import some_wrapper

some_wrapper.use_external_utility()


And then in some_wrapper, I would have code like:

import os

def use_external_utility():
  f = os.popen('utility_dir/some_external_utility')
  lines = f.readlines()
  f.close()
  return lines


Of course, the problem with that approach is that it fails because there
is no utility_dir in the CWD, which is actually top_level_dir.  So my
question is whether there is any way to specify that specified paths are
relative to the module's directory rather than the importing file's
directory.  I would really like to avoid kludging together some solution
that involves passing variables or having knowledge of where my module is
being imported from.

I am hoping that there is some simple solution to this problem that I
simply haven't found in my searches so far.  If so, I will humbly accept
any ridicule that comes along with said simple solution :-).

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


Re: paths in modules

2007-02-22 Thread Brandon Mintern
On Thu, 22 Feb 2007 11:13:46 -0500, Brandon Mintern wrote:
> Of course, the problem with that approach is that it fails because there
> is no utility_dir in the CWD...

...and of course by CWD, I actually mean "current working directory",
which should have actually been PWD or "present working directory".
Anyway, I just wanted to clear up any confusion that might result due to
my improper terminology.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to test whether a host is reachable?

2007-02-22 Thread Bart Ogryczak
On Feb 22, 3:22 pm, Fabian Steiner <[EMAIL PROTECTED]> wrote:

> Now I am wondering if there isn't any better method which would be more
> general. In fact, I think of something like a python version of ping
> which only tries to send ICMP packets.

Server or a firewall in between most probably will filter out any ICMP
packets, so you'll get no pings at all from a machine which IS on-
line. The only way is try the services that you know, that should be
open on that machine. Do not try too many at a time, becouse that
could be interpeted as portscan and you'll get blacklisted.



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


Re: paths in modules

2007-02-22 Thread Paul Boddie
On 22 Feb, 17:13, Brandon Mintern <[EMAIL PROTECTED]> wrote:
>
> toplevel_dir
> +-main script
> +-wrapper_dir
>   +-some_wrapper
>   +-utility_dir
> +-some_external_utility

[...]

> And then in some_wrapper, I would have code like:
>
> import os
>
> def use_external_utility():
>   f = os.popen('utility_dir/some_external_utility')
>   lines = f.readlines()
>   f.close()
>   return lines

And you really want to refer to utility_dir relative to some_wrapper.
What you can try is to split the __file__ attribute of some_wrapper -
it's a standard attribute on imported modules - in order to refer to
the module's parent directory (which should correspond to
wrapper_dir):

parent_dir, filename = os.path.split(__file__)

Then you can join the parent directory to the path of the command:

cmd = os.path.join(parent_dir, "utility_dir", "some_external_utility")

The __file__ attribute of modules is documented here:

http://docs.python.org/ref/types.html#l2h-109

Paul

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


Re: Bug in time module - %z works in perl, not in python?

2007-02-22 Thread bwooster47
On Feb 21, 9:50 pm, [EMAIL PROTECTED] wrote:
> On Feb 21, 6:17 pm, [EMAIL PROTECTED] wrote:
...
> > 2007-02-21 21:15:58 EST+  (iso localtime, python)

> Seems to be a bug.  I can duplicate the
> problem here (Python 2.4.3, Red Hat Desktop release 4).

I searched the bug database, found this issue was closed as not a bug.

I don't know if I should enter a new bug, for now, have just added a
comment to the above closure, not sure if anyone will look into
whether this issue should be reopened.

http://sourceforge.net/tracker/index.php?func=detail&aid=1493676&group_id=5470&atid=105470


[above bug says that %z (small z) is not supported by Python - that
seems to be incorrect, atleast to me. Capital Z may be deprecated, but
not small z as far as I can tell.]

Can we confirm whether this issue is not a python issue?
We are talking about small z, not capital Z.

>From Python docs at http://docs.python.org/lib/module-time.html  :
"The use of %Z is now deprecated, but the %z escape that expands to
the
preferred hour/minute offset is not supported by all ANSI C
libraries."

Most current C libraries support %z, it is in fact the preferred way
to do
things, would be bad to see python reject this.
Even then - isn't the above a bug? If not supported, %z should always
provide a empty character, but not print out totally incorrect data as
+ for EST.

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


Re: paths in modules

2007-02-22 Thread Larry Bates
Brandon Mintern wrote:
> I am developing a project in Python which uses several external utilities.
> For convenience, I am wrapping these accesses in a module. The problem is
> that I cannot be sure where these modules are imported from, so I am
> trying to figure out how to reliably execute e.g. a popen call.  Example
> layout:
> 
> toplevel_dir
> +-main script
> +-wrapper_dir
>   +-some_wrapper
>   +-utility_dir
> +-some_external_utility
> 
> So in my main script, I might say:
> 
> from wrapper_dir import some_wrapper
> 
> some_wrapper.use_external_utility()
> 
> 
> And then in some_wrapper, I would have code like:
> 
> import os
> 
> def use_external_utility():
>   f = os.popen('utility_dir/some_external_utility')
>   lines = f.readlines()
>   f.close()
>   return lines
> 
> 
> Of course, the problem with that approach is that it fails because there
> is no utility_dir in the CWD, which is actually top_level_dir.  So my
> question is whether there is any way to specify that specified paths are
> relative to the module's directory rather than the importing file's
> directory.  I would really like to avoid kludging together some solution
> that involves passing variables or having knowledge of where my module is
> being imported from.
> 
> I am hoping that there is some simple solution to this problem that I
> simply haven't found in my searches so far.  If so, I will humbly accept
> any ridicule that comes along with said simple solution :-).
> 
> Thanks in advance,
> Brandon

Normally this would be:

f = os.popen('./wrapper_dir/utility_dir/some_external_utility')

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


Re: paths in modules (solved)

2007-02-22 Thread Brandon Mintern
On Thu, 22 Feb 2007 08:28:50 -0800, Paul Boddie wrote:
> And you really want to refer to utility_dir relative to some_wrapper.
> What you can try is to split the __file__ attribute of some_wrapper -
> it's a standard attribute on imported modules - in order to refer to
> the module's parent directory (which should correspond to
> wrapper_dir):
> 
> parent_dir, filename = os.path.split(__file__)
> 
> Then you can join the parent directory to the path of the command:
> 
> cmd = os.path.join(parent_dir, "utility_dir", "some_external_utility")
> 
> The __file__ attribute of modules is documented here:
> 
> http://docs.python.org/ref/ty__file__ is the pathname of the file from
> which the module was loadedpes.html#l2h-109
> 
> Paul

Thanks a lot.  I was hoping for a solution like that, and it worked
perfectly for me (admittedly, in my trivial test files, but I'm sure that
the solution will extend to my actual use case).

Also, I had actually read that documentation you pointed me to, but the
language, "__file__ is the pathname of the file from which the module was
loaded" had me thinking that it was the pathname of the file doing the
loading, rather than the file being loaded.  I guess I should have
actually tried it out.

Anyways, thanks for the quick response and for the clarification.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to remove the ':' symbol in the end of lines starting with 'if', 'while' etc?

2007-02-22 Thread openopt
> Think on the bright side:
>
> you have to type ":" at the beginning of loop and conditional blocks,
> but you don't have to type "end"  at the end... you are still saving
> two strokes...
> ;-))

No, there no profits:
instead of 'end' I must type , ':' and backspace in the end of
block - so 3 keypress are used, same as 'end'
Of course Python is much more better in syntax vs C/C++ but I would
prefere tcl-style or caml-style
x = fun arg1 arg2 ... argn
however, in tcl annoing things are 'set' and 'expr'
and in ocaml '<-' and 'let x = ... in' - too many keypress instead of
'='
but their func calls still is better then fun(arg1, arg2, ..., argn)
and help _something_  or which _something_ in MATLAB is much more
better then help(_something_) in Python
the only bad thing in MATLAB (+absence of x = fun arg1 arg2 ... argn
call) is indexing arrays by () instead of [] - holding shift key
dozens times per day is very unconvinient.
And in Python vs MATLAB is very unconvinient arrays creation.

I'm very afraid of proposition that I noticed at
http://wiki.python.org/moin/SummerOfCode
Base multidimensional array type for Python core
Student: KarolLangner
Mentor: Travis E. Oliphant
I don't know about anyone mentioned but I'm not sure this is a good
idea to hire ordinary student for such important thing.
And writing 'dimarray(...)' dozens times per day is much more bad than
x = matrix('...'), x = array([...]) or, of course, MATLAB-style x = [1
2 3]
I guess it should 10 times more think about the array and make it once
and forever - Python already has some array-related classes and all
with syntax much more bad than MATLAB. I guess there should be only 2
types: one for storing data in convinient way without reallocating
(something like C++ STL vector<>) and one for quick calculations
(something like C++ valarray).
WBR, Dmitrey.

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


Re: list/get methods/attributes of a class?

2007-02-22 Thread Jason
On Feb 22, 8:27 am, [EMAIL PROTECTED] wrote:
> Hello,
> Sorry guys for this newbie questions. But I wonder if there is a
> standard or build-in method to know the methods of a class?
>
> I'm not originally a progrommer and I have worked with python/qt in a
> basic level. Now I work a package which has many predefined classes
> which I'm going to resue by importing them. I would like to know more
> about each imported class, what methods exists and so on. Printing the
> object or type(object) doesn't say so much.
>
> Any hint or helps is really appreciated!
> /Ben

Also, try out the built-in help function on the original class.  It'll
list the class layout, methods, and any associated document strings.
(It won't list member variables, though.)  To see all elements in an
instance or class, use the dir() function.

>>> class Dummy(object):
... "A sample class that can have any given data."
... def __init__(self, *args):
... self._args = args
... def GetArgCount(self):
... """Show how many arguments were passed at
instantiation."""
... return len(self._args)
...
>>> d = Dummy(1, 2, 'three')
>>> help(d)  # help(Dummy) also works
Help on Dummy in module __main__ object:

class Dummy(__builtin__.object)
 |  A sample class that can have any given data.
 |
 |  Methods defined here:
 |
 |  GetArgCount(self)
 |  Show how many arguments were passed at instantiation.
 |
 |  __init__(self, *args)
 |
 |
--
 |  Data and other attributes defined here:
 |
 |  __dict__ = 
 |  dictionary for instance variables (if defined)
 |
 |  __weakref__ = 
 |  list of weak references to the object (if defined)
>>>

  --Jason

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


Re: paths in modules

2007-02-22 Thread Brandon Mintern
On Thu, 22 Feb 2007 10:30:59 -0600, Larry Bates wrote:
> Normally this would be:
> 
> f = os.popen('./wrapper_dir/utility_dir/some_external_utility')
> 
> -Larry

Yes, but the problem with that solution is, let's say that I further
abstract the whole thing and I add a directory outside of my toplevel_dir,
which has the syntax:

from toplevel_dir.wrapper_dir import some_wrapper

some_wrapper.use_external_utility()


Now, once again, the module is broken.  This is what I was trying to
avoid.  At any rate, Paul's solution was exactly what I was looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


export an array of floats to python

2007-02-22 Thread Peter Wuertz
Hi,

I'm writing a C module for python, that accesses a special usb camera. 
This module is supposed to provide python with data (alot of data). Then 
SciPy is used to fit the data.

My question is, how to make python read from a C array? By reading the 
documentation, one could get the impression that PyBufferObjects do that 
job.

http://docs.python.org/api/bufferObjects.html

It says:
"Two examples of objects that support the buffer interface are strings 
and arrays."

Where this function looks promising:
"PyBuffer_FromMemory - Return a new read-only buffer object that reads 
from a specified location in memory, with a specified size."

All right, lets imagine I created a PyBufferObject from my float array 
in the C module, and passed it to python.

I dont know what to do with a BufferObject in python, I would like to 
"cast" it to a Array of the type float, but Arrays do not have that kind 
of function... they can only be constructed from files or lists.

Apart from creating these BufferObjects, there is no documentation about 
what to do with them :(

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


How can I track/monitor an application and system resources.

2007-02-22 Thread [EMAIL PROTECTED]
Hello All,

I'm a newbie to Python!

I am trying to develop a program that monitors the performance of an
application.  The kind of information I am interested in is the CPU/
Process/Thread and memory performance. Specifically, I would like to
track the following

CPU usage
Used Memory on Phone
Free Memory on Phone
Number of Processes running
Number of threads running
Number of Filehandles currently open
Memory used by a process/thread
Process/Thread CPU activity.

All this under Windows

Can anyone help me, or direct me to the appriopriate API's so I can
get the above information?

Does anyone have any other sugestions on what else I could monitor for
a running application?

Does anyone have any example code they can direct me to?

Many thanks in advance,


Richard

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


Possible to set cpython heap size?

2007-02-22 Thread Andy Watson
I have an application that scans and processes a bunch of text files.
The content I'm pulling out and holding in memory is at least 200MB.

I'd love to be able to tell the CPython virtual machine that I need a
heap of, say 300MB up front rather than have it grow as needed.   I've
had a scan through the archives of comp.lang.python and the python
docs but cannot find a way to do this.  Is this possible to configure
the PVM this way?

Much appreciated,
Andy
--

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


[ANN] MathTran project

2007-02-22 Thread Jonathan Fine
MathTran is a JISC funded project to provide translation of mathematical
content as a web service.  MathTran will be using TeX to provide
mathematical typography, and will use Python as its main programming
language.

http://www.open.ac.uk/mathtran/
http://www.jisc.ac.uk/

http://www.jisc.ac.uk/whatwedo/programmes/elearning_framework/toolkit_mathtran.aspx

-- 
Jonathan Fine
The Open University, Milton Keynes, England


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


Re: Local class variables? (mod_python problem)

2007-02-22 Thread Rory Campbell-Lange
On 22/02/07, Rory Campbell-Lange ([EMAIL PROTECTED]) wrote:

> In essence we use class variables as follows:
> 
> class Part (object):
> totalgia = 0
> def __init__(self, gia):
> self.gia = gia  # gross internal area
> self.giaratio = 0
> Part.totalgia += self.gia
> def addavgbm(self):
> self.giaratio = float(self.gia)/float(Part.totalgia)
> def __repr__(self):
> return "gia: %0.1f giaratio: %0.2f" % (self.gia, self.giaratio)
> 
> if __name__ == '__main__':
> p1 = Part(20)
> p2 = Part(30)
> for p in p1, p2:
> p.addavgbm()
> print p
> 
> totalgia keeps incrementing when this code is used under mod_python.

> On 22/02/07, Rory Campbell-Lange ([EMAIL PROTECTED]) wrote:

On 22/02/07, Piet van Oostrum ([EMAIL PROTECTED]) wrote:
> > Rory Campbell-Lange <[EMAIL PROTECTED]> (RC) wrote:
> >RC> totalgia keeps incrementing when this code is used under mod_python.
> 
> And also when used outside of mod_python. It is because it is a class level
> variable. In fact I think under certain circumstances in mod_python it will
> not do that because different requests can run in different Apache
> processes (on Linux, Unix, Mac OS X etc.). So it this desired behaviour or
> not? Your post isn't clear about that. And if it isn't what is the desired
> behaviour?
> 
> And you certainly should do something about the concurrent access. 

It is not desirable for the class variable to keep incrementing outside
of invocations of '__main__', as is the case when it is loaded under
mod_python under apache2 on linux.

I would be grateful for pointers on dealing with concurrent access.

Regards
Rory


-- 
Rory Campbell-Lange 
<[EMAIL PROTECTED]>

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


Re: Bug in time module - %z works in perl, not in python?

2007-02-22 Thread Paul Boddie
On 22 Feb, 17:29, [EMAIL PROTECTED] wrote:
> On Feb 21, 9:50 pm, [EMAIL PROTECTED] wrote:
>
> > On Feb 21, 6:17 pm, [EMAIL PROTECTED] wrote:
> ...
> > > 2007-02-21 21:15:58 EST+  (iso localtime, python)
> > Seems to be a bug.  I can duplicate the
> > problem here (Python 2.4.3, Red Hat Desktop release 4).
>
> I searched the bug database, found this issue was closed as not a bug.

As far as I can see, the reason for the differing behaviour of
time.strftime is due to the way any supplied tuple is processed:

1. In Modules/timemodule.c, the time_strftime function calls gettmarg.

2. In gettmarg, various fields of struct tm are filled in, except for
tm_gmtoff and tm_zone/__tm_zone (according to /usr/include/time.h).

3. Consequently, any structure produced from a tuple may lack those
fields, in contrast to such structures produced directly by the system
calls.

4. Thus, the strftime system call fails to find or make use of time
zone information.

So it looks like no call to strftime with a supplied argument will
produce time zone information. Trying to use the datetime module to
reproduce the problem seems to involve a need to produce "aware"
datetime objects, apparently requiring me to define my own tzinfo
class:

class mytz(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(minutes=60)
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return "CET"

Only then will there be time zone or offset information on datetime
objects:

now = datetime.datetime.now(mytz())
now.strftime("%Y-%m-%d %H:%M:%S %z")
# produced '2007-02-22 18:14:41 +0100'

Some helper classes would really be useful for this kind of thing (and
I remember that there is a time zone database module out there
somewhere), but at least the time zone information gets through in the
end.

Paul

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


Re: Possible to set cpython heap size?

2007-02-22 Thread Diez B. Roggisch
Andy Watson wrote:

> I have an application that scans and processes a bunch of text files.
> The content I'm pulling out and holding in memory is at least 200MB.
> 
> I'd love to be able to tell the CPython virtual machine that I need a
> heap of, say 300MB up front rather than have it grow as needed.   I've
> had a scan through the archives of comp.lang.python and the python
> docs but cannot find a way to do this.  Is this possible to configure
> the PVM this way?

Why do you want that? And no, it is not possible. And to be honest: I have
no idea why e.g. the JVM allows for this.

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


How to covert ASCII to integer in Python?

2007-02-22 Thread John
Is there any built in function that converts ASCII to integer or vice versa
in Python?

Thanks!


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


Re: export an array of floats to python

2007-02-22 Thread Travis Oliphant
Peter Wuertz wrote:
> Hi,
> 
> I'm writing a C module for python, that accesses a special usb camera. 
> This module is supposed to provide python with data (alot of data). Then 
> SciPy is used to fit the data.
>

Which version of scipy are you using?


> My question is, how to make python read from a C array? By reading the 
> documentation, one could get the impression that PyBufferObjects do that 
> job.
> 
> http://docs.python.org/api/bufferObjects.html
> 
> It says:
> "Two examples of objects that support the buffer interface are strings 
> and arrays."
> 
> Where this function looks promising:
> "PyBuffer_FromMemory - Return a new read-only buffer object that reads 
> from a specified location in memory, with a specified size."
> 
> All right, lets imagine I created a PyBufferObject from my float array 
> in the C module, and passed it to python.

How about creating an array directly from your float array using 
PyArray_SimpleNewFromData (the NumPy C-API) or PyArray_FromDimsAndData 
(the Numeric C-API).


-Travis

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


Re: How can I track/monitor an application and system resources.

2007-02-22 Thread Jordan
On Feb 22, 11:48 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hello All,
>
> I'm a newbie to Python!
>
> I am trying to develop a program that monitors the performance of an
> application.  The kind of information I am interested in is the CPU/
> Process/Thread and memory performance. Specifically, I would like to
> track the following
>
> CPU usage
> Used Memory on Phone
> Free Memory on Phone
> Number of Processes running
> Number of threads running
> Number of Filehandles currently open
> Memory used by a process/thread
> Process/Thread CPU activity.
>
> All this under Windows
>
> Can anyone help me, or direct me to the appriopriate API's so I can
> get the above information?
>
> Does anyone have any other sugestions on what else I could monitor for
> a running application?
>
> Does anyone have any example code they can direct me to?
>
> Many thanks in advance,
>
> Richard

You will definitely want to check out pywin32api, because it is the
best (and most powerful) way to interact with windows through python.
Also, if you know any c++, you might search for taskmanager extensions
on codeproject.com or look at the msdn on taskmanager to see how it
gets all of its information (which is essentially what you want -- a
taskmanager).  Either way you'll almost defitely need pywin32, so look
there first.

Cheers,
Jordan

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread Larry Bates
John wrote:
> Is there any built in function that converts ASCII to integer or vice versa
> in Python?
> 
> Thanks!
> 
> 
You probably should go through the tutorial ASAP that is located here:

http://docs.python.org/tut/


Convert ascii string to integer:

a='1'
b=int(a)

Convert integer to ascii string:

a=1
b=str(a)

or

a=1
b="%i" % a

-Larry Bates

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread keirr
On Feb 22, 5:43 pm, "John" <[EMAIL PROTECTED]> wrote:
> Is there any built in function that converts ASCII to integer or vice versa
> in Python?
>
> Thanks!

Try int.
ie.

try:
   int_val = int(str_val)
except ValueError:
   # conversion failed

Keir.

--
Keir Robinson
Sometimes a scream is better than a thesis. (Emerson)


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


Re: export an array of floats to python

2007-02-22 Thread Larry Bates
Peter Wuertz wrote:
> Hi,
> 
> I'm writing a C module for python, that accesses a special usb camera.
> This module is supposed to provide python with data (alot of data). Then
> SciPy is used to fit the data.
> 
> My question is, how to make python read from a C array? By reading the
> documentation, one could get the impression that PyBufferObjects do that
> job.
> 
> http://docs.python.org/api/bufferObjects.html
> 
> It says:
> "Two examples of objects that support the buffer interface are strings
> and arrays."
> 
> Where this function looks promising:
> "PyBuffer_FromMemory - Return a new read-only buffer object that reads
> from a specified location in memory, with a specified size."
> 
> All right, lets imagine I created a PyBufferObject from my float array
> in the C module, and passed it to python.
> 
> I dont know what to do with a BufferObject in python, I would like to
> "cast" it to a Array of the type float, but Arrays do not have that kind
> of function... they can only be constructed from files or lists.
> 
> Apart from creating these BufferObjects, there is no documentation about
> what to do with them :(
> 
> Thanks for your help!

I've always used the struct module to unpack the C array into the floats
(or ints or strings or ...) that I wanted.

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


Re: Possible to set cpython heap size?

2007-02-22 Thread Andy Watson
 > Why do you want that? And no, it is not possible. And to be honest:
I have
> no idea why e.g. the JVM allows for this.
>
> Diez

The reason why is simply that I know roughly how much memory I'm going
to need, and cpython seems to be taking a fair amount of time
extending its heap as I read in content incrementally.

Ta,
Andy
--

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


Re: when will python 2.5 take in mainstream?

2007-02-22 Thread Martin v. Löwis
> Its simple to require changes, not so sure that doing these
> modifications keep things simple. Maybe an internal Python hacker can
> give us his advice on such a modification (ie. staying compatible with
> legacy modules compiled for previous versions).

I think it should be possible to specify a Python API that then future
versions can guarantee. This would be a subset of what you can currently
do on the Python API, in particular, access to the structure layout of
Python objects would not be available.

Extension modules compiled against this API could then be compatible
across versions.

This would require both a change to the interpreter (to really mark
all API that is or is not "stable"), and to extension modules (to
restrict themselves to only this API).

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread hg
John wrote:

> Is there any built in function that converts ASCII to integer or vice
> versa in Python?
> 
> Thanks!
>>> int('10')
10
>>> str(10)
'10'
>>> 

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


Re: export an array of floats to python

2007-02-22 Thread Peter Wuertz
Travis Oliphant wrote:
> Peter Wuertz wrote:
>> Hi,
>>
>> I'm writing a C module for python, that accesses a special usb camera. 
>> This module is supposed to provide python with data (alot of data). 
>> Then SciPy is used to fit the data.
>>
> 
> Which version of scipy are you using?

I'm using ubuntu edgy eft, which ships scipy 0.5.2

> How about creating an array directly from your float array using 
> PyArray_SimpleNewFromData (the NumPy C-API) or PyArray_FromDimsAndData 
> (the Numeric C-API).

Cool thanks, thats exactly what I needed!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: when will python 2.5 take in mainstream?

2007-02-22 Thread Martin v. Löwis
Paul Rubin schrieb:
> Laurent Pointal <[EMAIL PROTECTED]> writes:
>> IMHO trying to have a binary compatibility with older compiled modules
>> by maintaining an ad-hoc layer to switch between 2.4/2.5 engines make
>> Python code more complex. And more complex code have generally more
>> bugs. This is the reason for my KISS hope about Python.
> 
> I haven't heard of other languages that seriously try to do that,
> though maybe some do.  

Languages typically achieve this by specifying an ABI (in addition
to the API), and then sticking to that.

The most prominent example is the language C, where you normally
can upgrade the C library on most current systems without having
to recompile all applications. Today, there is machinery to still
allow evolution of the C library. E.g. on Linux, there really
is a layer in the C library to provide binary compatibility with
earlier versions.

Another example is Java and JNI, which is an interface that just
won't change (AFAIK).

Similar to Python, Tcl has a layer of function pointers that is
designed to be version-indepdendent - whether this actually works,
I don't know.

There are many more examples.

Regards,
Martin

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


Re: when will python 2.5 take in mainstream?

2007-02-22 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> I think it should be possible to specify a Python API that then future
> versions can guarantee. This would be a subset of what you can currently
> do on the Python API, in particular, access to the structure layout of
> Python objects would not be available.

An FFI like this is a reasonable idea, but it shouldn't look anything
like the current C API.  It should be more like a Lisp FFI, or the
Java Native Interface.  There might have to be a wrapper layer to get
it to work with CPython.
-- 
http://mail.python.org/mailman/listinfo/python-list


JIT (just-in-tme accelerator) for Python - exists or no?

2007-02-22 Thread openopt
Or is any progress going on now?

The JIT in MATLAB or Java seems to be very effective.

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


Re: when will python 2.5 take in mainstream?

2007-02-22 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> > I haven't heard of other languages that seriously try to do that,
> > though maybe some do.  
> Languages typically achieve this by specifying an ABI (in addition
> to the API), and then sticking to that.

Oh yes, at that level, it's reasonable and desirable.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicodedata implementation

2007-02-22 Thread Martin v. Löwis
James Abley schrieb:
> So from my understanding of the Unicode (3.2.0) spec, the code point
> 0x325F has a numeric property with a value of 35, but the python (2.3
> and 2.4 - I haven't put 2.5 onto my box yet) implementation of
> unicodedata disagrees, presumably for good reason.
> 
> I can't see where I'm going wrong.

You might not be wrong at all. CPython has a hard-coded list for the
numeric mapping (see Object/unicodectype.c), and that hadn't been
updated even when the rest of the character database was updated.
Patch #1494554 corrected this and updated the numeric properties to
Unicode 4.1, for Python 2.5.

There is still a patch pending generating this function, instead
of maintaining it manually.

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


Re: JIT (just-in-tme accelerator) for Python - exists or no?

2007-02-22 Thread bearophileHUGS
On Feb 22, 7:04 pm, [EMAIL PROTECTED] wrote:
> Or is any progress going on now?
> The JIT in MATLAB or Java seems to be very effective.

Have you tried Psyco?
Other progress is probably in the PyPy field too.

Bye,
bearophile

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


Re: Possible to set cpython heap size?

2007-02-22 Thread Diez B. Roggisch
Andy Watson wrote:

>  > Why do you want that? And no, it is not possible. And to be honest:
> I have
>> no idea why e.g. the JVM allows for this.
> 
> The reason why is simply that I know roughly how much memory I'm going
> to need, and cpython seems to be taking a fair amount of time
> extending its heap as I read in content incrementally.

I'm not an expert in python malloc schemes, I know that _some_ things are
heavily optimized, but I'm not aware that it does some clever
self-management of heap in the general case. Which would be complicated in
the presence of arbitrary C extensions anyway.


However, I'm having doubts that your observation is correct. A simple

python -m timeit -n 1 -r 1 "range(5000)"
1 loops, best of 1: 2.38 sec per loop

will create a python-process of half a gig ram - for a split-second - and I
don't consider 2.38 seconds a fair amount of time for heap allocation.

When I used a 4 times larger argument, my machine began swapping. THEN
things became ugly - but I don't see how preallocation will help there...

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread Jeff McNeil

Or perhaps...


ord ("a")

97

chr (97)

'a'






On 2/22/07, hg <[EMAIL PROTECTED]> wrote:


John wrote:

> Is there any built in function that converts ASCII to integer or vice
> versa in Python?
>
> Thanks!
>>> int('10')
10
>>> str(10)
'10'
>>>

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

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

Re: Possible to set cpython heap size?

2007-02-22 Thread Irmen de Jong
Andy Watson wrote:
>  > Why do you want that? And no, it is not possible. And to be honest:
> I have
>> no idea why e.g. the JVM allows for this.
>>
>> Diez
> 
> The reason why is simply that I know roughly how much memory I'm going
> to need, and cpython seems to be taking a fair amount of time

^
> extending its heap as I read in content incrementally.

First make sure this is really the case.
It may be that you are just using an inefficient algorithm.
In my experience allocating extra heap memory is hardly ever
noticeable. Unless your system is out of physical RAM and has
to swap.

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread John
I just found ord(c), which convert ascii to integer.

Anybody know what the reverse is?

"John" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is there any built in function that converts ASCII to integer or vice
versa
> in Python?
>
> Thanks!
>
>


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


JasperServer

2007-02-22 Thread batok
JasperServer is a report engine ( java based ).  It has a soap
interface.  Does anybody has used Jasperserver via Soap ?

An example would be appreciated.

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread Lloyd Zusman
"John" <[EMAIL PROTECTED]> writes:

> I just found ord(c), which convert ascii to integer.
>
> Anybody know what the reverse is?

The inverse of "ord" is "chr":

  % python
  Python 2.5 (r25:51908, Jan  5 2007, 00:12:45) 
  [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> ord('i')
  105
  >>> chr(105)
  'i'
  >>>

IIRC, the first use of the names "ord" and "chr" for these functions
appeared in the Basic language in the 1960's ... in case anyone is
interested in this bit of historical trivia.


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread Larry Bates
John wrote:
> I just found ord(c), which convert ascii to integer.
> 
> Anybody know what the reverse is?
> 
> "John" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Is there any built in function that converts ASCII to integer or vice
> versa
>> in Python?
>>
>> Thanks!
>>
>>
> 
> 
The phrasing of your question threw us all.  What you want is chr

backslash=chr(92)

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


Re: export an array of floats to python

2007-02-22 Thread sturlamolden
On Feb 22, 5:40 pm, Peter Wuertz <[EMAIL PROTECTED]>
wrote:

> I'm writing a C module for python, that accesses a special usb camera.
> This module is supposed to provide python with data (alot of data). Then
> SciPy is used to fit the data.
>
> My question is, how to make python read from a C array? By reading the
> documentation, one could get the impression that PyBufferObjects do that
> job.

Never mind the buffer object.

Since you use SciPY I assume you want to wrap your C array with a
NumPy array. This can be accomplished using the API call:

PyObject *PyArray_SimpleNewFromData(int nd, npy_intp* dims, int
typenum, void* data);

nd is the number of dimensions.
dims is an array of length nd containing the size in each dimension.
typenum can e.g. be NPY_FLOAT, NPY_DOUBLE, NPY_BYTE, NPY_UBYTE,
NPY_INT, NPY_UINT, NPY_SHORT, NPY_USHORT, etc.

Don't deallocate the data buffer until the NuPy array is deleted.

Otherwise, you could create a new array from scratch using:

PyObject *PyArray_SimpleNew(int nd, npy_intp* dims, int typenum);

Then, use

void *PyArray_DATA(PyObject* obj);

to get a pointer to the data buffer. Then fill in (e.g. memcpy)
whatever you have from your camera.

If you e.g. have unsigned integers from the camera and want to cast
them into Python floats:

unsigned int *camera_buffer = ... /* whatever */
npy_int dim = {480, 640}; /* whatever the size of your data, in C-
order */
PyObject *myarray;
double *array_buffer;
int i;
myarray = PyArray_SimpleNew(2, &dim, NPY_DOUBLE);
Py_INCREF(myarray);
array_buffer = (double *)PyArray_DATA(myarray);
for (i=0; i<640*480; i++) *array_buffer++ = (double) *camera_buffer++;

Now return myarray and be happy.












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


Re: export an array of floats to python

2007-02-22 Thread sturlamolden
On Feb 22, 7:36 pm, "sturlamolden" <[EMAIL PROTECTED]> wrote:

> npy_int dim = {480, 640}; /* whatever the size of your data, in C-
> order */

oops...

npy_int dim[] = {480, 640};


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


American Expertise in Science and China, amazing good life at the end

2007-02-22 Thread stj911
http://www.newsreview.com/sacramento/Content?oid=oid%3A16418

Google search for Robert Hanson accidentally led to the amazing story
in the link above

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


Re: Possible to set cpython heap size?

2007-02-22 Thread Chris Mellon
On 22 Feb 2007 09:52:49 -0800, Andy Watson <[EMAIL PROTECTED]> wrote:
>  > Why do you want that? And no, it is not possible. And to be honest:
> I have
> > no idea why e.g. the JVM allows for this.
> >
> > Diez
>
> The reason why is simply that I know roughly how much memory I'm going
> to need, and cpython seems to be taking a fair amount of time
> extending its heap as I read in content incrementally.
>

To my knowledge, no modern OS actually commits any memory at all to a
process until it is written to. Pre-extending the heap would either a)
do nothing, because it'd be essentially a noop, or b) would take at
least long as doing it incrementally (because Python would need to
fill up all that space with objects), without giving you any actual
performance gain when you fill the object space "for real".

In Java, as I understand it, having a fixed size heap allows some
optimizations in the garbage collector. Pythons GC model is different
and, as far as I know, is unlikely to benefit from this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to covert ASCII to integer in Python?

2007-02-22 Thread Paul Rubin
"John" <[EMAIL PROTECTED]> writes:
> I just found ord(c), which convert ascii to integer.
> Anybody know what the reverse is?

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


  1   2   >