Re: Need Billy the Kid modul for windows

2006-07-07 Thread alex23
 There is a nice modul called BtK at
 http://home.student.utwente.nl/g.v.berg/btk/
 Has someone a link for btk-python on windows?

Hey spooky,

I haven't seen a Windows version of BtK anywhere.

Have you seen these alternative wrappers around libpcap? Could they
help you out?
* pylibpcap: http://pylibpcap.sourceforge.net/
* Pcapy: http://oss.coresecurity.com/projects/pcapy.html

There's also libdnet, which has Python bindings:
* libdnet: http://libdnet.sourceforge.net/

Hope this helps.

-alex23

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


Re: web app breakage with utf-8

2006-07-07 Thread Justin Ezequiel
replacing connection.character_set_name instance method seems to work
but is this the correct/preferred way?

 import MySQLdb
 MySQLdb.get_client_info()
'4.1.8'
 import sys
 sys.version
'2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]'
 sys.platform
'win32'
 cred = {'passwd': 'secret', 'host': 'myhost', 'db': 'mydb', 'user': 
 'justin'}
 insert = 'insert into unicodetest2 (foo) values (%s)'
 alpha = u'\N{GREEK SMALL LETTER ALPHA}'
 alpha
u'\u03b1'
 conn.close()
 conn = MySQLdb.connect(**cred)
 cur = conn.cursor()
 cur.execute(insert, 'a')
1L
 conn.commit()
 conn.close()
 conn = MySQLdb.connect(**cred)
 cur = conn.cursor()
 cur.execute(select)
1L
 cur.fetchall()
((9L, 'a'),)
 conn.close()
 conn = MySQLdb.connect(**cred)
 cur = conn.cursor()
 cur.execute(insert, alpha)
Traceback (most recent call last):
  File interactive input, line 1, in ?
  File E:\Python23\Lib\site-packages\MySQLdb\cursors.py, line 95, in
execute
return self._execute(query, args)
  File E:\Python23\Lib\site-packages\MySQLdb\cursors.py, line 114, in
_execute
self.errorhandler(self, exc, value)
  File E:\Python23\Lib\site-packages\MySQLdb\connections.py, line 33,
in defaulterrorhandler
raise errorclass, errorvalue
LookupError: unknown encoding: latin1_swedish_ci
 conn.close()
 conn = MySQLdb.connect(**cred)
 def character_set_name(*args, **kwargs): return 'utf-8'
...
 character_set_name()
'utf-8'
 conn.close()
 conn = MySQLdb.connect(**cred)
 conn.character_set_name()
'latin1_swedish_ci'
 import new
 conn.character_set_name = new.instancemethod(character_set_name, conn, 
 conn.__class__)
 conn.character_set_name()
'utf-8'
 cur = conn.cursor()
 cur.execute(insert, alpha)
1L
 conn.close()
 conn = MySQLdb.connect(**cred)
 conn.character_set_name()
'latin1_swedish_ci'
 cur = conn.cursor()
 cur.execute(select)
2L
 cur.fetchall()
((10L, '\xce\xb1'), (9L, 'a'))
 conn.close()
 conn = MySQLdb.connect(unicode='utf-8', **cred)
 conn.character_set_name()
'latin1_swedish_ci'
 cur = conn.cursor()
 cur.execute(select)
2L
 cur.fetchall()
((10L, u'\u03b1'), (9L, u'a'))
 conn.close()
 conn = MySQLdb.connect(**cred)
 cur = conn.cursor()
 cur.execute(select)
2L
 cur.fetchall()
((10L, '\xce\xb1'), (9L, 'a'))
 conn.close()


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


Re: How to increase the window sinze in python?

2006-07-07 Thread Fredrik Lundh
arvind wrote:

 i want to inctrease the window size in python and make it as big as
 normal window.
 at the same time i want to change the background colour of the screen.
 what's the solution?

what window is this ?

/F

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


Re: Python SOAP and XML-RPC performance extremely low?

2006-07-07 Thread Fredrik Lundh
Jack wrote:

 When I try TooFPy with the SOAP and XML-RPC sample client code
 provided in TooFPy tutorials, a log entry shows up quickly on web server
 log window, but it takes a long time (5 seconds or longer)

okay, 5 seconds...

 No, I'm not using any accelerator. The code is extremely simple (from 
 toofpy):
 
 # XML-RPC test
 import xmlrpclib
 srv = xmlrpclib.Server('http://localhost:4334/RPC2/greeting')
 print srv.greeting('you', 5)

and a 5 as the second argument in the greeting call.  I wonder what 
that does ? ;-)

(if you need a hint, look for waits the given number of seconds on 
this page:

http://pyds.muensterland.org/wiki/toolserverframeworkforpythonquickstartguide.html

)

/F

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


Help Needed !!! Browsing and Selecting More Than One File

2006-07-07 Thread Kilicaslan Fatih

Thank you very much for your indications. I've just
subscribed for the group and even I don't know how to
reply directly through mailing list. I will try to
answer some of the questions you have asked about my
program.

Question:
What has it to do with running your program with
several file names as arguments? Is it two different
ways to select several files in your application? Or
do you want one or the other?

Answer:
I want to browse, and want to select all of the *.c
files in a folder and than run  code analyzer
program for all of these files. The syntax to run 
on multiple files on DOS is:

 file1.c file2.c file3.c

I want to have 2 options on my GUI, one for only to
select one file, the other is to select multiple files
in a project(folder). 

I didn't yet change the code according to your
indications, there are still basic mistakes but I will
send the whole code, to be more clear. When I run this
code: 
I can browse a file and 
than open a file through the browser, 
assign it to  as parameter
and able to analyse one C file through a GUI

I can't select more than one file. I want to do this
because I will need to analyze the total project which
is composed of 8-15 *.c files.  

Source Code:

from Tkinter import *
from tkFileDialog import *
import tkMessageBox
import os


class App:

#Function for browsing a file
def browseFile(self):
global file
file = askopenfilename(filetypes = [(C source
code, *.c), (All Files, *.*)])
   
#Function for running  
def run(self, event):
if type(file)==str:
dosya = file
cmd = ' ' + dosya
print cmd
return os.system(cmd)
else:
message = tkMessageBox.showinfo(Window
Text, Please Browse a File Firstly)
  
def __init__(self, master):

frame = Frame(master)
frame.pack(fill=both)   

self.menubar = Menu(master)
self.menubar.add_command(label=Browse File,
command=self.browseFile)
master.config(menu=self.menubar)

self.Run = Button(frame, text=Run ,
fg=red)
self.Run.bind(Button-1, self.run)
self.Run.pack(side=LEFT, padx=10, pady=20)

self.close = Button(frame, text=QUIT,
fg=red, command=frame.quit)
self.close.pack(side=LEFT, padx=10, pady=20)

 
root = Tk()
app=App(root)
root.mainloop()

Best Regards,
Fatih K.




__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Solution for XML-RPC over a proxy

2006-07-07 Thread Laszlo Nagy
Andrew R írta:
 All,

 I couldn't get my xml-rpc script to work via a corporate proxy.

 I noticed a few posts asking about this, and a very good helper script by jjk 
 on
 starship. That script didn't work for me, and I think its a little old -- but 
 it
 was very helpful to figure it out.

 The below script is a replacement/update to the earlier work. It is runnable 
 as
 a test or usable as a module. Tests pass from behind and away from a proxy, on
 win32 and Linux i686, with Python 2.4.1.

 Comments welcome.
   
I believe you should also post this in the Python Cookbook.
-- 
http://mail.python.org/mailman/listinfo/python-list


switching users in cgi

2006-07-07 Thread s99999999s2003
hi
i am developing cgi script that read a unix user name and password,
After authentication, i need to switch the environment to that of that
user and display his/her files in her/his home directory. As my web
server runs as nobody , it cannot have access to files in the user's
home. What is a correct way to be able to achieve this?
thanks

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


Re: Need Billy the Kid modul for windows

2006-07-07 Thread spooky
Hey,

 Have you seen these alternative wrappers around libpcap? Could they
 help you out?
 * pylibpcap: http://pylibpcap.sourceforge.net/
 * Pcapy: http://oss.coresecurity.com/projects/pcapy.html

 There's also libdnet, which has Python bindings:
 * libdnet: http://libdnet.sourceforge.net/

 Hope this helps.

I Know the wrappers, but I think for packet creation like RAW-Packet the 
wrappers are not useful :( ?!? There is only the dpkt modul for windows 
and scapy and Billy the Kid for unix. Scray is too big for me :) an so I 
want to use the blk-modul. It is very easy to use, small and has great 
functions.

Is there a posibility to compile the package for windows??

Thanks for your help,

Spooky

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Fredrik Lundh
Antoon Pardon wrote:

 have any of your my mental model of how Python works is more important 
 than how it actually works ever had a point ?
 
 Be free to correct me. But just suggesting that I'm wrong doesn't help
 me in changing my mental model.

over the years, enough people have wasted enough time on trying to get 
you to understand how Python works, in various aspects.  if you really 
were interested in learning, you would have learned something by now, 
and you wouldn't keep repeating the same old misunderstandings over and 
over again.

/F

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Piet van Oostrum
 Terry Reedy [EMAIL PROTECTED] (TR) wrote:

TR Antoon Pardon [EMAIL PROTECTED] wrote in message 
TR news:[EMAIL PROTECTED]
 And if  Nested variables are harmfull,

TR I don't know if anyone said that they were, but Guido obviously does not 
TR think so, or he would not have added them.  So skip that.

I used that phrase (with correct spelling). I had supposed that it would
be recognised as a variation of 'Global variables considered harmful',
(William Wulf and Mary Shaw, ACM SIGPLAN Notices, 1973, 8 (2) pp. 28--34).
I think nested variables have the same troubles as global variables, so
they should be used with care.
-- 
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: Nested scopes, and augmented assignment

2006-07-07 Thread Piet van Oostrum
 Antoon Pardon [EMAIL PROTECTED] (AP) wrote:

AP Could you maybe clarify what problem we are discussing? All I wrote
AP was that with an assignment the search for the lefthand variable
AP depends on whether the lefthand side is a simple variable or
AP more complicated. 

What do you mean with `the lefthand variable'? Especially when talking
about `complicated lefthand sides'?

AP Sure people may prefer to speak about (re)binding
AP vs mutating variables, but just because I didn't use the prefered terms,
AP starting to doubt my understanding of the language, seems a bit
AP premature IMO. I'm sure there are areas where my understanding of
AP the language is shaky, metaclasses being one of them, but understanding
AP how names are searched doesn't seem to be one of them.

You didn't understand it in your OP. Maybe your understanding has gained in
the meantime?
-- 
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: Nested scopes, and augmented assignment

2006-07-07 Thread Fredrik Lundh
Antoon I'm no nincompoop, but I play one on the internet Pardon wrote:

 I don't see the contradiction. That Namespaces and names lookup are
 fundamentel parts of the Python language, doesn't mean that 
 the right behaviour can't be implemented in multiple ways and
 doesn't contradict that a specific explanation depend on a specific
 implementation instead of just on language definition.

the behaviour *is* defined in the language definition, and has nothing 
to do with a specific implementation.  have you even read the language
reference ?  do you even know that it exists ?

/F

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Fredrik Lundh
Piet van Oostrum wrote:

 There is no big difference I think. Only Python doesn't have syntax for the
 former. Older versions of Python didn't even have nested scopes.

arbitrarily nested scopes, at least.  the old local/global/builtin 
approach (the LGB rule) is of course a kind of nesting; the new thing is 
support for enclosing scopes in Python 2.1/2.2 (the LEGB rule).  for 
some background, see:

 http://www.python.org/dev/peps/pep-0227/

the section Rebinding names in enclosing scopes discusses the 2.X-
specific thinking; this may be revised in 3.0 (see current python-dev 
discussions).

/F

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


know reference name in instance

2006-07-07 Thread pipehappy
Hello:

Is it possible for an instance know its name used by other part of
program.  I mean like this:

class test:
def __init__(self):
pass

when some one writes

x = test()

then one of attribute of x contain the name x

Is it possible?

I expect someone can tell me how to do it.

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


Re: know reference name in instance

2006-07-07 Thread Fredrik Lundh
pipehappy wrote:

 Is it possible for an instance know its name used by other part of
 program.  I mean like this:
 
 class test:
 def __init__(self):
 pass
 
 when some one writes
 
 x = test()
 
 then one of attribute of x contain the name x
 
 Is it possible?

not really.

and what should happen if you do, say

x = test()
y = x

or

x = [test(), test(), test()]

?

for more on this, see:

http://pyfaq.infogami.com/how-can-my-code-discover-the-name-of-an-object

/F

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


Re: Solution for XML-RPC over a proxy

2006-07-07 Thread Stefan Krah
* Andrew R [EMAIL PROTECTED] wrote:
 All,
 
 I couldn't get my xml-rpc script to work via a corporate proxy.
 
 I noticed a few posts asking about this, and a very good helper script by jjk 
 on
 starship. That script didn't work for me, and I think its a little old -- but 
 it
 was very helpful to figure it out.
 
 The below script is a replacement/update to the earlier work. It is runnable 
 as
 a test or usable as a module. Tests pass from behind and away from a proxy, on
 win32 and Linux i686, with Python 2.4.1.
 
 Comments welcome.

No real comment, just to point out an alternative that works well for me:

http://docs.python.org/dev/lib/xmlrpc-client-example.html


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


Announcement : Octavia

2006-07-07 Thread sreekant
Hi folks

I just released a text to midi converter. Have a look at

http://sourceforge.net/projects/octavia

http://sourceforge.net/project/showfiles.php?group_id=171815

It uses a text description of music and runs the body of the music 
source file in python, leaving full facilities of python in your hands!

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


Re: Python SOAP and XML-RPC performance extremely low?

2006-07-07 Thread Jack
Ha! Thanks Fredrik for the big hint :) I wasn't careful when reading that 
page.
Was in too much of a hurry to try the code :)

 and a 5 as the second argument in the greeting call.  I wonder what that 
 does ? ;-)

 (if you need a hint, look for waits the given number of seconds on this 
 page:

 http://pyds.muensterland.org/wiki/toolserverframeworkforpythonquickstartguide.html

 )

 /F
 


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


Re: poplib Q

2006-07-07 Thread SuperHik
Neil Hodgson wrote:
 SuperHik:
 
 I did ofc, but I noticed something strange...
 *my* socket module really doesn't have SSL object,
 even tho it's listed in the documentation...
 (not the online docs, but docs that came with my Python version)
 ffs how can that be!
 
You are probably using ActiveState's distribution which doesn't 
 include SSL due to encryption regulations. The python.org distribution 
 does include SSL and you may be able to copy _ssl.pyd into the 
 ActiveState installation.
 
Neil

thank you!
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I thought I'd 'got' globals but...

2006-07-07 Thread meridian
Thanks Bruno. Not only do you give solutions to my problem but also
throw in great MVC tutorials too.
You're a gent.

I'm using
controller - A CherryPy app
views - Cheetah Templating for the html  data
model - mostly SQLite DB using pysqlite
also Config

It's only a desk-web app for single-user, so no concurrency issues.
However, taking on board your advice to avoid globals, I've now
realised that the info that I need to retain between pages can simply
be session information (for the only user) that can be initialised at
startup from the config.
So I'm looking at just storing it all in the cherrypy.session ram vs
using python globals.
Thanks again  Regards
Steve

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


multinormal distribution

2006-07-07 Thread TG
hi there.

I'm struggling with a function of numpy. Here it is :


import numpy as NP
mean = NP.array([0,0])
cov = NP.array([[1,0.25],[0.25,1]])
v = NP.random.multivariate_normal(mean,cov)

Quite simple code : it is supposed to generate an array of two random
values taken from a multinormal distribution, with respect to means and
covariance matrix given as parameters.

What happens on my computer is simple : it freezes ! I can't even stop
the process with ctrl-C in my python interpreter i have to kill it from
outside.

I'm running : 
- python 2.4.1
- numpy 0.9.8

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


How to increase the window sinze in python?

2006-07-07 Thread arvind
hi all,
i want to inctrease the window size in python and make it as big as
normal window.
at the same time i want to change the background colour of the screen.
what's the solution?

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


Re: Making a time series analysis package in python - advice or assistance sought

2006-07-07 Thread bearophileHUGS
Ray Tomes:
 My package will have the following capabilities:
 1. Able to read time series data in a variety of formats.
 2. Able to create, manipulate and save time series files.
 3. Able to do vector arithmetic on time series, including
 dozens of functions.
 4. Loop and macro facilities to simplify repetitive stuff.
 5. Flexible high-resolution graphic presentation.
 6. Built in functions to include:
 FFT / fourier analysis, MESA / maximum entropy spectral analysis,
 multiple regression, canonical correlation etc etc etc.
 I have code for all these mostly in FORTRAN, some QBASIC.

It seems quite doable. Beside doing vector arithmetic with SciPy, and
plotting/generating graphs with MatPlotLib, you may need a GUI toolkit,
like Tkinter (built-in), wxpython, etc:
http://pythoncard.sourceforge.net/
http://www.wxpython.org/
etc.

Designing good GUIs requires some time.

The Loop and macro facilities can be done in Python itself.

To use Fortran from Python:
http://cens.ioc.ee/projects/f2py2e/

Bye,
bearophile

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Bruno Desthuilliers
Antoon Pardon wrote:
 On 2006-07-06, Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 
Antoon Pardon wrote:

On 2006-07-05, Piet van Oostrum [EMAIL PROTECTED] wrote:


It's not about finding a name/identifier, it's about the difference
between (re)binding a name and mutating an object.

AP The two don't contradict each other. Python has chosen that it won't
AP rebind variables that are out of the local scope. So if the lefthand
AP side of an assignment is a simple name it will only search in the
AP local scope for that name. But if the lefthand side is more complicated
AP if will also search the outerscopes for the name.

Now it's pretty clear you *don't* understand.

In the second case, ie:

k = [0]
def f(i):
  k[0] += i

'k[0]' is *not* a name. The name is 'k'. If we rewrite this snippet
without all the syntactic sugar, we get something like:

k = [0]
def f(i):
  k.__setitem_(0, k.__getitem__(0) + i)

Now where do you see any rebinding here ?
 
 
 What point do you want to make? As far as I can see, I
 didn't write anything that implied I expected k to
 be rebound in code like

Please re-read your own writing above.

 
   k[0] += i
 
 So why are you trying so hard to show me this?
 

I was just expecting to be of any help, but it seems you just *refuse*
to understand.

No. It will always use the same search order.


So if I understand you correctly in code like:

  c.d = a
  b = a

All three names 

which ones ?


are searched for in all scopes between the local en global
one. 

In this example, we're at the top level, so the local scope is the
global scope. I assert what you meant was:
 
 
 I'm sorry I should have been more clear. I meant it to be 
 a piece of function code.
 
 
c = something
a = something_else

def somefunc():
  c.d = a
  b = a

(NB : following observations will refer to this code)


That is what I understand with your statement that [python] always
uses the same search order.

yes.


My impression was that python will search for c and a in the total current
namespace

what is the total current namespace ?


I still wait your explanation on this...

but will not for b.

b is bound in the local namespace, so there's no need to look for it in
enclosing namespaces.
 
 
 Now could you clarify please. First you agree with the statement that python
 always uses the same search order,

Yes : local namespace, then enclosing namespaces.

 then you state here there is no need
 to look for b because it is bound to local namespace. 

Yes. b being bound in the local namespace, it's found in the local
namespace, so lookup stops here. Pretty simple.

 That seems to
 imply that the search order for b is different.

cf above.


 AFAIR my original statement was that the search for b was different than
 the search for a;

And it's plain wrong, as anyone taking a few minutes reading the doc and
doing some tests would know.

 meaning that the search for b was limited to the local
 scope and this could be determined from just viewing a line like b = a
 within a function. The search for a (or c in a line like: c.d = a)
 is not limited to the local scope. 

Please repeat after me :
1/ binding in the local namespace makes the name local
2/ search order is local namespace first, then enclosing namespaces.

 I may see some interpretation where you may say that the search order
 for b is the same as for a and c

There's nothing to interpret here.

 but I still am not comfortable with
 it.

Too bad for you. But whether you are comfortable with reality is none
of my concern.

 
But a variable that is bound
inside the function (with an asignment) and is not declared global, is in
the local namespace.

 
Aren't we now talking about implementation details?

Certainly not. Namespaces and names lookup rules are fundamental parts
of the Python language.
 
 
 I don't see the contradiction. 

So go and get yourself some glasses.

 That Namespaces and names lookup are
 fundamentel parts of the Python language, doesn't mean that 
 the right behaviour

define right behaviour ?

 can't be implemented in multiple ways

I don't give a damn about how it's implemented.

 and
 doesn't contradict that a specific explanation depend on a specific
 implementation instead of just on language definition.
 

This is totally meaningless.

Sure the compilor
can set things up so that local names are bound to the local scope and
so the same code can be used. But it seems somewhere was made the
decision that b was in the local scope without looking for that b in
the scopes higher up.

binding creates a name in the current namespace. b is bound in the local
namespace, so b is local. period.
  
 I wrote nothing that contradicts that.

I give up. You're a crank.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Jack
I just did some testing between CherryPy's web server and lighttpd.
My test was very simple and I used ab.exe for this purpose.
CherryPy web server can serve about 140 simple request / second, while
lighttpd can handle around 400 concurrent requests.

 You haven't really said much about your requirements though.  Perhaps
 if you describe them in more detail (for example, what does high
 performance mean to you?) someone can make a more useful recommendation.

 Jean-Paul 


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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Bruno Desthuilliers
Piet van Oostrum wrote:
(snip)
 There is no big difference I think. Only Python doesn't have syntax for the
 former. Older versions of Python didn't even have nested scopes. maybe it
 was a mistake to add them.

Certainly not. Nested scopes allow closures, which allow decorators and
lot of *very* useful things. Remove this from Python, and you'll see a
*lot* of experimented programmers switch to another language.


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Bruno Desthuilliers
Antoon Pardon wrote:
 On 2006-07-06, Piet van Oostrum [EMAIL PROTECTED] wrote:
 
 
AP Aren't we now talking about implementation details? Sure the compilor
AP can set things up so that local names are bound to the local scope and
AP so the same code can be used. But it seems somewhere was made the
AP decision that b was in the local scope without looking for that b in
AP the scopes higher up.

Yes, as I (and others) have already said several times: an assignment to a
variable inside a function body (but not an assignment to an attribute or
part of an object) without a global declaration makes that variable a local
variable. That is not an implementation detail; it is part of the language 
definition.
 
 
 You seem to think I didn't understand this. 

And he's right, cf below.

(snip)

 Could you maybe clarify what problem we are discussing? All I wrote
 was that with an assignment the search for the lefthand variable
 depends on whether the lefthand side is a simple variable or
 more complicated.

You're obviously clueless. Which would not be a problem if you did not
refuse to first aknowledge the fact then take appropriate actions.

 Sure people may prefer to speak about (re)binding
 vs mutating variables, but just because I didn't use the prefered terms,

If you refuse to understand that there are pretty good reasons to use
the appropriate semantic, that's your problem, but then no one can help
you.

 starting to doubt my understanding of the language, seems a bit
 premature IMO.

I do not 'doubt', I'm 111% confident.

 I'm sure there are areas where my understanding of
 the language is shaky, metaclasses being one of them, but understanding
 how names are searched doesn't seem to be one of them.

It is, obviously.

And you're definitively a crank.

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Fredrik Lundh
Bruno Desthuilliers wrote:

 Certainly not. Nested scopes allow closures, which allow decorators and
 lot of *very* useful things.

decorators can be trivially implemented as classes, of course.  it's a 
bit unfortunate that many people seem to think that decorators *have* to 
be implemented as nested functions, rather than arbitrary callables.

/F

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


Re: I thought I'd 'got' globals but...

2006-07-07 Thread Bruno Desthuilliers
meridian wrote:
 Thanks Bruno. Not only do you give solutions to my problem but also
 throw in great MVC tutorials too.
 You're a gent.

(blush)

 I'm using
 controller - A CherryPy app
 views - Cheetah Templating for the html  data
 model - mostly SQLite DB using pysqlite
 also Config
 
 It's only a desk-web app for single-user, so no concurrency issues.

Err... I would not be so confident wrt/ this point. What about having
two browser windows opened on different pages of the app ?

 However, taking on board your advice to avoid globals, I've now
 realised that the info that I need to retain between pages can simply
 be session information (for the only user) that can be initialised at
 startup from the config.
 So I'm looking at just storing it all in the cherrypy.session ram vs
 using python globals.

Think this will be better !-)

But still, avoid overusing sessions - ie, don't make session available
to objects just for covenience when you can pass required data as params.

My 2 cents...

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: handling unicode data

2006-07-07 Thread Filipe

Dennis Lee Bieber wrote:
 If I interpret a short Google search, DB-Library might date back to
 the original Sybase core from which M$ SQL Server was spawned. M$'s site
 recommends /not/ using DB-Library but to use ODBC/OLEDB methods instead
 -- something about ODBC being extensible. Could be confusing if both
 Sybase and M$ SQL Server were on the same machine...

 http://www.cs.sfu.ca/CourseCentral/Software/Sybase/DB-LIBRARY/DB-LIBRARY.html

   Technical details reference Sybase, but the wordy stuff is SQL
 Server and Transact-SQL.

The only reason I still think Pymssql (and therefore, DB-Library) might
be the best option is that, it is the only one I know that is both
cross-platform and free - as in beer and as in freedom. (check, in this
thread, a previous message by Tim Golden)

I searched a bit if there are any OLEDB based python libs and found
this one:
http://pyoledb.datadmin.com/

I'm still not sure if it's cross-platform or not, but It does have a
commercial license, so it's not my first choice for now.

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


Re: know reference name in instance

2006-07-07 Thread pipehappy

Fredrik Lundh wrote:

 pipehappy wrote:

  Is it possible for an instance know its name used by other part of
  program.  I mean like this:
 
  class test:
  def __init__(self):
  pass
 
  when some one writes
 
  x = test()
 
  then one of attribute of x contain the name x
 
  Is it possible?

 not really.

 and what should happen if you do, say

 x = test()
 y = x

I may choose the name when the class is initialized, other may choose
the newest name. It depends.
 or

 x = [test(), test(), test()]

 ?
None may be the good answer here.

 for more on this, see:

 http://pyfaq.infogami.com/how-can-my-code-discover-the-name-of-an-object

 /F
Yes, You are right. But variety of condition is not necessary
prohibiting the promotion of such question but provides the possibility
for different answer. So is there some way I can ask the environment to
tell me the name? 

With respect, I read your words and it's great.

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


Re: setting variables from a tuple NEWB

2006-07-07 Thread Steven D'Aprano
On Thu, 06 Jul 2006 04:20:01 -0700, manstey wrote:

 Hi,
 
 If I have a tuple like this:
 
 tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh'))
 
 is it possible to write code using tupGlob that is equivalent to:
 VOWELS = 'aeiou'
 CONS = ''bcdfgh'

Why don't you just do that?

VOWELS = 'aeiou'
CONS = 'bcdfgh'

What benefit do you gain by stuffing your variables into tuples?



-- 
Steven.

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Antoon Pardon
On 2006-07-07, Piet van Oostrum [EMAIL PROTECTED] wrote:
 Antoon Pardon [EMAIL PROTECTED] (AP) wrote:

AP Could you maybe clarify what problem we are discussing? All I wrote
AP was that with an assignment the search for the lefthand variable
AP depends on whether the lefthand side is a simple variable or
AP more complicated. 

 What do you mean with `the lefthand variable'? Especially when talking
 about `complicated lefthand sides'?

The name on the left side of an assignment that refers to a variable,
as opposed to names that are attributes.

AP Sure people may prefer to speak about (re)binding
AP vs mutating variables, but just because I didn't use the prefered terms,
AP starting to doubt my understanding of the language, seems a bit
AP premature IMO. I'm sure there are areas where my understanding of
AP the language is shaky, metaclasses being one of them, but understanding
AP how names are searched doesn't seem to be one of them.

 You didn't understand it in your OP. Maybe your understanding has gained in
 the meantime?

I don't rule out that I gained some understanding without noticing it.
Maybe my choice of words was poor then.

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Antoon Pardon
On 2006-07-07, Fredrik Lundh [EMAIL PROTECTED] wrote:
 Antoon I'm no nincompoop, but I play one on the internet Pardon wrote:

 I don't see the contradiction. That Namespaces and names lookup are
 fundamentel parts of the Python language, doesn't mean that 
 the right behaviour can't be implemented in multiple ways and
 doesn't contradict that a specific explanation depend on a specific
 implementation instead of just on language definition.

 the behaviour *is* defined in the language definition, and has nothing 
 to do with a specific implementation.

As far as I can see I didn't write anything that contradicts this.
It is possible that at some point my choice of wording was bad
and that I gave the impression that i somehow wanted to contradict
this. If that happened my appologies.

 have you even read the language
 reference ?  do you even know that it exists ?

You mean this, I suppose:

http://docs.python.org/ref/naming.html

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Antoon Pardon
On 2006-07-07, Fredrik Lundh [EMAIL PROTECTED] wrote:
 Antoon Pardon wrote:

 have any of your my mental model of how Python works is more important 
 than how it actually works ever had a point ?
 
 Be free to correct me. But just suggesting that I'm wrong doesn't help
 me in changing my mental model.

 over the years, enough people have wasted enough time on trying to get 
 you to understand how Python works, in various aspects.  if you really 
 were interested in learning, you would have learned something by now, 
 and you wouldn't keep repeating the same old misunderstandings over and 
 over again.

May be I misunderstand, maybe I sometimes have difficulties making my self
clear. If you already made up your mind which is it, that is fine by me.
I just don't see the point of just posting a response that just
boils down to: You are wrong. Even if you have given up on me, others
might be helped if you took the trouble of explainig what was wrong.

Well, that was just what I was thinking. 

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


Re: Making a time series analysis package in python - advice or assistance sought

2006-07-07 Thread beliavsky
Ray Tomes wrote:
 Hi Folks

 I am an old codger who has much experience with computers
 in the distant past before all this object oriented stuff.
 Also I have loads of software in such languages as FORTRAN
 and BASIC, QBASIC etc that is very useful except that it
 really doesn't like to run on modern operating systems and
 has hopeless graphics resolution and lack of ease of use in
 some ways.

The Fortran code, which I assume is Fortran 77 or earlier, should run
fine on modern operating systems using free (g77, g95, or gfortran)
or commercial compilers.

 My desire is to get all the facilities available in my
 old programs working in a modern platform with flexible
 and high-res graphics and easy to use. Ideally I might
 find some good coders that are interested in the subject
 who would assist me, alternatively some help in getting
 started because there is so much info and so many resources
 and libraries etc that I don't know where to start.

 My package will have the following capabilities:
 1. Able to read time series data in a variety of formats.
 2. Able to create, manipulate and save time series files.
 3. Able to do vector arithmetic on time series, including
 dozens of functions.

Fortran 90 and later versions have array operations, as does NumPy. You
could convert parts of the FORTRAN code to F90

 4. Loop and macro facilities to simplify repetitive stuff.
 5. Flexible high-resolution graphic presentation.
 6. Built in functions to include:
 FFT / fourier analysis, MESA / maximum entropy spectral analysis,
 multiple regression, canonical correlation etc etc etc.
 I have code for all these mostly in FORTRAN, some QBASIC.

 The applications of the package include:
 1. Analysis of time series data from many branches of science.
 2. Economic / business models including forecasting.
 3. Markets, stocks, commodities forecasting.
 4. Interdisciplinary causal analysis.
 5. Many more

There exist public domain codes for many of the topics you mention, and
I think several are part of NumPy. Many statistical algorithms are in
R, for which the underlying C and Fortran code is available. I suggest
that you identify which of your algorithms are not publicly available
and focus on those, making an R package of them. I am interested in
MESA. Then you can exploit the R graphics and language (called S) and
have your work easily accessible to many users.

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


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Tim Williams
On 07/07/06, Jack [EMAIL PROTECTED] wrote:
 I just did some testing between CherryPy's web server and lighttpd.
 My test was very simple and I used ab.exe for this purpose.
 CherryPy web server can serve about 140 simple request / second, while
 lighttpd can handle around 400 concurrent requests.

  You haven't really said much about your requirements though.  Perhaps
  if you describe them in more detail (for example, what does high
  performance mean to you?) someone can make a more useful recommendation.
 

Karrigell has an async server, in standalone mode it won't be as fast
as lighttpd but its simpler to use and code in than cherrypy.
However, it can also work behind lighttpd,  so you might get a good
mix of server speed and fast development time.

http://www.karrigell.com

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


COM Makepy Question

2006-07-07 Thread gregarican
Using Pythonwin's COM Makepy utility I created a COM wrapper around an
OCX file that's used to communicate with a magstripe card reader. The
wrapper was created without incident and I can invoke any get type of
method without a problem. But whenever I attempt to invoke any of the
set type of methods I receive an error message that states:

(-2147352567, 'Exception occurred.', (0, 'ctlUSBHID', 'Client
Site not available', None, 1000398, -2146827890), None)

Googling around I see that this error message indicates an ActiveX
control that's being referenced without residing within a container.
Not sure if this is something that I can fix myself within the Makepy
COM wrapper or if I have to rely on the vendor shipping an updated OCX
file. I did see a Python discussion thread where someone else ran into
a similar problem and had to wait for the vendor to ship a revised OCX
file.

Dolphin Smalltalk has a similar COM wrapper utility and the same exact
error occurs. The OCX file is ideally suited for Visual Basic but I
don't have that compilation environment setup on my workstation to try
out.

Anyone familiar with such matters? I have contacted the vendor to try
to initiate things on that end. But if there's something I can do to
circumvent that route using Python I'd give it a go.

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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Bruno Desthuilliers
Fredrik Lundh wrote:
 Bruno Desthuilliers wrote:
 
 Certainly not. Nested scopes allow closures, which allow decorators and
 lot of *very* useful things.
 
 
 decorators can be trivially implemented as classes, of course.  it's a
 bit unfortunate that many people seem to think that decorators *have* to
 be implemented as nested functions, rather than arbitrary callables.

Your of course right - and I should know better since AFAIK (IOW please
correct me if I'm wrong), closures and classes are somewhat
interchangeable.

OTHO, using closures can make things far more simple - just like having
functions being objects is not absolutely necessary for having HOF-like
features, but can make HOF much more simple. If you take back all these
kind of features from Python, you end up with something that's not
really better than Java - and then me run away screaming !-)

Thanks for the correction anyway.
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Gerard Flanagan

Tim Williams wrote:
 On 07/07/06, Jack [EMAIL PROTECTED] wrote:
  I just did some testing between CherryPy's web server and lighttpd.
  My test was very simple and I used ab.exe for this purpose.
  CherryPy web server can serve about 140 simple request / second, while
  lighttpd can handle around 400 concurrent requests.
 
   You haven't really said much about your requirements though.  Perhaps
   if you describe them in more detail (for example, what does high
   performance mean to you?) someone can make a more useful recommendation.
  

 Karrigell has an async server, in standalone mode it won't be as fast
 as lighttpd but its simpler to use and code in than cherrypy.
 However, it can also work behind lighttpd,  so you might get a good
 mix of server speed and fast development time.

 http://www.karrigell.com


Yes, agree about Karrigell's quick development time - an almost flat
learning curve if you've programmed for the web before, and none of the
arcana which you can run into  elsewhere.

high performance? - I'm using it to provide an intranet for a small
library with *three* networked computers - performance is impeccable!

Gerard

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


Re: multithreading and shared dictionary

2006-07-07 Thread placid

Stéphane Ninin wrote:
 Hello,

 Probably a stupid question, but I am not a multithreading expert...

 I want to share a dictionary between several threads.
 Actually, I will wrap the dictionary in a class
 and want to protect the sensitive accesses with locks.

 The problem is I am not sure which concurrent access to the dictionary
 could cause a problem.

 I assume that two write's on the same location would be,
 but what if one thread does

 mydict['a'] = something

  and another thread:

 mydict['b'] = something else

 Is a lock required in such a case ?

i dont think you need to use a lock for these cases because mydict['a']
refers to mydict['b'] memory locations (i may be wrong because i dont
know Python implementation).

Just a recomendation, you could also use a Queue object to control
write access to the dictionary.

-Cheers

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


Re: wxPython and Linux dependencies

2006-07-07 Thread Frithiof Andreas Jensen

[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Error message cannot find wx

 infact I have wxpython in /usr/lib/

 I installed it using the rpms given on the wxPython website. Do I
need
 to set some path or something.

I vaguely remember that wxWindows changed name to wxWidgets and
wxPython changed convention along the way so that one should do:

include wx  and reference wx stuff as wxdotsomething 

instead of the old way of:

from wxPython include * and reference as f.ex. wxDialog:

This is from memory, I cannot remember what version of wxPython the
change happened - but I was bitten by it.

Check the versions of wxPython on RedHat and Ubuntu - Ubuntu will
almost certainly be newer than RedHat!


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


Re: searching for strings (in a tuple) in a string

2006-07-07 Thread Steven D'Aprano
On Thu, 06 Jul 2006 04:45:35 -0700, manstey wrote:

 Hi,
 
 I often use:
 
 a='yy'
 tup=('x','yy','asd')
 if a in tup:
...
 
 but I can't find an equivalent code for:
 
 a='xfsdfyysd asd x'
 tup=('x','yy','asd')
 if tup in a:
 ...

Of course you can't. Strings don't contain tuples, since they are utterly
different kinds of objects.

 I can only do:
 
 if 'x' in a or 'yy' in a or 'asd' in a:
...
 
 but then I can't make the if clause dependent on changing value of tup.

Sure you can.

a = 'xfsdfyysd asd x'
tup = ('x','yy','asd')
for item in tup:
if item not in a:
print Item missing
break
else:
print All items found.

It's a little verbose, but you can stick it into a function definition and
use it as a one-liner.

Or, use a list comprehension:

a = 'xfsdfyysd asd x'
tup = ('x','yy','asd')
if [item for item in tup if item in a]:
print Some items found.
else:
print No items found.

Or, you can use filter:

a = 'xfsdfyysd asd x'
tup = ('x','yy','asd')
if filter(lambda item, a=a: item in a, tup):
print Some items found.
else:
print No items found.


However, keep in mind that in has a subtly different effect in strings
and tuples. 

x in (x, y) is true, but x in (xy, yy) is not, as you would
expect. However, the situation for strings isn't quite the same:
x in x y is true, but so is x in xx yy.

One way around that is to convert your string a into a list:

a = 'xfsdfyysd asd x'
a = a.split()  # split on any whitespace

and now your tests will behave as you expected.



-- 
Steven.

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


RE: COM Makepy Question

2006-07-07 Thread Stefan Schukat
It seems that the ocx only works in a GUI environment. Perhaps you could
try to embed
the ocx in a pythonwin dialog which you create invisible since the
dialog is then 
a control container

see Python24\Lib\site-packages\pythonwin\pywin\Demos\ocx\ocxtest.py

Stefan

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On 
 Behalf Of gregarican
 Sent: Friday, July 07, 2006 1:37 PM
 To: python-list@python.org
 Subject: COM Makepy Question
 
 Using Pythonwin's COM Makepy utility I created a COM wrapper 
 around an OCX file that's used to communicate with a 
 magstripe card reader. The wrapper was created without 
 incident and I can invoke any get type of method without a 
 problem. But whenever I attempt to invoke any of the set 
 type of methods I receive an error message that states:
 
 (-2147352567, 'Exception occurred.', (0, 'ctlUSBHID', 'Client 
 Site not available', None, 1000398, -2146827890), None)
 
 Googling around I see that this error message indicates an 
 ActiveX control that's being referenced without residing 
 within a container.
 Not sure if this is something that I can fix myself within 
 the Makepy COM wrapper or if I have to rely on the vendor 
 shipping an updated OCX file. I did see a Python discussion 
 thread where someone else ran into a similar problem and had 
 to wait for the vendor to ship a revised OCX file.
 
 Dolphin Smalltalk has a similar COM wrapper utility and the 
 same exact error occurs. The OCX file is ideally suited for 
 Visual Basic but I don't have that compilation environment 
 setup on my workstation to try out.
 
 Anyone familiar with such matters? I have contacted the 
 vendor to try to initiate things on that end. But if there's 
 something I can do to circumvent that route using Python I'd 
 give it a go.
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Steven D'Aprano
On Thu, 06 Jul 2006 03:34:32 -0700, manstey wrote:

 Hi,
 
 I have a text file called a.txt:
 
 # comments
 [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
 [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})]
 [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})]
 
 I read it using this:
 
 filAnsMorph = codecs.open('a.txt', 'r', 'utf-8') # Initialise input
 file
 dicAnsMorph = {}
 for line in filAnsMorph:
 if line[0] != '#': # Get rid of comment lines
 x = eval(line)
 dicAnsMorph[x[0][1]] = x[1][1] # recid is key, parse dict is
 value
 
 But it crashes every time on x = eval(line). Why is this?

Some people have incorrectly suggested the solution is to remove the
newline from the end of the line. Others have already pointed out one
possible solution.

I'd like to ask, why are you using eval in the first place?

The problem with eval is that it is simultaneously too finicky and too
powerful. It is finicky -- it has problems with lines ending with a
carriage return, empty lines, and probably other things. But it is also
too powerful. Your program wants a specific piece of data, but eval
will accept any string which is a valid Python expression. eval is quite
capable of giving you a dictionary, or an int, or just about anything --
and, depending on your code, you might not find out for a long time,
leading to hard-to-debug bugs. 

Is your data under your control? Could some malicious person inject data
into your file a.txt? If so, you should be aware of the security
implications:

# comment
[('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
[('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})]
# line injected by a malicious user
__import__('os').system('echo if I were bad I could do worse')
[('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})]

Now, if the malicious user can only damage their own system, maybe you
don't care -- but the security hole is there. Are you sure that no
malicious third party, given *only* write permission to the file a.txt,
could compromise your entire system?

Personally, I would never use eval on any string I didn't write myself. If
I was thinking about evaluating a user-string, I would always write a
function to parse the string and accept only the specific sort of data I
expected. In your case, a quick-and-dirty untested function might be:

def parse(s):
Parse string s, and return a two-item list like this:

[tuple(string, integer), tuple(string, dict(string: string)]


def parse_tuple(s):
Parse a tuple with two items exactly.
s = s.strip()
assert s.startswith(()
assert s.endswith())
a, b = s[1:-1].split(,)
return (a.strip(), b.strip())

def parse_dict(s):
Parse a dict with two items exactly.
s = s.strip()
assert s.startswith({)
assert s.endswith(})
a, b = s[1:-1].split(,)
key1, value1 = a.strip().split(:)
key2, value2 = b.strip().split(:)
return {key1.strip(): value1.strip(), key2.strip(): value2.strip()}

def parse_list(s):
Parse a list with two items exactly.
s = s.strip()
assert s.startswith([)
assert s.endswith(])
a, b = s[1:-1].split(,)
return [a.strip(), b.strip()]

# Expected format is something like:
# [tuple(string, integer), tuple(string, dict(string: string)]
L = parse_list(s)
T0 = parse_tuple(L[0])
T1 = parse_tuple(L[1])
T0 = (T0[0], int(T0[1]))
T1 = (T1[0], parse_dict(T1[1]))
return [T0, T1]


That's a bit more work than eval, but I believe it is worth it.

-- 
Steven

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


Re: COM Makepy Question

2006-07-07 Thread gregarican
Gotcha. That makes perfect sense looking at the container references
others made during my Googling adventures. Thanks!

Stefan Schukat wrote:
 It seems that the ocx only works in a GUI environment. Perhaps you could
 try to embed
 the ocx in a pythonwin dialog which you create invisible since the
 dialog is then
 a control container

 see Python24\Lib\site-packages\pythonwin\pywin\Demos\ocx\ocxtest.py

   Stefan

  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED] On
  Behalf Of gregarican
  Sent: Friday, July 07, 2006 1:37 PM
  To: python-list@python.org
  Subject: COM Makepy Question
 
  Using Pythonwin's COM Makepy utility I created a COM wrapper
  around an OCX file that's used to communicate with a
  magstripe card reader. The wrapper was created without
  incident and I can invoke any get type of method without a
  problem. But whenever I attempt to invoke any of the set
  type of methods I receive an error message that states:
 
  (-2147352567, 'Exception occurred.', (0, 'ctlUSBHID', 'Client
  Site not available', None, 1000398, -2146827890), None)
 
  Googling around I see that this error message indicates an
  ActiveX control that's being referenced without residing
  within a container.
  Not sure if this is something that I can fix myself within
  the Makepy COM wrapper or if I have to rely on the vendor
  shipping an updated OCX file. I did see a Python discussion
  thread where someone else ran into a similar problem and had
  to wait for the vendor to ship a revised OCX file.
 
  Dolphin Smalltalk has a similar COM wrapper utility and the
  same exact error occurs. The OCX file is ideally suited for
  Visual Basic but I don't have that compilation environment
  setup on my workstation to try out.
 
  Anyone familiar with such matters? I have contacted the
  vendor to try to initiate things on that end. But if there's
  something I can do to circumvent that route using Python I'd
  give it a go.
  
  --
  http://mail.python.org/mailman/listinfo/python-list
 

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


Re: wxPython and Linux dependencies

2006-07-07 Thread John Salerno
Nick Vatamaniuc wrote:

 To see where Python is looking for libraries open an interactive Python
 prompt and type
 import sys
 print sys.path

After doing this you will see something like

'C:\\Python24\\lib\\site-packages\\wx-2.6-msw-ansi' (from my system)

in the list, otherwise it isn't finding wxPython. Also, probably just 
looking at the version of Python you are using when the interactive 
prompt starts up might give you a clue. If it's different than the 
version you installed wxPython in, then that's why it isn't finding it. 
(But I don't know if the version that the interactive prompt uses is 
necessarily the version that will be used to run your program, assuming 
you have multiple versions installed, so maybe these methods won't be 
perfectly accurate. Not sure how it gets decided which version to use if 
you have more than one, especially on Unix systems.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to increase the window sinze in python?

2006-07-07 Thread John Salerno
Fredrik Lundh wrote:
 arvind wrote:
 
 i want to inctrease the window size in python and make it as big as
 normal window.
 at the same time i want to change the background colour of the screen.
 what's the solution?
 
 what window is this ?
 
 /F
 

and what does as big as a normal window mean? :) that might depend on 
the OS, too
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Tim Williams
On 7 Jul 2006 06:27:43 -0700, Gerard Flanagan [EMAIL PROTECTED] wrote:

 Tim Williams wrote:
  On 07/07/06, Jack [EMAIL PROTECTED] wrote:
   I just did some testing between CherryPy's web server and lighttpd.
   My test was very simple and I used ab.exe for this purpose.
   CherryPy web server can serve about 140 simple request / second, while
   lighttpd can handle around 400 concurrent requests.
  
You haven't really said much about your requirements though.  Perhaps
if you describe them in more detail (for example, what does high
performance mean to you?) someone can make a more useful 
recommendation.
   
 
  Karrigell has an async server, in standalone mode it won't be as fast
  as lighttpd but its simpler to use and code in than cherrypy.
  However, it can also work behind lighttpd,  so you might get a good
  mix of server speed and fast development time.
 
  http://www.karrigell.com
 

 Yes, agree about Karrigell's quick development time - an almost flat
 learning curve if you've programmed for the web before, and none of the
 arcana which you can run into  elsewhere.

 high performance? - I'm using it to provide an intranet for a small
 library with *three* networked computers - performance is impeccable!

If you disable the Reverse-DNS lookups in one of the python (not
Karrigell) web modules (I'll dig out a previous post somewhere about
this),  it speeds up karrigell tremendously,  my apps aren't huge,
but I have no problems with karrigell across   the internet :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Browser Pygame Plug-in?

2006-07-07 Thread Gregory Piñero
Are there security issues too?  Would you remove potentially harmful
Python libraries for the plugin, not allow system calls, etc?  Would
you only allow file system access in one area?

I guess you'd just copy however Java applets work?  But run faster ;-)


On 7/7/06, Shane Hathaway [EMAIL PROTECTED] wrote:
 Gregory Piñero wrote:
  I was just idley curious on what it would take to make a web plug-in
  for Pygame.  I'm picturing it working the way my browser currently
  shows flash games.  Is such an idea even possible?  Has anyone
  attempted this?

 I once played with a similar idea.  Yes, it's possible, although
 platform differences make the idea non-trivial.

 Specifically, I ran into difficulty when I discovered that it's not easy
 on Linux to load a dynamic library (such as libpython.so) which in turn
 loads other dynamic libraries (such as native Python modules), since the
 library search path is not modifiable at runtime.  A possible workaround
 is to launch a separate process which projects into the browser window.

 I don't know what surprises may pop up on other platforms.

 Shane



-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a time series analysis package in python - advice or assistance sought

2006-07-07 Thread Cameron Laird
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:
Ray Tomes wrote:
 Hi Folks

 I am an old codger who has much experience with computers
 in the distant past before all this object oriented stuff.
 Also I have loads of software in such languages as FORTRAN
 and BASIC, QBASIC etc that is very useful except that it
 really doesn't like to run on modern operating systems and
 has hopeless graphics resolution and lack of ease of use in
 some ways.

The Fortran code, which I assume is Fortran 77 or earlier, should run
fine on modern operating systems using free (g77, g95, or gfortran)
or commercial compilers.

 My desire is to get all the facilities available in my
 old programs working in a modern platform with flexible
 and high-res graphics and easy to use. Ideally I might
 find some good coders that are interested in the subject
 who would assist me, alternatively some help in getting
 started because there is so much info and so many resources
 and libraries etc that I don't know where to start.

 My package will have the following capabilities:
 1. Able to read time series data in a variety of formats.
 2. Able to create, manipulate and save time series files.
 3. Able to do vector arithmetic on time series, including
 dozens of functions.

Fortran 90 and later versions have array operations, as does NumPy. You
could convert parts of the FORTRAN code to F90

 4. Loop and macro facilities to simplify repetitive stuff.
 5. Flexible high-resolution graphic presentation.
 6. Built in functions to include:
 FFT / fourier analysis, MESA / maximum entropy spectral analysis,
 multiple regression, canonical correlation etc etc etc.
 I have code for all these mostly in FORTRAN, some QBASIC.

 The applications of the package include:
 1. Analysis of time series data from many branches of science.
 2. Economic / business models including forecasting.
 3. Markets, stocks, commodities forecasting.
 4. Interdisciplinary causal analysis.
 5. Many more

There exist public domain codes for many of the topics you mention, and
I think several are part of NumPy. Many statistical algorithms are in
R, for which the underlying C and Fortran code is available. I suggest
that you identify which of your algorithms are not publicly available
and focus on those, making an R package of them. I am interested in
MESA. Then you can exploit the R graphics and language (called S) and
have your work easily accessible to many users.


The original poster has received much good advice.  I'll reinforce
a couple of points:
1.  Flexibility, high usability, and appealing
graphics indeed are worth the effort.  They
can be achieved withOUT object orientation,
though, and you absolutely should consider
modernization of your existing *BASIC, 
Fortran, and so on.  Don't let lack of a
compiler block your progress; I'm sure we
can help locate appropriate ones for you.
2.  Python is indeed a great vehicle for this
sort of work, as I've argued in the past
URL: http://phaseit.net/claird/comp.programming/open_source_science.html .
For your particular circumstances, though,
I applaud Mr. Beliavsky's suggestion that
you look into R URL:
http://www-106.ibm.com/developerworks/linux/library/l-sc16.html .
You might get even quicker satisfaction,
with a somewhat lower long-term ceiling,
through Yorick URL: http://wiki.tcl.tk/yorick .

I understand that you were thinking in terms of enlistment of fellow
developers.  You might well be best off, though, with another round
of research and experimentation on your own.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML-RPC + SimpleHTTPServer question

2006-07-07 Thread jbrewer
Thank you very much, Fredrik.  Your code and suggestion worked
perfectly.  I haven't benchmarked the plain HTTP post vs Binary
wrapper, but strangely even using the naive Binary wrapper in Python
sends files much faster than how Java + Axis wraps byte arrays in SOAP
messages.

Jeremy

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


Re: wxPython and Linux dependencies

2006-07-07 Thread diffuser78
Let me explain and give you some more details.

When I type python at the command prompt it shows the following info.
python 2.3.4 (#Feb 01 2005), GCC 3.4.3 20041212  Red Hat 3.4.3-9.EL4 on
linux2


In /usr/lib/ there are two directories called python 2.3 and python 2.4

In /usr/lib/python2.3/site-packages I could NOT find anything related
to wx and in particular

wx-2.6-gtk2-unicode
wx.pth
wxversion.py
wxversion.pyc


In /usr/lib/python2.4/ there is only one folder called site-packages
and NO other files.

So /usr/lib/python2.4/site-packages/ has only one folder called
wx-2.6-gtk2-unicode and a file called  wx.pth and another file
wx.version.py (and its compiler version wx.version.pyc). wx.pth
contains wx-2.6-gtk2-unicode

So, what my feeling is that I have python 2.3 and wx package is for
2.4. So my installed variant cannot find the wx package.

What is the easiest way from this point on to get my small wxPython app
running ???

Every help is appreciated.



Nick Vatamaniuc wrote:
 John,
 To see where Python is looking for libraries open an interactive Python
 prompt and type
  import sys
  print sys.path
 You will get a list of paths where Python will look for modules. Also
 check to see if you have the PYTHONPATH environment variable set. If
 /usr/lib is not in the path list then Python won't be able to import wx
 from there. To test your wx app, you can append to sys.path the path of
 your wx module then try to import again.

 Hope this helps,
 Nick V.



 [EMAIL PROTECTED] wrote:
  How can we find that it is not using the right version of Python ?
 
  John Salerno wrote:
   [EMAIL PROTECTED] wrote:
Error message cannot find wx
   
infact I have wxpython in /usr/lib/
   
I installed it using the rpms given on the wxPython website. Do I need
to set some path or something.
  
   Could it be that it is trying to use another, pre-installed version of
   Python -- one which doesn't have wxPython installed with it?

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


Re: Web Browser Pygame Plug-in?

2006-07-07 Thread Gregory Piñero
Shane Wrote:
 Ah, so you also want to distribute untrusted Python code.  That's fairly
 hard.  There's a discussion about it on Python-Dev right now.

Well, I want to write a game in Pygame, and people can just go to my
website and play it within their browser.  I guess that would be
untrusted code?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Browser Pygame Plug-in?

2006-07-07 Thread Rob Knapp
On Thu, 2006-07-06 at 14:24 -0400, Gregory Piñero wrote:
 Hi guys,
 
 I was just idley curious on what it would take to make a web plug-in
 for Pygame.  I'm picturing it working the way my browser currently
 shows flash games.  Is such an idea even possible?  Has anyone
 attempted this?
 

At a previous position, I looked at this.  Not for a game but for
embedding our components in IE  Mozilla.

I started work on a Mozilla (this was pre-firefox) plugin that was based
on pyxpcom.  The company told me to stop development due to changing
business stuff, and I convinced them to release the non-working source.

However, I have since lost the source code.  It was a strange situation
as I wasn't allowed to start a sf project, and hosted the source on my
website. (they didn't want to be seen supporting open source if that
makes any sense...esp since the project was largely python based).
Unfortunately, sometime over the course of 2 web host changes and 1 move
from NC to PA I lost the source.  It might be available in a mailing
list archive of the pyxpcom list. (I make no claims of quality code,
this was during extra-special heavy duty start-up mode and I was getting
maybe 6 hours of downtime a day for meals, sleep and saying Hi to my
wife... so if you do manage to find the code, keep that in mind. :) )

It was not, as I recall, overly difficult at least conceptually since
most of the cross-platform hurdles were handled by pyxpcom.  Just follow
the examples in pyxpcom and in the netscape documentation to get a basic
plugin.  This would load a xpcom component and start it.  It was just a
matter of creating the pyxpcom component and that was it.  (Pushing
aside implementation details like getting pyxpcom installed on the
machine, and how the extent of the plugin's area gets passed in and a
bunch of other niggling little details.)

Mind you this was back in 2002, so my memory may be simplifying things
slightly, and there is always the chance that I was just flat out wrong
from beginning to end. :)   Also, I'd spent maybe 10 hours on the
project before I was told to stop, so who knows what issues might be
laying under the surface.  For example, getting the same concept to work
in IE ended up taking a great deal of development as we ended up using
trolltech's ActiveQT to wrap our components (which were already QT
classes).

At anyrate, I'm 90% certain that it can be done and think it's a rockin'
good idea.  I might return to it in future, as my new employer may have
a need, but that wouldn't be until at least next year, if not the year
after that.





 -- 
 Gregory Piñero
 Chief Innovation Officer
 Blended Technologies
 (www.blendedtechnologies.com)

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

Re: Launching multiple instances of a program with win32com.client.Dispatch?

2006-07-07 Thread tyler . schlosser
Hi Roger,

Thanks for the response, but DispatchEx seems to do the exact same
thing as Dispatch in my case; there is still only one processID and one
instance of my program (I forgot to mention that I also need two unique
processID's to keep track of them).

I have also tried:

###

AB1 =
pythoncom.CoCreateInstance(Broker.Application,None,pythoncom.CLSCTX_SERVER,pythoncom.IID_IDispatch)

AB2 =
pythoncom.CoCreateInstance(Broker.Application,None,pythoncom.CLSCTX_SERVER,pythoncom.IID_IDispatch)

win32com.client.Dispatch(AB1)
win32com.client.Dispatch(AB2)

###

That also seems to do the exact same thing.

Any other ideas of things I might try?

Roger Upole wrote:
 win32com.client.DispatchEx should create a new instance.

Roger

 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
  Hi there, I am trying to launch a program called AmiBroker using the
  command:
 
  AB = win32com.client.Dispatch(Broker.Application)
 
  However, I have a dual-core CPU and would like to launch two instances
  of AmiBroker. I know it is possible to run two instances simultaneously
  since it is easy to do manually by double-clicking the AmiBroker.exe
  file twice. However, when I write two lines of code like this:
 
  AB = win32com.client.Dispatch(Broker.Application)
  AB2 = win32com.client.Dispatch(Broker.Application)
 
  and proceed to address these objects, they interfere with each other
  since both AB and AB2 are grabbing the same instance of AmiBroker. If
  I try to run two separate Python scripts, each one containing a
  win32com.client.Dispatch(Broker.Application) comand, the same
  problem happens (where even though the objects are named differently,
  they do not each launch an instance of the program; the first one
  launches it and the second one just grabs it).
 
  Does anyone know how to force two separate program launches rather than
  having both Dispatch commands access the same object? I would be
  incredibly thankful to anyone who could offer some help with this.
 
  Thank you very much,
 
  Tyler
 

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


Re: Python SOAP and XML-RPC performance extremely low?

2006-07-07 Thread skip

Jack No, I'm not using any accelerator. The code is extremely simple
Jack (from toofpy):
...

To use sgmlop, just download and install it.  Your code doesn't need to
change.  The xmlrpclib module detects its presence and uses it
automatically.

As someone else noted though, a five-second delay for such a small example
doesn't seem to be an XML-RPC problem.  A simple round-trip to my XML-RPC
server running on the localhost takes about 5 *milli*seconds.  That's with
sgmlop installed, but even without it, I can't imagine it taking more than
50-100 ms.

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


Re: what's wrong here? (search script)

2006-07-07 Thread Michael Fisher
Brendan Fay wrote:
 I figured it out.  Is there any way to delete your own posts?
 
 Brendan Fay wrote:
 Dear Someone:

  I have written a script that accesses the googleAPI through
 pygoogle and saves each of the ten documents as a .txt file by using a
 specific function for each respective file type (.doc, .pdf, .html) to
 convert it to such.  Everything works fine, except that I am trying to
 make it search and return another result in the event that a file type
 other than .doc, .pdf, .html, or .txt comes up.  Python is new to me
 and I'm not sure why my method doesn't work.  I'd really appreciate any
 advice; here is the relevant code:

 def searchhelper(words, start=0, max=10):
  data = google.doGoogleSearch(words)
  objlist = data.results
  urllist = map((lambda x: x.URL), objlist)
  return urllist


 def searchhelper2(initwords, urls, counter):
  for url in urls:
  if findinlink(url, 'pdf'): # all these functions are defined
 elsewhere,
  convertpdf(url)  # fbut they definitely are working 
 properly
  elif findinlink(url, 'htm'):
  converthtml(url)
  elif findinlink(url, 'txt'):
  urllib.urlretrieve(url, parse(x))
  elif findinlink(url, 'doc'):
  convertdoc(url)
  elif not findinlink(url, '.'):
  converthtml(url)
  else:
  urllist = urls[counter + 1:] + searchhelper(initwords, 
 11 + counter,
 1) # (I'm
  searchhelper2(initwords, urllist, counter + 1)# 
 assuming this is
 where I have  #
   erred; however, I'm not sure)


 def search(initwords):
  urllist = searchhelper(initwords)
  searchhelper2(initwords, urllist, 0)

 Thanks,
 Brendan
 

Instead of deleting the previous post, you should post the solution for 
all to learn from.

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


Re: Python SOAP and XML-RPC performance extremely low?

2006-07-07 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 As someone else noted though, a five-second delay for such a small example
 doesn't seem to be an XML-RPC problem.  A simple round-trip to my XML-RPC
 server running on the localhost takes about 5 *milli*seconds.

even if the service you're connecting is waiting 5 seconds before it 
sends the response ? ;-)

/F

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


Re: Error type for shelve.open()

2006-07-07 Thread Simon Forman
[EMAIL PROTECTED] wrote:
 I tried what you said and it looked like maybe AttributeError, but that
 didn't work either.

 This code snippet:

 import shelve
 from traceback import format_exc

 try:
db = shelve.open(meh, r)
 except:
print format_exc()

 Gave me this output:
 Traceback (most recent call last):
   File test.py, line 5, in ?
 db = shelve.open(meh, r)
   File /usr/lib/python2.4/shelve.py, line 231, in open
 return DbfilenameShelf(filename, flag, protocol, writeback, binary)
   File /usr/lib/python2.4/shelve.py, line 212, in __init__
 Shelf.__init__(self, anydbm.open(filename, flag), protocol,
 writeback, binary)
   File /usr/lib/python2.4/anydbm.py, line 77, in open
 raise error, need 'c' or 'n' flag to open new db
 error: need 'c' or 'n' flag to open new db

 Exception exceptions.AttributeError: DbfilenameShelf instance has no
 attribute 'writeback' in  ignored

 Do you know what the error is?

No.  If you tried catching AttributeError and it didn't work then I'd
guess that the AttributeError is a secondary result of the initial
error.

This part of the traceback,

   File /usr/lib/python2.4/anydbm.py, line 77, in open
 raise error, need 'c' or 'n' flag to open new db
 error: need 'c' or 'n' flag to open new db

indicates that some sort of custom error, probably defined in the
anydbm.py module.

Catching the execption and binding it to a var,

 try:
... db = shelve.open(meh, r)
... except Exception, err:
... E = err
...
Exception exceptions.AttributeError: DbfilenameShelf instance has no
attribute 'writeback' in  ignored
 E
anydbm.error instance at 0xb7d8270c



So:
 from anydbm import error
 try:
... db = shelve.open(meh, r)
... except error:
... print 'Aha!  got it!'
...
Aha!  got it!
Exception exceptions.AttributeError: DbfilenameShelf instance has no
attribute 'writeback' in  ignored


Well, that catches the error, but I don't know what's going on with the
additional AttributeError or what to do about it.

Peace,
~Simon

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


how can I avoid abusing lists?

2006-07-07 Thread Thomas Nelson
I have this code:
type1 = [0]
type2 = [0]
type3 = [0]
map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}  # the real map is
longer than this

def increment(value):
map[value][0] += 1

increment(1)
increment(1)
increment(0)
increment(4)
#increment will actually be called many times through other functions
print type1[0], type2[0], type3[0]
#should print 3 1 0

This is exactly what I want to do: every time I encounter this kind of
value in my code, increment the appropriate type by one.  Then I'd like
to go back and find out how many of each type there were.  This way
I've written seems simple enough and effective, but it's very ugly and
I don't think it's the intended use of lists.  Does anyone know a
cleaner way to have the same funtionality?

Thanks,
THN

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Rob Cowie
Just forget the lists...

counters = {0:0, 1:0, 2:0, 3:0, 4:0}

def increment(value):
counters[value] += 1

increment(1)
increment(1)
increment(3)
increment(4)

print counters[0]
 0
print counters[1]
 2
print coutners[2]
 0
print counters[3]
 1
print coutners[4]
 1

The increment function should probably include a try:...except:
statement to catch KeyErrors that would arise if you passed a value
that is not a key in the counters dictionary.

Rob C

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


Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Ant

 [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
 [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})]
 # line injected by a malicious user
 __import__('os').system('echo if I were bad I could do worse')
 [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})]

I'm curious, if you disabled import, could you make eval safe?

For example:

 eval(__import__('os').system('echo if I were bad I could do worse'))
if I were bad I could do worse
0
 eval(__import__('os').system('echo if I were bad I could do worse'), 
 {'__import__': lambda x:None})
Traceback (most recent call last):
  File stdin, line 1, in ?
  File string, line 0, in ?
AttributeError: 'NoneType' object has no attribute 'system'

So, it seems to be possible to disable access to imports, but is this
enough? Are there other ways to access modules, or do damage via
built-in commands?

It seems that there must be a way to use eval safely, as there are
plenty of apps that embed python as a scripting language - and what's
the point of an eval function if impossible to use safely, and you have
to write your own Python parser!!

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


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Jack
I wrote the last posting at late late night and I didn't know what I was
typing at that time ;-p

I didn't mean the test with CherryPy was not concurrent
connections, or the test with lighttpd was all concurrent
connections. I actually tried both concurrent (-c in ab command line)
and non-concurrent (without -c in ab command line) and I tried
the threading and threadpooling in CherryPy. The result did not
vary much.

This article http://www.cherrypy.org/wiki/CherryPySpeed says CherryPy
can process around 400-500 requests/second. It's set up is:

  Pentium M 1.6, 1G RAM, Windows XP2 laptop, test done with apache 2.0.41 
ab.

I have a slightly better hardware set up:

  Pentium M 1.7MHz, 1.5G RAM on Windows XP2 laptop, test done with Apache 
2.2 ab

However, I don't get even close. The best I get is around 140
requests/second. I'm using the same test script as the CherryPy test
with slight modification just to make it run. As a matter of fact,
the Cygwin build of lighttpd only gets around 430 requests/second for
a 2-byte static file. I disabled firewall and antivirus on the box when
tests were done. Any idea about the huge difference? It would be very
interesting if some CherryPy (or python) users can post their performance
benchmarks.

Jack

Jack [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I just did some testing between CherryPy's web server and lighttpd.
 My test was very simple and I used ab.exe for this purpose.
 CherryPy web server can serve about 140 simple request / second, while
 lighttpd can handle around 400 concurrent requests.

 You haven't really said much about your requirements though.  Perhaps
 if you describe them in more detail (for example, what does high
 performance mean to you?) someone can make a more useful recommendation.

 Jean-Paul

 


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


Re: how can I avoid abusing lists?

2006-07-07 Thread Ant

Rob Cowie wrote:
 Just forget the lists...
 counters = {0:0, 1:0, 2:0, 3:0, 4:0}

Or perhaps just use a list:

 counters = [0,0,0,0]
 def inc(v):
...   counters[v] += 1
...
 inc(1)
 inc(1)
 inc(3)
 counters
[0, 2, 0, 1]

 The increment function should probably include a try:...except:

Likewise for IndexErrors

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


Publishing ODBC database content as PDF

2006-07-07 Thread vasudevram

Publishing ODBC database content as PDF:

A blog post by me on how to do this, using my PDF conversion toolkit,
xtopdf.
This is sample code from my next upcoming release of xtopdf, which will
support more input formats, such as CSV, XLS, TDV and ODBC data.

http://jugad.livejournal.com/2006/07/07/

Enjoy, and feedback welcome.
Vasudev

Vasudev Ram
http://www.geocities.com/vasudevram
PDF conversion toolkit:
http://sourceforge.net/projects/xtopdf


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


Re: Python SOAP and XML-RPC performance extremely low?

2006-07-07 Thread skip

 As someone else noted though, a five-second delay for such a small
 example doesn't seem to be an XML-RPC problem.  A simple round-trip
 to my XML-RPC server running on the localhost takes about 5
 *milli*seconds.

Fredrik even if the service you're connecting is waiting 5 seconds
Fredrik before it sends the response ? ;-)

Well, yeah I suppose that might have an effect. ;-) I saw your earlier
response about a minute after I responded...

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Simon Forman
Thomas Nelson wrote:
 I have this code:
 type1 = [0]
 type2 = [0]
 type3 = [0]
 map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}  # the real map is
 longer than this

 def increment(value):
   map[value][0] += 1

 increment(1)
 increment(1)
 increment(0)
 increment(4)
 #increment will actually be called many times through other functions
 print type1[0], type2[0], type3[0]
 #should print 3 1 0

 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.  Does anyone know a
 cleaner way to have the same funtionality?

 Thanks,
 THN

In this case, lists are unnecessary.  Just use ints.

Since your type codes are ints, you can create your map like this
(assuming 10 types):

map = dict((n, 0) for n in range(10))


Then your increment function becomes:

def increment(value):
map[value] += 1


And instead of,
print type1[0], type2[0], type3[0]

say,
print map[0], map[1], map[2]


Peace,
~Simon

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


Re: Publishing ODBC database content as PDF

2006-07-07 Thread vasudevram
Oops: The source indentation - tabs - is removed in the blog post, by
the LiveJournal software. You will need to insert them at the
appropriate places, for which you will need to know Python and
understand the code, at least the overall logic. I'll post the code as
a zip file (with some other samples) on one of my sites, and then put a
link to it here.

- Vasudev.

vasudevram wrote:
 Publishing ODBC database content as PDF:

 A blog post by me on how to do this, using my PDF conversion toolkit,
 xtopdf.
 This is sample code from my next upcoming release of xtopdf, which will
 support more input formats, such as CSV, XLS, TDV and ODBC data.

 http://jugad.livejournal.com/2006/07/07/

 Enjoy, and feedback welcome.
 Vasudev
 
 Vasudev Ram
 http://www.geocities.com/vasudevram
 PDF conversion toolkit:
 http://sourceforge.net/projects/xtopdf
 

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Tim Chase
 Just forget the lists...
 
 counters = {0:0, 1:0, 2:0, 3:0, 4:0}

You'll notice that the OP's code had multiple references to the 
same counter (0, 1, and 3 all mapped to type1)

The OP's method was about as good as it gets.  One might try to 
redo it with an accumulator class of some sort:

class Accumulator(object):
def __init__(self, startvalue = 0):
self.counter = startvalue
def __iadd__(self, qty):
self.counter += qty
return self.counter
def add(self, qty = 1):
self.counter += qty
def __int__(self):
return self.counter
def __str__(self):
return str(self.counter)
def __repr__(self):
return 'Accumulator 0x%x (%s)' % (
id(self), str(self.counter))

type1 = Accumulator()
type2 = Accumulator()
type3 = Accumulator()
d = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}

print ','.join([str(x) for x in d.values()])
# all zeros
d[0] += 1
print ','.join([str(x) for x in d.values()])
# d[0], d[1], and d[3] have incremented
d[2].add()
d[2].add()
print ','.join([str(x) for x in d.values()])
# d[2] has now incremented twice
d[4].add(5)
print ','.join([str(x) for x in d.values()])
# d[4] has now incremented by 5

Some of the syntactic sugar of the class could likely be left out 
if you just want, but it does the same thing as the OP's, with a 
diff. spin on the syntax.

-tkc






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


Re: how can I avoid abusing lists?

2006-07-07 Thread Justin Azoff
Thomas Nelson wrote:
 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.  Does anyone know a
 cleaner way to have the same funtionality?

 Thanks,
 THN

Just assign each type a number (type1 - 1, type2 - 2) and then count
the values as usual

def count(map, it):
d={}
for x in it:
x = map[x] #only difference from normal count function
#d[x]=d.get(x,0)+1
if x in d:
d[x] +=1
else:
d[x] = 1
return d

 map = {0:1, 1:1, 2:3, 3:1, 4:2}
 count(map, [1,1,0,4])
{1: 3, 2: 1}
 for x in count(map, [1,1,0,4]).items():
...  print 'type%d: %d' %x
... 
type1: 3
type2: 1

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Bruno Desthuilliers
Thomas Nelson wrote:
 I have this code:
 type1 = [0]
 type2 = [0]
 type3 = [0]
 map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}  

Warning : you're shadowing the builtin map() function.

 # the real map is
 longer than this
 
 def increment(value):
   map[value][0] += 1
 
 increment(1)
 increment(1)
 increment(0)
 increment(4)
 #increment will actually be called many times through other functions
 print type1[0], type2[0], type3[0]
 #should print 3 1 0
 
 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.

Not really.

  Does anyone know a
 cleaner way to have the same funtionality?


# first replace the list hack
class Counter(object):
def __init__(self, name, *keys):
self.name = name
self.keys = keys
self.count = 0

def inc(self):
self.count += 1

# now wrap the whole thing in a convenient way
class Counters(object):
def __init__(self, *counters):
self._counters = dict()
self._counters_map = dict()
for counter in counters:
assert counter.name not in self._counters
self._counters[counter.name] = counter
for key in counter.keys:
assert key not in self._counters_map
self._counters_map[key] = counter

def __getattr__(self, name):
return self._counters[name].count

def __getitem__(self, key):
return self._counters_map[key].count

def __call__(self, key):
self._counters_map[key].inc()

# and finally, let's use it:
increment = Counters(Counter(type1, 0, 1, 3),
 Counter(type2, 4),
 Counter(type3, 2)
 )

increment(1)
increment(1)
increment(0)
increment(4)

print increment.type1, increment.type2, increment.type3


HTH
-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Fredrik Lundh
Ant wrote:

 It seems that there must be a way to use eval safely, as there are
 plenty of apps that embed python as a scripting language - and what's
 the point of an eval function if impossible to use safely, and you have
 to write your own Python parser!!

embedding python != accepting scripts from anywhere.

/F

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


Re: how can I avoid abusing lists?

2006-07-07 Thread [EMAIL PROTECTED]

Thomas Nelson wrote:
 I have this code:
 type1 = [0]
 type2 = [0]
 type3 = [0]
 map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}  # the real map is
 longer than this

 def increment(value):
   map[value][0] += 1

 increment(1)
 increment(1)
 increment(0)
 increment(4)
 #increment will actually be called many times through other functions
 print type1[0], type2[0], type3[0]
 #should print 3 1 0

 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.  Does anyone know a
 cleaner way to have the same funtionality?

I usually do this:

 histogram = {}
 for i in range(1,7):
for j in range(1,7):
s = i + j
if histogram.has_key(s):
histogram[s] += 1
else:
histogram[s] = 1

 for i in histogram:
print i,histogram[i]

2 1
3 2
4 3
5 4
6 5
7 6
8 5
9 4
10 3
11 2
12 1

Note that only results actually encountered create dictionary
entries, so there is no result for index 0 or 1. 

 
 Thanks,
 THN

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


pyXLWriter - grid lines and if formula

2006-07-07 Thread Luis P. Mendes
Hi,

I know that pyExelerator is the supported project now, but I can't use
it because I'd need it to generate files from a web platform. Since I
can not save a file to a file-like object, I have to use pyXLWriter.

The problems are:
1- how to turn off/on the grid lines of each sheet?
2- I tried to build a simple 'if' formula but couldn't.  Is it my
problem or pyXLWriter's problem?  If the former, is it possible to post
an example?

TIA
Luis P. Mendes
-- 
http://mail.python.org/mailman/listinfo/python-list


IRC questions!!

2006-07-07 Thread bruce
hi...

i'm trying to figure out what i have to do to setup mIRC to get the #python
channel on IRC!!

any pointers. the mIRC docs didn't get me very far.

is there an irc.freenode.net that i need to connect to? how do i do it?

thanks..

-bruce

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


Re: How can I avoid abusing lists?

2006-07-07 Thread Klaus Alexander Seistrup
[EMAIL PROTECTED] wrote:

   if histogram.has_key(s):
   histogram[s] += 1
   else:
   histogram[s] = 1

I wonder if

histogram[s] = histogram.get(s, 0) + 1

would be more efficient...

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://ipsum.dk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval to dict problems NEWB going crazy !

2006-07-07 Thread Fredrik Lundh
Steven D'Aprano wrote:

 Personally, I would never use eval on any string I didn't write myself. If
 I was thinking about evaluating a user-string, I would always write a
 function to parse the string and accept only the specific sort of data I
 expected. In your case, a quick-and-dirty untested function might be:

for a more robust approach, you can use Python's tokenizer module, 
together with the iterator-based approach described here:

 http://online.effbot.org/2005_11_01_archive.htm#simple-parser-1

here's a (tested!) variant that handles lists and dictionaries as well:

 import cStringIO, tokenize

 def sequence(next, token, end):
out = []
token = next()
while token[1] != end:
out.append(atom(next, token))
token = next()
if token[1] == , or token[1] == ::
token = next()
return out

 def atom(next, token):
if token[1] == (:
return tuple(sequence(next, token, )))
elif token[1] == [:
return sequence(next, token, ])
elif token[1] == {:
seq = sequence(next, token, })
res = {}
for i in range(0, len(seq), 2):
res[seq[i]] = seq[i+1]
return res
elif token[0] in (tokenize.STRING, tokenize.NUMBER):
return eval(token[1]) # safe use of eval!
raise SyntaxError(malformed expression (%s) % token[1])

 def simple_eval(source):
src = cStringIO.StringIO(source).readline
src = tokenize.generate_tokens(src)
src = (token for token in src if token[0] is not tokenize.NL)
res = atom(src.next, src.next())
if src.next()[0] is not tokenize.ENDMARKER:
raise SyntaxError(bogus data after expression)
return res

(now waiting for paul to post the obligatory pyparsing example).

/F

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Peter Otten
Thomas Nelson wrote:

 I have this code:
 type1 = [0]
 type2 = [0]
 type3 = [0]
 map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2}  # the real map is
 longer than this
 
 def increment(value):
 map[value][0] += 1
 
 increment(1)
 increment(1)
 increment(0)
 increment(4)
 #increment will actually be called many times through other functions
 print type1[0], type2[0], type3[0]
 #should print 3 1 0
 
 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.  Does anyone know a
 cleaner way to have the same funtionality?

I don't think your code is ugly. Anyway, here are two more alternatives:

 types = [0] * 3
 dispatch = [0, 0, 2, 0, 1]
 for value in [1, 1, 0, 4]:
... types[dispatch[value]] += 1
...
 types
[3, 1, 0]


 inflated = [0] * 5
 groups = [[0, 1, 3], [4], [2]]
 for value in [1, 1, 0, 4]:
... inflated[value] += 1
...
 [sum(inflated[i] for i in group) for group in groups]
[3, 1, 0]

Peter

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


template is calling 2 times

2006-07-07 Thread sanjeevdivekar
hi,

i am newbie to python so i am trying to learn mod_python as my new
development kit for my small web apps.

i am getting strange result can anybody explain me.
*
index.py
*
from mod_python import apache
from mod_python import psp
from mod_python import util

def index(req, para=None):
tmpl = psp.PSP(req, filename='a.html')
tmpl.run(vars = {'para':para})
tmpl.run()

def show_data(req, name):
index(req, name)
*

*
a.htm
*

!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN
HTML
HEAD
/HEAD
BODY
h1%=para%/h1
form method=post action=http://localhost:8080/test/show_data;
input type=text name=name
input type=submit
/form
/BODY
/HTML
*

*
Result
*
None
textbox submitbutton

Mod_python error: PythonHandler mod_python.publisher
Traceback (most recent call last):
File E:\Python24\Lib\site-packages\mod_python\apache.py, line 299, in
HandlerDispatch result = object(req)
File E:\Python24\Lib\site-packages\mod_python\publisher.py, line 213,
in handler published = publish_object(req, object)
File E:\Python24\Lib\site-packages\mod_python\publisher.py, line 412,
in publish_object return Publish_object(req,util.apply_fs_data(object,
req.form, req=req))
File E:\Python24\lib\site-packages\mod_python\util.py, line 439, in
apply_fs_data return object(**args)
File E:\Apache Group\Apache2\htdocs\test\index.py, line 8, in index
tmpl.run()
File E:\Python24\Lib\site-packages\mod_python\psp.py, line 213, in
run exec code in global_scope
File E:\Apache Group\Apache2\htdocs\test\a.html, line 1, in ?
NameError: name 'para' is not defined



what's wrong in this code?
any good internet resource to learn mod_python?

thanks in advanced
Sanjeev

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


Re: IRC questions!!

2006-07-07 Thread Jon Clements

bruce wrote:
 hi...

 i'm trying to figure out what i have to do to setup mIRC to get the #python
 channel on IRC!!

 any pointers. the mIRC docs didn't get me very far.

 is there an irc.freenode.net that i need to connect to? how do i do it?

 thanks..

 -bruce

Assuming you're familiar with the basics of IRC.

In mIRC, File-Select Server-Add, enter Freenode as description,
enter irc.freenode.net as server. Leave the port as 6667, then change
it later if server supports other ports.

Click connect to server.

Cheers,

Jon.

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


Re: Error type for shelve.open()

2006-07-07 Thread aomighty
Yes, the problem was that I hadn't imported anydbm.error... it's
working now.

As for the AttributeError at the end, I talked to someone else, and he
looked at the source and said it was a bug in shelve. I think I will
report it to python.org.

Anyway, thanks :).
Simon Forman wrote:
 [EMAIL PROTECTED] wrote:
  I tried what you said and it looked like maybe AttributeError, but that
  didn't work either.
 
  This code snippet:
 
  import shelve
  from traceback import format_exc
 
  try:
 db = shelve.open(meh, r)
  except:
 print format_exc()
 
  Gave me this output:
  Traceback (most recent call last):
File test.py, line 5, in ?
  db = shelve.open(meh, r)
File /usr/lib/python2.4/shelve.py, line 231, in open
  return DbfilenameShelf(filename, flag, protocol, writeback, binary)
File /usr/lib/python2.4/shelve.py, line 212, in __init__
  Shelf.__init__(self, anydbm.open(filename, flag), protocol,
  writeback, binary)
File /usr/lib/python2.4/anydbm.py, line 77, in open
  raise error, need 'c' or 'n' flag to open new db
  error: need 'c' or 'n' flag to open new db
 
  Exception exceptions.AttributeError: DbfilenameShelf instance has no
  attribute 'writeback' in  ignored
 
  Do you know what the error is?

 No.  If you tried catching AttributeError and it didn't work then I'd
 guess that the AttributeError is a secondary result of the initial
 error.

 This part of the traceback,

File /usr/lib/python2.4/anydbm.py, line 77, in open
  raise error, need 'c' or 'n' flag to open new db
  error: need 'c' or 'n' flag to open new db

 indicates that some sort of custom error, probably defined in the
 anydbm.py module.

 Catching the execption and binding it to a var,

  try:
 ... db = shelve.open(meh, r)
 ... except Exception, err:
 ... E = err
 ...
 Exception exceptions.AttributeError: DbfilenameShelf instance has no
 attribute 'writeback' in  ignored
  E
 anydbm.error instance at 0xb7d8270c



 So:
  from anydbm import error
  try:
 ... db = shelve.open(meh, r)
 ... except error:
 ... print 'Aha!  got it!'
 ...
 Aha!  got it!
 Exception exceptions.AttributeError: DbfilenameShelf instance has no
 attribute 'writeback' in  ignored


 Well, that catches the error, but I don't know what's going on with the
 additional AttributeError or what to do about it.
 
 Peace,
 ~Simon

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


Re: pyXLWriter - grid lines and if formula

2006-07-07 Thread Gregory Piñero
On 7/7/06, Luis P. Mendes [EMAIL PROTECTED] wrote:
 Hi,

 I know that pyExelerator is the supported project now, but I can't use
 it because I'd need it to generate files from a web platform. Since I
 can not save a file to a file-like object, I have to use pyXLWriter.

I don't really know what I'm talking about, but maybe have a Python
script that uses pyExelerator and saves the file to Sdout, name that
script with an .xls extension and the browser will present it to the
user as an Excel file?

Maybe, maybe??

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


Re: Amara: Where's my attribute?

2006-07-07 Thread uche . ogbuji
AdSR wrote:
 [EMAIL PROTECTED] wrote:
  What is the actual problem you're trying to solve?  If you just want to
  force a namespace declaration in output (this is sually to support
  QNames in content) the most well-known XML hack is to create a dummy
  attribute with the needed prefix and namespace.  But this does not work
  when you're trying to force a default namespace declaration.  Then
  again, you generally can't use QNames in content with a default
  namespace declaration.  So my guess is that you somehow got way off the
  rails in your problem-solving, and you'll need to provide mre
  background if you want help.

 I wanted to remove documentation elements from some XML Schema files.
 The problem showed when I tried to use the stripped schemas, because
 the namespace declaration for user-defined types was missing. Of
 course, since these types are named and referred to in attribute
 *values*, Amara had no way to know that the namespace declaration was
 still needed (didn't matter if default or non-default). This is more a
 problem of how XML Schema is defined against XML namespace rules, since
 XML Schena uses namespaces in a context of which XML parsers aren't
 normally aware.

Yeah.  Just so you know.  This is one of those things about XML that
make sane people want to dye their eyeballs red.

Unfortunately there isn't much recourse but to switch to namespace
qualified form for your QNames and adding dummy attributes so the
namespace is recognized.  Let me know if you need an example.


  BTW, I recommend upgrading to Amara 1.1.7.  That branch will soon be
  1.2, and I consider it more mature than 1.0 at this point.  The API's
  also easier:

 I know, especially the insert-before/after feature :) But I ran into a
 problem that I describe below and you advertised 1.0 as stable
 version, so I switched immediately.

 The problem can be reproduced like this:

  import amara
  amara.parse('http://www.w3.org/2001/XMLSchema.xsd')
 START DTD xs:schema -//W3C//DTD XMLSCHEMA 200102//EN XMLSchema.dtd
 http://www.w3.org/2001/datatypes.dtd:99:23: Attribute 'id' already
 declared
 http://www.w3.org/2001/datatypes.dtd:122:23: Attribute 'id' already
 declared
 http://www.w3.org/2001/datatypes.dtd:130:27: Attribute 'id' already
 declared
 ...some 40 more lines like this and then Python crashes (Windows shows
 the bug-reporting dialog)


I don't get a crash on my system (Ubuntu), but I do get a legitimate
error message because that DTD is broken.  The W3C seems to like
disseminating broken DTDs.  Just yesterday I was helping someone around
the infamous broken XHTML 1.1 DTDs.

I do want to know why you're gettign a crash rather than just the error
message.  What version of Python is that?  Any chance you can try with
current CVS Amara (you can use easy_install)?  This part of the
discussion should perhaps move to the 4Suite mailing list.  I only
check this NG once a week.

--
Uche Ogbuji   Fourthought, Inc.
http://uche.ogbuji.nethttp://fourthought.com
http://copia.ogbuji.net   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

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


Parsing HTML--looking for info/comparison of HTMLParser vs. htmllib modules.

2006-07-07 Thread Kenneth McDonald
I'm writing a program that will parse HTML and (mostly) convert it to 
MediaWiki format. The two Python modules I'm aware of to do this are 
HTMLParser and htmllib. However, I'm currently experiencing either real 
or conceptual difficulty with both, and was wondering if I could get 
some advice.

The problem I'm having with HTMLParser is simple; I don't seem to be 
getting the actual text in the HTML document. I've implemented the 
do_data method of HTMLParser.HTMLParser in my HTMLParser subclass, but 
it never seems to receive any data. Is there another way to access the 
text chunks as they come along?

HTMLParser would probably be the way to go if I can figure this out. It 
seems much simpler than htmllib, and satisfies my requirements.

htmllib will write out the text data (using the AbstractFormatter and 
AbstractWriter), but my problem here is conceptual. I simply don't 
understand why all of these different levels of abstractness are 
necessary, nor how to use them. As an example, the html itext/i 
should be converted to ''text'' (double single-quotes at each end) in my 
mediawiki markup output. This would obviously be easy to achieve if I 
simply had an html parse that called a method for each start tag, text 
chunk, and end tag. But htmllib calls the tag functions in HTMLParser, 
and then does more things with both a formatter and a writer. To me, 
both seem unnecessarily complex (though I suppose I can see the benefits 
of a writer before generators gave the opportunity to simply yield 
chunks of output to be processed by external code.) In any case, I don't 
really have a good idea of what I should do with htmllib to get my 
converted tags, and then content, and then closing converted tags, 
written out.

Please feel free to point to examples, code, etc. Probably the simplest 
solution would be a way to process text content in HTMLParser.HTMLParser.

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


Idea/request for new python mailing list/newsgroup.

2006-07-07 Thread Kenneth McDonald
Would a mailing list and newsgroup for python contributions be of 
interest? I currently have a module which is built on top of, and is 
intended to semantically replace, the 're' module. I use it constantly 
to great advantage, but have not made it public for the following reasons:

* The API should probably be cleaned up in places.
* Documentation is reasonable, but should be more organized and put into 
D'Oxygen format. It also needs to be slightly updated.
* A few more unit tests should be added.
* A few features of regular expressions are not yet available.
* Some capabilities go well beyond those of the re module, and there is 
the potential for much more.

I'd very much likes a ML/newsgroup wherein potential python contributors 
could

* Post alphas/betas and seek feedback.
* Request volunteer help to finish a project.
* Discuss details of implementation (API, useful vs. nonuseful 
functionality, etc.)
* etc. etc. etc.

For example, my library is extremely useful as is, but I currently don't 
have much time to do the things (API cleanup, doc organization, 
potential additional features) that I'd like to see before a public 
release. I also don't have the time or knowledge to set it up as an 
online project. On the other hand, I'd certainly be willing to share my 
experiences and knowledge of the current codebase. An appropriate 
mailing list or newsgroup could give feedback for when I do have time 
and, if my library is interesting enough, possibly even provide some help.

One thing to emphasize is that this should not be a list/newsgroup where 
people post requests or ideas. Requests or ideas for additional 
functionality are a dime a dozen. The sole intent of this group would be 
to provide a forum for discussion and coordination for work which is 
well under way, but needs input or further help.

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


Re: import

2006-07-07 Thread David Jackson
Indeed you are correct...that is indeed TWO underscores and everything works 
fine now.  Thanks for pointing out the obvious...I thought it was a simple 
problem.  --DJ

faulkner [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 that should be __init__.py [TWO underscores].
 and you might want to import sys and check sys.path [the list of
 directories searched by the import mechanism].


 David Jackson wrote:
 Hi all,

 I'm a real beginner with python but have what I think is a simple 
 question.
 I am writing some simple modules and would like to place them into a
 subdirectory.  But then I cannot seem to import them.  I have tried the
 following.

 I wrote a module called fibo.py with some definitions in it (one called
 fibo).  In the same directory, I wrote another file (test.py) and began 
 with
 import fibo.  This worked fine and I was able to use the function fibo as
 fibo.fibo.  Then, I made a directory called test and placed the file 
 fibo.py
 in this directory.  I also placed a blank file called _init_.py into this
 directory.  I went back to the original directory and tried to import
 test.fibo but this fails.  I get the following error message:

 Traceback (innermost last)
   File ...test.py, line 1, in ?
 import test.fibo
   File ...test.py, line 1, in ?
 import test.fibo
 ImportError: No module named fibo

 Any help would be greatly appreciated.  If it makes any difference, I'm
 working on a Mac, OSX 10.3.9

 Thanks,
 David
 


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


Re: how can I avoid abusing lists?

2006-07-07 Thread Jon Ribbens
In article [EMAIL PROTECTED], Thomas Nelson wrote:
 This is exactly what I want to do: every time I encounter this kind of
 value in my code, increment the appropriate type by one.  Then I'd like
 to go back and find out how many of each type there were.  This way
 I've written seems simple enough and effective, but it's very ugly and
 I don't think it's the intended use of lists.  Does anyone know a
 cleaner way to have the same funtionality?

How about this:

map = {}
def increment(value):
  map[value] = map.get(value, 0) + 1

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


Re: Idea/request for new python mailing list/newsgroup.

2006-07-07 Thread Simon Forman

Kenneth McDonald wrote:
 Would a mailing list and newsgroup for python contributions be of
 interest? I currently have a module which is built on top of, and is
...
 I'd very much likes a ML/newsgroup wherein potential python contributors
 could

 * Post alphas/betas and seek feedback.
 * Request volunteer help to finish a project.
 * Discuss details of implementation (API, useful vs. nonuseful
 functionality, etc.)
 * etc. etc. etc.

Why is this (c.l.p) not that newsgroup?

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


Re: multinormal distribution

2006-07-07 Thread Robert Kern
TG wrote:
 hi there.
 
 I'm struggling with a function of numpy. Here it is :
 
 import numpy as NP
 mean = NP.array([0,0])
 cov = NP.array([[1,0.25],[0.25,1]])
 v = NP.random.multivariate_normal(mean,cov)
 
 Quite simple code : it is supposed to generate an array of two random
 values taken from a multinormal distribution, with respect to means and
 covariance matrix given as parameters.
 
 What happens on my computer is simple : it freezes ! I can't even stop
 the process with ctrl-C in my python interpreter i have to kill it from
 outside.
 
 I'm running : 
 - python 2.4.1
 - numpy 0.9.8

Well, it's working quite well for me on OS X PPC and Linux AMD-64 with a 
reasonably recent SVN checkout of numpy. Did you build numpy yourself, or use a 
binary distribution? Windows? Linux? OS X?

Please join us on the numpy mailing list with this information; hopefully there 
is someone there with a similar platform who can replicate your bug or offer 
better advice than myself.

   http://www.scipy.org/Mailing_Lists

In the meantime, you might try compiling a recent SVN checkout of numpy and see 
if the problem goes away for you.

-- 
Robert Kern

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

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Simon Forman

Tim Chase wrote:


 You'll notice that the OP's code had multiple references to the
 same counter (0, 1, and 3 all mapped to type1)

 The OP's method was about as good as it gets.  One might try to

D'oh!  Didn't notice that.

Yeah, Thomas,  if you really do want more than type code (i.e. key to
your map dict) to map to the same type counter then IMHO your original
method is very apt.

Peace,
~Simon

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


RE: IRC questions!!

2006-07-07 Thread bruce
given that nothing appears to be connecting..

should i have anything in the group window/dialog of the server setting...

-bruce


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Jon Clements
Sent: Friday, July 07, 2006 10:57 AM
To: python-list@python.org
Subject: Re: IRC questions!!



bruce wrote:
 hi...

 i'm trying to figure out what i have to do to setup mIRC to get the
#python
 channel on IRC!!

 any pointers. the mIRC docs didn't get me very far.

 is there an irc.freenode.net that i need to connect to? how do i do it?

 thanks..

 -bruce

Assuming you're familiar with the basics of IRC.

In mIRC, File-Select Server-Add, enter Freenode as description,
enter irc.freenode.net as server. Leave the port as 6667, then change
it later if server supports other ports.

Click connect to server.

Cheers,

Jon.

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

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


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread fumanchu
Jack wrote:
 I wrote the last posting at late late night and I didn't know what I was
 typing at that time ;-p

 I didn't mean the test with CherryPy was not concurrent
 connections, or the test with lighttpd was all concurrent
 connections. I actually tried both concurrent (-c in ab command line)
 and non-concurrent (without -c in ab command line) and I tried
 the threading and threadpooling in CherryPy. The result did not
 vary much.

 This article http://www.cherrypy.org/wiki/CherryPySpeed says CherryPy
 can process around 400-500 requests/second. It's set up is:

   Pentium M 1.6, 1G RAM, Windows XP2 laptop, test done with apache 2.0.41
 ab.

 I have a slightly better hardware set up:

   Pentium M 1.7MHz, 1.5G RAM on Windows XP2 laptop, test done with Apache
 2.2 ab

 However, I don't get even close. The best I get is around 140
 requests/second. I'm using the same test script as the CherryPy test
 with slight modification just to make it run. As a matter of fact,
 the Cygwin build of lighttpd only gets around 430 requests/second for
 a 2-byte static file. I disabled firewall and antivirus on the box when
 tests were done. Any idea about the huge difference? It would be very
 interesting if some CherryPy (or python) users can post their performance
 benchmarks.

It would be good to know which version of CherryPy you are using. That
wiki page is talking about the CP 2.0 branch; 2.1 and later are quite
different. If you have a later version, try using
cherrypy/test/benchmark.py

Note also that you can use lighttpd as an HTTP server for CherryPy apps
via FCGI/SCGI.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Istvan Albert
  I will have to install lighttpd or other web servers.

 If it is a Python web server, it would be nice to extend it by putting code
 right into the web server. The performance should be better than FastCGI
 because it removes the cost to send the requests/replies back and forth.

you'll need to make a distinction between a webserver written in python
(primary purpose to serve data) and a web framework that integrates
python and allows you to generate said data with python

as for the so called load test that you mention above, those tests
are pointless and provide no insight whatsoever to the realistic
behavior of the server ... unless of course all your users are expected
to connect from the same machine while asking for the same 2 byte file
at the maximum speed the system allows them to.

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


Re: how can I avoid abusing lists?

2006-07-07 Thread Thomas Nelson
Thanks to everyone who posted.  First, I don't think my question was
clear enough: Rob Cowie, Ant, Simon Forman, [EMAIL PROTECTED], and Jon
Ribbens offered solutions that don't quite work as-is, because I need
multiple values to map to a single type.  Tim Chase and Bruno
Destuilliers both offer very nice OOP solutions, and I think this is
the route I will probably go.  However, for the simplest and easiest
solution, I really like this from Peter Otten:
inflated = [0]*5
groups = [[0,1,3],[4],[2]]
for value in [1,1,0,4]:
inflated[value] += 1
print [sum(inflated[i] for i in group) for group in groups]

4 lines (one more to assign the lists to name values, but that's
minor), and intuitive.  If I had just thought of this to begin with, I
wouldn't have bothered posting.

Thanks to all for the advice.

THN

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


Re: Looking for a high performance web server written in Python, and supports CGI/FastCGI

2006-07-07 Thread Jack
You are right. Load test can be complicated because of the various patterns
of web applications and usages. The simple tests I mentioned and conducted 
just
give myself some idea about the performance. Given the same set up, some
numbers should be comparable and reveal some aspects on web servers'
performance. They are by no means formal load tests, but they are helpful to 
me :-)

Istvan Albert [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
  I will have to install lighttpd or other web servers.

 If it is a Python web server, it would be nice to extend it by putting 
 code
 right into the web server. The performance should be better than FastCGI
 because it removes the cost to send the requests/replies back and forth.

 you'll need to make a distinction between a webserver written in python
 (primary purpose to serve data) and a web framework that integrates
 python and allows you to generate said data with python

 as for the so called load test that you mention above, those tests
 are pointless and provide no insight whatsoever to the realistic
 behavior of the server ... unless of course all your users are expected
 to connect from the same machine while asking for the same 2 byte file
 at the maximum speed the system allows them to.
 


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


Re: Nested scopes, and augmented assignment

2006-07-07 Thread Terry Reedy

Antoon Pardon [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 others might be helped if you took the trouble of explaining
 what was wrong.

Aside from F., I tried to explain what I think you said wrong.  Did you 
read it?  Did it help any?

tjr




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


Re: pyXLWriter - grid lines and if formula

2006-07-07 Thread John Machin
On 8/07/2006 3:43 AM, Luis P. Mendes wrote:
 Hi,
 
 I know that pyExelerator is the supported project now, but I can't use
 it because I'd need it to generate files from a web platform. Since I
 can not save a file to a file-like object, I have to use pyXLWriter.
 
 The problems are:
 1- how to turn off/on the grid lines of each sheet?

It is an open source project. When you went to the source directory and 
typed:

grep def.*grid *.py

what went wrong?

 2- I tried to build a simple 'if' formula but couldn't.

What did you try, and what was the result when you opened the file with 
OO.o Calc / Gnumeric / you-know-what? Have you had success with *any* 
formulas that have functions with more than one argument?

 Is it my
 problem or pyXLWriter's problem?

Given the limited information, certainty is impossible, but I'd say it's 
your problem.

 If the former, is it possible to post
 an example?

It is possible to post an example irrespective of whether it is your 
problem or not.

It is also possible to go to the examples directory and type:

grep -i =if *.py

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


[ANNOUNCE] Thirty-third release of PythonCAD now available

2006-07-07 Thread Art Haas
Hi.

I'm pleased to announce the thirty-third development release of PythonCAD,
a CAD package for open-source software users. As the name implies,
PythonCAD is written entirely in Python. The goal of this project is
to create a fully scriptable drafting program that will match and eventually
exceed features found in commercial CAD software. PythonCAD is released
under the GNU Public License (GPL).

PythonCAD requires Python 2.2 or newer. The interface is GTK 2.0
based, and uses the PyGTK module for interfacing to GTK. The design of
PythonCAD is built around the idea of separating the interface
from the back end as much as possible. By doing this, it is hoped
that both GNOME and KDE interfaces can be added to PythonCAD through
usage of the appropriate Python module. Addition of other PythonCAD 
interfaces will depend on the availability of a Python module for that
particular interface and developer interest and action.

The thirty-third release contains several major updates to the program.
Drawing operations have been greatly sped up when entities are added
to a drawing, modified, or deleted from a drawing. Users on older
hardware or machines with slower video systems will notice this
change immediately. A second large change in this release is the
completion of separating the interface code from the core code by
using the internal messaging system in place of object inheritance.
The third big change in this release is the formatting of the interface
text strings for internationalization, and a Spanish translation is
now available for users to install. It is hoped that more translations
appear in future releases. Additionally, a large number of smaller
improvements, enhancements, and bug fixes are also present in this
release.

A mailing list for the development and use of PythonCAD is available.
Visit the following page for information about subscribing and viewing
the mailing list archive:

http://mail.python.org/mailman/listinfo/pythoncad

Visit the PythonCAD web site for more information about what PythonCAD
does and aims to be:

http://www.pythoncad.org/

Come and join me in developing PythonCAD into a world class drafting
program!

Art Haas
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can I avoid abusing lists?

2006-07-07 Thread Rob Cowie
No, your question was clear. With hindsght and a more thorough read of
your post I see my error ;^)

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


  1   2   >