Announce: Linux Desktop Testing Project (LDTP) 0.8.0 released

2007-02-19 Thread A Nagappan
We are proud to announce the release of LDTP 0.8.0. This release
features number of important breakthroughs in LDTP as well as in the
field of Test Automation. This release note covers a brief introduction
on LDTP followed by the list of new features and major bug fixes which
makes this new version of LDTP the best of the breed. Useful references
have been included at the end of this article for those who wish to hack
/ use LDTP.

About LDTP
==

Linux Desktop Testing Project is aimed at producing high quality test
automation framework (C / Python) and cutting-edge tools that can be
used to test Linux Desktop and improve it. It uses the Accessibility
libraries to poke through the application's user interface. The
framework also has tools to record test-cases based on user events in
the interface of the
application which is under testing. We strive to help in building a
quality desktop.

Whats new in this release...


+ Major performance enhancement
In this release major contribution from Nagappan A
[EMAIL PROTECTED]. Valgrinded LDTP engine and fixed lot of memory
leaks in LDTP and improved the performance.

+ Palm Source testing team has contributed significant amount of code in
ldtprunner and also reported all major issues to make LDTP execution
engine more stable.

+ Added LDTP repository into to OpenSuSE build system. Packages will be
available for SuSE 10.0, SuSE 10.1, OpenSuSE 10.2, OpenSuSE Factory,
Fedora 4, Fedora 5, Fedora 6, Mandriva just on a single click. The
OpenSuSE build system really rocks  ;) 

+ Bug fixes
This version includes loads of bug fixes to address important issues
like memory leak, API functionality, accessibility compatible issues
etc., For a detailed list please refer to release notes section of our
project site hosted in http://ldtp.freedesktop.org. Thanks to all the
developers for their contribution and Guofu Xu (lavi) especially.

Download source tarball -
http://download.freedesktop.org/ldtp/0.x/0.8.x/ldtp-0.8.0.tar.gz

LDTP news
=

* LDTP packages are now built through OpenSuSE build system -
http://software.opensuse.org/download/home:/anagappan/
* Accessibility test suite by Rodney Dawes (dobey) -
http://webcvs.freedesktop.org/ldtp/a11y-test-suite/

LDTP Recording demo
===

Record / Playback of scripts -
http://people.freedesktop.org/~nagappan/ldtpguidemo.html

References
==

For detailed information on LDTP framework and latest updates visit
http://ldtp.freedesktop.org

For information on various APIs in LDTP including those added for this
release can be got from http://ldtp.freedesktop.org/user-doc/index.html

To subscribe to LDTP mailing lists, visit
http://ldtp.freedesktop.org/wiki/Mailing_20list

IRC Channel - #ldtp on irc.freenode.net

For suggestions to improve this newsletter, please write to
[EMAIL PROTECTED]

Nagappan A [EMAIL PROTECTED]
Linux Desktop Testing Project - http://ldtp.freedesktop.org
http://nagappanal.blogspot.com

Novell, Inc.
SUSE® Linux Enterprise 10
Your Linux is ready™
http://www.novell.com/linux


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Does Python have equivalent to MATLAB varargin, varargout, nargin, nargout?

2007-02-19 Thread openopt
Ok, thx
But can I somehow determing how many outputs does caller func require?
for example:
MATLAB:
function [objFunVal firstDerive secondDerive] = simpleObjFun(x)
objFunVal = x^3;
if nargout1
firstDerive = 3*x^2;
end
if nargout2
secondDerive = 6*x;
end

So if caller wants only
[objFunVal firstDerive] = simpleObjFun(15)
than 2nd derivatives don't must to be calculated with wasting cputime.
Is something like that in Python?

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


How to test if one dict is subset of another?

2007-02-19 Thread Jay Tee
Hi,

I have some code that does, essentially, the following:

- gather information on tens of thousands of items (in this case, jobs
running on a
 compute cluster)
- store the information as a list (one per job) of Job items
(essentially wrapped
 dictionaries mapping attribute names to values)

and then does some computations on the data.  One of the things the
code needs to do, very often, is troll through the list and find jobs
of a certain class:

for j in jobs:
   if (j.get('user') == 'jeff' and j.get('state')=='running') :
  do_something()

This operation is ultimately the limiting factor in the performance.
What I would like to try, if it is possible, is instead do something
like this:

   if j.subset_attr({'user' : 'jeff', 'state' : 'running'}) :
  do_something()


where subset_attr would see if the dict passed in was a subset of the
underlying attribute dict of j:

  j1's dict : { 'user' : 'jeff', 'start' : 43, 'queue' : 'qlong',
'state' : 'running' }
  j2's dict : { 'user' : 'jeff', 'start' : 57, 'queue' : 'qlong',
'state' : 'queued' }

so in the second snippet, if j was j1 then subset_attr would return
true, for j2 the answer would be false (because of the 'state' value
not being the same).

Any suggestions?  Constraint : the answer has to work for both python
2.2 and 2.3 (and preferably all pythons after that).

 JT

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


Re: How do I create an array of functions?

2007-02-19 Thread Diez B. Roggisch
Steven W. Orr schrieb:
 I have a table of integers and each time I look up a value from the 
 table I want to call a function using the table entry as an index into 
 an array whose values are the different functions.  I haven't seen 
 anything on how to do this in python.

def f():
pass

fmap = { key: f }


fmap[key]()


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


Re: How do I create an array of functions?

2007-02-19 Thread Rob Wolfe

Steven W. Orr wrote:
 I have a table of integers and each time I look up a value from the table
 I want to call a function using the table entry as an index into an array
 whose values are the different functions.  I haven't seen anything on how
 to do this in python.

Do you mean something like that?

# test.py

def fun1(): return fun1
def fun2(): return fun2
def fun3(): return fun3

# list of functions
dsp = [f for fname, f in sorted(globals().items()) if callable(f)]
tab = range(len(dsp))
print dsp[tab[2]]()

# dictionary of functions
d = dict([(fname, f) for fname, f in globals().items() if
callable(f)])
tab = [fname for fname, f in sorted(globals().items()) if callable(f)]
print d[tab[2]]()

--
HTH,
Rob

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


Re: How to test if one dict is subset of another?

2007-02-19 Thread Diez B. Roggisch
Jay Tee schrieb:
 Hi,
 
 I have some code that does, essentially, the following:
 
 - gather information on tens of thousands of items (in this case, jobs
 running on a
  compute cluster)
 - store the information as a list (one per job) of Job items
 (essentially wrapped
  dictionaries mapping attribute names to values)
 
 and then does some computations on the data.  One of the things the
 code needs to do, very often, is troll through the list and find jobs
 of a certain class:
 
 for j in jobs:
if (j.get('user') == 'jeff' and j.get('state')=='running') :
   do_something()
 
 This operation is ultimately the limiting factor in the performance.
 What I would like to try, if it is possible, is instead do something
 like this:
 
if j.subset_attr({'user' : 'jeff', 'state' : 'running'}) :
   do_something()
 
 
 where subset_attr would see if the dict passed in was a subset of the
 underlying attribute dict of j:

This would still need to run over all items in jobs. No gain.

 
   j1's dict : { 'user' : 'jeff', 'start' : 43, 'queue' : 'qlong',
 'state' : 'running' }
   j2's dict : { 'user' : 'jeff', 'start' : 57, 'queue' : 'qlong',
 'state' : 'queued' }
 
 so in the second snippet, if j was j1 then subset_attr would return
 true, for j2 the answer would be false (because of the 'state' value
 not being the same).

If you're jobs dictionary is immutable regarding the key-set (not from 
it's implementation, but from its usage), the thing you can do to 
enhance performance is to create an index. Take a predicate like

def p(j):
return j.get('user') == 'jeff'

and build a list

jeffs_jobs = [j for j in jobs if p(j)]

Then you can test only over these. Alternatively, if you have quite a 
few of such predicate/action-pairs, try and loop once over all jobs, 
applynig the predicates and actions accordingly.

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


Re: How do I create an array of functions?

2007-02-19 Thread Paul Rubin
Steven W. Orr [EMAIL PROTECTED] writes:
 I have a table of integers and each time I look up a value from the
 table I want to call a function using the table entry as an index into
 an array whose values are the different functions.  I haven't seen
 anything on how to do this in python.

func_array = [f1, f2, f3]# array of functions
index = table_lookup()
func_array[index](x,y,z) # select a function and call it
-- 
http://mail.python.org/mailman/listinfo/python-list


Building Python Pagage for Newer Python Version

2007-02-19 Thread bg_ie
Hi,

I have just downloaded the source for PyXML-0.8.4, which I would like
to build for Python 2.5. How exactly do I go about doing this?

Thanks for your help,

Barry.

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


Re: ANN: java2python 0.2

2007-02-19 Thread Kay Schluehr
On 19 Feb., 15:38, Troy Melhase [EMAIL PROTECTED] wrote:
 java2python - Java to Python Source Code Translator
 ---
 java2python 0.2 Released 18 February 2007

 What is java2python?
 --
 java2python is a simple but effective tool to translate Java source code into
 Python source code.  It's not perfect, and does not aspire to be.

 What's new in this release?
 --
 Small enhancement:  added converstion of public static void main method into
 module if __name__ == '__main__' block.

 Better classmethod support:  fixed class/instance member formatting strings to
 account for classmethods.

 Slightly more pythonic:  replace x == None expressions with x is None in
 output code, also replace x != None with x is not None.

 Bugfix:  Fixed dotted type identifiers.

 Better exception translation:  added support for mapping java exception types
 to python exception types.

 Support for non-local base class members:  added support for base class
 members via config modules.

 Bugfix:  changed single % characters to %% in expression format strings.

 Small enhancement:  added support for 'methodPreambleSorter' configuration
 item.  With this value, config modules can specify how to sort method
 preambles (typically decorators).

 Where can I get java2python?
 --
 java2python is available for download from Google code:

http://code.google.com/p/java2python/downloads/list

 Project page:

http://code.google.com/p/java2python/

 How do I use java2python?
 --
 Like this:

 $ j2py -i input_file.java -o output_file.py

 The command has many options, and supports customization via multiple
 configuration modules.

 What are the requirements?
 --
 java2python requires Python 2.5 or newer.  Previous versions may or may not
 work.  java2python requires ANTLR and PyANTLR to translate code, but
 translated code does not require ANTLR.

 What else?
 --
 java2python is installed with distutils.  Refer to the Python distutils
 documentation for more information.  The digest version is:

 $ tar xzf java2python-0.2.tar.gz
 $ cd java2python-0.2
 $ python setup.py install

 java2python is licensed under the GNU General Public License 2.0.  No license
 is assumed of (or applied to) translated source.

 I'm very interested in your experience with java2python.  Please drop me an
 note with any feedback you have.

 Troy Melhase
 mailto:[EMAIL PROTECTED]

  application_pgp-signature_part
 1KHerunterladen


Hi Troy. What is the rationale for your project?

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


Re: Does Python have equivalent to MATLAB varargin, varargout, nargin, nargout?

2007-02-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 Ok, thx
 But can I somehow determing how many outputs does caller func require?
 for example:
 MATLAB:
 function [objFunVal firstDerive secondDerive] = simpleObjFun(x)
 objFunVal = x^3;
 if nargout1
 firstDerive = 3*x^2;
 end
 if nargout2
 secondDerive = 6*x;
 end
 
 So if caller wants only
 [objFunVal firstDerive] = simpleObjFun(15)
 than 2nd derivatives don't must to be calculated with wasting cputime.
 Is something like that in Python?

For a sequence whose items are to be calulated on demand you would typically
use a generator in Python. You still have to provide the number of items
somehow (see the head() helper function).

from itertools import islice

def derive(f, x0, eps=1e-5):
while 1:
yield f(x0)
def f(x, f=f):
return (f(x+eps) - f(x)) / eps

def head(items, n):
return tuple(islice(items, n))

if __name__ == __main__:
def f(x): return x**6
print head(derive(f, 1), 4)

Peter

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


distutils and paths

2007-02-19 Thread billie
Hi there.
I played with distutils for some hours but I didn't figured out how to
solve this problem so I would really be thankful if someone could help
me out.
My package is structured as follows:

setup.py
 |
  mypkg
 |  |
 |   __init__.py
 |   library.py
 |
  test
 |  |
 |   test.py
 |
  doc
   |
doc.html
doc_files
  |
   doc.css

By using setup.py script I would like to copy test and doc
directories (and all files contained in them) into Python's site-
package directory (on Windows C:\Python2x\Lib\site-packages\mypkg,
on unix /usr/lib/python2.x/site-packages/mypkg.)
Could someone point me in the right direction, please?


Thanks in advance.

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


(beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread openopt
I have
class A:
def __init__(self, objFun, x0):
#(I want to have self.primal.f = objFun)
#both
self.primal.f = objFun
#and
self.primal = None
self.primal.f = objFun

yields error
what should I do?
Thx

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


timeout in urllib.open()

2007-02-19 Thread Stefan Palme
Hi all,

is there a way to modify the time a call of

  urllib.open(...)

waits for an answer from the other side? Have a tool
which automatically checks a list of websites for 
certain content. The tool hangs when one of the
contacted websites behaves badly and never answers...

Thanks and regards
-stefan-

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


Re: Django, one more newbie question

2007-02-19 Thread Stefan Scholl
Boris Ozegovic [EMAIL PROTECTED] wrote:
 Umm, can somebody tell me which language is this one:

pNo polls are available./p

English?

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


Re: (beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 I have
 class A:
 def __init__(self, objFun, x0):
 #(I want to have self.primal.f = objFun)
 #both
 self.primal.f = objFun
 #and
 self.primal = None
 self.primal.f = objFun

None is a singleton, so if Python were to allow the above f would always be
the objFun of the last created A instance.

 yields error
 what should I do?

Make a dedicated Primal class:

 class Primal:
... pass
...
 class A:
... def __init__(self, fun, x0):
... self.primal = Primal()
... self.primal.f = fun
...
 def square(x): return x*x
...
 a = A(square, 42)
 a.primal.f
function square at 0x401d609c

Even better, because it makes no assumptions about the internal layout of
Primal:

class Primal:
   def __init__(self, f):
  self.f = f

...
self.primal = Primal(fun)
...

Peter

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


Re: How to test if one dict is subset of another?

2007-02-19 Thread Peter Otten
Jay Tee wrote:

 Hi,
 
 I have some code that does, essentially, the following:
 
 - gather information on tens of thousands of items (in this case, jobs
 running on a
  compute cluster)
 - store the information as a list (one per job) of Job items
 (essentially wrapped
  dictionaries mapping attribute names to values)
 
 and then does some computations on the data.  One of the things the
 code needs to do, very often, is troll through the list and find jobs
 of a certain class:
 
 for j in jobs:
if (j.get('user') == 'jeff' and j.get('state')=='running') :
   do_something()
 
 This operation is ultimately the limiting factor in the performance.
 What I would like to try, if it is possible, is instead do something
 like this:
 
if j.subset_attr({'user' : 'jeff', 'state' : 'running'}) :
   do_something()
 
 
 where subset_attr would see if the dict passed in was a subset of the
 underlying attribute dict of j:
 
   j1's dict : { 'user' : 'jeff', 'start' : 43, 'queue' : 'qlong',
 'state' : 'running' }
   j2's dict : { 'user' : 'jeff', 'start' : 57, 'queue' : 'qlong',
 'state' : 'queued' }
 
 so in the second snippet, if j was j1 then subset_attr would return
 true, for j2 the answer would be false (because of the 'state' value
 not being the same).
 
 Any suggestions?  Constraint : the answer has to work for both python
 2.2 and 2.3 (and preferably all pythons after that).

Use a RDBMS (a database), they tend to be good at this kind of operations.

Peter

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


Free URL Submission, Forum, Free Ebooks, Articles

2007-02-19 Thread Rohin
Free URL Submission, Forum, Free Ebooks, Articles. http://www.aonearticles.com.

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


Re: timeout in urllib.open()

2007-02-19 Thread Peter Otten
Stefan Palme wrote:

 is there a way to modify the time a call of
 
   urllib.open(...)
 
 waits for an answer from the other side? Have a tool
 which automatically checks a list of websites for
 certain content. The tool hangs when one of the
 contacted websites behaves badly and never answers...

I believe this can only be set globally:

import socket
socket.setdefaulttimeout(seconds)

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


Choices: scipy, matplot ...

2007-02-19 Thread dug
Hi,

I would like to do some real time signal processing with a graphical
display and I would like your advice as to what I should use.  I would
like to be able to view the results and to change parameters of some
signal processing in 'real time'. Data is coming quite slowly in every
1-5 seconds and will consist of (x,y,t).


I have been thinking about SciPy or matplot, but am not restricting
myself to these (or even Python).

Thank you for any advice,

Douglas

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


Re: timeout in urllib.open()

2007-02-19 Thread Stefan Palme

Uuuh this is no solution for me, because the 
website-checking tool is part of a very very big
application running in an application server, so
globally setting the timeout may break a lot of
other things...

But when there is a default timeout (as indicated by
the method name) - isn't there a per-socket timeout
too?

-stefan-

 I believe this can only be set globally:
 
 import socket
 socket.setdefaulttimeout(seconds)
 
 Peter

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


Embedded and extending python 2.5: trouble with __main__ in PyRun_SimpleFileExFlags?

2007-02-19 Thread Carl Douglas
Hi Python fans,

I am developing a DLL that is loaded by a host application on windows.
 I'm using python 2.5.

My DLL uses an embedded python interpreter which can access the host
application through an API which I have exposed using SWIG 1.3.31.

Therefore I have both extended and embedded Python at once: the SWIG
generated code is statically linked into my DLL, and one of the
functions in my DLL executes PyRun_SimpleFile.

Using python25_d.dll, I stepped through some python code to understand
what is happening, and it appears that PyRun_SimpleFile is returning
-1 because python cannot create the module __main__.

Here's the code from pythonrun.c:

int
PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
PyCompilerFlags *flags)
{
PyObject *m, *d, *v;
const char *ext;

m = PyImport_AddModule(__main__);
if (m == NULL)
return -1;
.
.
.
}

BTW, PyImport_AddModule fails because deeper down a dictionary check fails:

if (!PyDict_Check(op))
return NULL;


Can someone suggest what I need to do to get this to work?

Here are the relevant lines from my code:

if (GetOpenFileName(ofn)==TRUE)
{
Py_Initialize();
init_mymodule(); // SWIG generated method

PyObject* PyFileObject = PyFile_FromString(ofn.lpstrFile, r);

if (PyRun_SimpleFile(PyFile_AsFile(PyFileObject), 
ofn.lpstrFile)==-1)
{
MessageBox(NULL, error running script, Python, 
MB_ICONERROR);
}

Py_DECREF(PyFileObject);

Py_Finalize();
}

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


Re: timeout in urllib.open()

2007-02-19 Thread Peter Otten
Stefan Palme wrote:

(top-posting undone)

[Peter]
 I believe this can only be set globally:
 
 import socket
 socket.setdefaulttimeout(seconds)

[Stefan]
 Uuuh this is no solution for me, because the
 website-checking tool is part of a very very big
 application running in an application server, so
 globally setting the timeout may break a lot of
 other things...
 
 But when there is a default timeout (as indicated by
 the method name) - isn't there a per-socket timeout
 too?

Yes, but it isn't as easily available...

Perhaps you find some ideas here:

http://mail.python.org/pipermail/python-dev/2007-February/070897.html

Peter

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


writing a file:newbie question

2007-02-19 Thread kavitha thankaian
Hi,
   
  i have a file test.txt and it contains a list of strings say,,,
   
  a,b,c,d,a1,b1,c1,d1,a2,b2,c2,d2,
   
  i would like to write the file as
   
  a,b,c,d
  a1,b1,c1,d1
  a2,b2,c2,d2
   
  and would like to delete the comma at the end.
   
  if soneone knows pls help me,,,
   
  kavitha


-
 Here’s a new way to find what you're looking for - Yahoo! Answers -- 
http://mail.python.org/mailman/listinfo/python-list

ipython shortcut to reload modules

2007-02-19 Thread [EMAIL PROTECTED]
Hey!

I'm using ipython as my python shell and often run scripts with the
magic command %run:

In [1]: %run script.py

If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call

In [2]: reload(module1)
Out [2]: module 'module1' from 
In [3]: reload(module2)
Out [3]: module 'module2' from ...
In [4]: %run script.py

Is there a shortshut to reload the modules automatically before
rerunning the script?

In case of names imported from modules into the shell environment I
have to reload and re-import in order to have the changes available:

In [5]: from module1 import *
In [6]: reload(module1)
In [7]: from module1 import *

Is there a shortcut to force a reload of loaded modules and re-
defining the names loaded with fromimport...?

Thanks! Bernhard

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


Re: How to test if one dict is subset of another?

2007-02-19 Thread Jay Tee
On Feb 19, 11:07 am, Peter Otten [EMAIL PROTECTED] wrote:

 Use a RDBMS (a database), they tend to be good at this kind of operations.

yeah, one of the options is metakit ... sqlite and buzhug both looked
promising but the constraint of pythons 2.2 and 2.3 ruled that out.
disadvantage of metakit is that it's not pure python, meaning possible
integration problems.  the system has to be deployed at 200+ sites
worldwide on a mix of RHEL 3 and 4 based systems, with some Debian
clusters thrown in, and running real production ...

hence my desire to find a pure-python solution if at all possible.
it's looking grim.

 JT

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread sturlamolden
On Feb 17, 1:34 am, Stef Mientki [EMAIL PROTECTED]
wrote:

 - designing the GUI will cost me about 2 .. 3 times as much in Python

Use a design tool like GLADE for PyGTK, wxGlade for wxPython or Komodo
for tkinter. The more of the GUI code you can remove from your
functional code the better. GUI code tends to clutter up the
functional code. Have you ever tried to make changes in an MFC
project? The optimal solutions are Microsoft's 'Avalon' and GTK/
libglade, where all GUI code are placed inside an XML resource.

The second thing is that GUIs are made very differently in Python and
traditional Windows tools like Delphi and VS.NET. Most Python toolkit
have a concept of 'layout managers' that will size and lay out the
widgets for you. In Delphi and VB you will typically drag and drop
controls on a form, and use anchors and docking and manually size the
controls. You are therefore much more dependent on graphical GUI
design in these environments. In Python toolkits, the layout manager
do all this work for you. Layout managers are also found in Java
toolkits like Swing and SWT. In order to make effective GUIs in Python
you must learn to use these, and forget about all the bad habits
Delphi thought you. Try to imagine the GUI as a tree of containers,
where the widgets reside on the leafs, instead of controls dropped on
a form. When you can do that in your head, you can make GUIs more
quickly in Python than VB or Delphi.

The main advantages to using layout managers are: GUIs are less
tedious to develop, you don't have to worry about resizing and
adapting to different screen sizes, and large projects become easier
to maintain.

















 - Python is not capable of doing everything I need
 (almost all interactive actions are very primitive and crashes a lot)
 - designing my other functional code in Python,
 will reduce the development time with an estimated factor of 2
 So the combination of Delphi (or VB) and Python seems the optimal combination 
 for heavily GUI's.
 - one of the big problems with Python is the version differences 
 (compatibility)

 In one of the other threads, Dabo was meant as a GUI designer,
 I tried it yesterday,
 and although it looks very promising,
 at the moment this is not a graphical design environment,
 just a complex (compared to Delphi) design environment with graphical 
 feedback.
 Just my 2 cents ;-)



  (although others in this group will definitely have a different opinion),
  the beautiful thing about Python is,
  that you can easily embed /encapsulate it in VB,
  giving you the best of both worlds.

  Why would one go thru the pain of embedding Python in VB (if that's
  even possible) when Python can directly access the Win32 API and all COM
  components and have bindings for GUI toolkits like wxWidgets ?

 Pain of embedding ?
 About 10 lines of code, which you find ready to use on the web ;-)
 And the performance is fantastic !
 (I even use it for realtime, as a complete replacement for MatLab and LabView)

 Bruno, I think we've a different audience / target application,
 and at the moment we'll never agree about GUI,
 but I promise that'll try the different Python graphics in the future,
 and you will be the first to hear if my current conclusions are wrong.

 cheers,
 Stef


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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread sturlamolden
On Feb 16, 11:12 pm, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:

 GUI based programming languages ? What's that ?

LabView


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


Re: 'import dl' on AMD64 platform

2007-02-19 Thread John Pye
On Feb 19, 6:30 am, Nick Craig-Wood [EMAIL PROTECTED] wrote:
 John Pye [EMAIL PROTECTED] wrote:
   application from running on the Debian Etch AMD64 platform.
   It seems that the 'dl' module is not available on that platform. The
   only reason I need the 'dl' module, however, is for the values of
   RTLD_LAZY etc, which I use with sys.setdlopenflags() in order to make
   my imported SWIG module share its symbols correctly with more deeply-
   nested plugin modiles in my C-code layer.

   I wonder if there is a workaround for this -- perhaps another way to
   access the values of those RTLD flags?

 Read stuff out of /usr/include/bits/dlfcn.h ?

 It seems to be a constant 1 anyway

 #define RTLD_LAZY   0x1

 You could try compiling the dl module by hand.

Well yes, and that's the workaround I came up with: for systems that
don't provide the 'dl' module, I just default to the values I found on
my linux (ubuntu) system. This is a nasty hack however.

I wonder if anyone could say why the Debian people left out this
important module from their AMD64 platform?

Cheers
JP

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


Re: (beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread openopt
Thx
but is there any simpleir way, if using not class, but just struct (or
something like that, MATLAB equivalent for that one)?
I'm thinking of rewriting some optimization solvers (non-smooth,
constrained, with (sub)gradients or patterns provided by user) to
Python and I don't know currently is it possible to easy convert
things like
prob = [];
prob.advanced.ralg.hs = 1 (so in this line all subfields are
generating automatically in MATLAB or Octave)
I have huge amount of such lines, and implementing separate class for
each one is unreal.
Thank you in advance, Dmitrey


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


Re: Choices: scipy, matplot ...

2007-02-19 Thread sturlamolden
On Feb 19, 11:34 am, dug [EMAIL PROTECTED] wrote:

 I would like to do some real time signal processing with a graphical
 display and I would like your advice as to what I should use.  I would
 like to be able to view the results and to change parameters of some
 signal processing in 'real time'. Data is coming quite slowly in every
 1-5 seconds and will consist of (x,y,t).

 I have been thinking about SciPy or matplot, but am not restricting
 myself to these (or even Python).

You will need:

- Python 25
- NumPy
- SciPy (possibly)
- Matplotlib (for graphing)
- PyGTK or wxPython (for the rest of the GUI)

Finally you need something to make Python talk to your hardware. Pick
one of the following, dependent on your need and skills:

- ctypes
- pyrex
- inlined C with scipy.weave
- autogenerated wrappers with swig
- hand-written Python extension in C
- hand-written Python extension in C++ (CXX or Boost.Python)





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


Re: timeout in urllib.open()

2007-02-19 Thread Stefan Palme
 [Peter]
 I believe this can only be set globally:
 
 import socket
 socket.setdefaulttimeout(seconds)

 [Stefan]
 ...
 But when there is a default timeout (as indicated by
 the method name) - isn't there a per-socket timeout
 too?
 
 [Peter]
 Yes, but it isn't as easily available...
 
 Perhaps you find some ideas here:
 
 http://mail.python.org/pipermail/python-dev/2007-February/070897.html

Thanks, will have a look at this.

Regards
-stefan-


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


Re: How to test if one dict is subset of another?

2007-02-19 Thread Peter Otten
Jay Tee wrote:

 On Feb 19, 11:07 am, Peter Otten [EMAIL PROTECTED] wrote:
 
 Use a RDBMS (a database), they tend to be good at this kind of
 operations.
 
 yeah, one of the options is metakit ... sqlite and buzhug both looked
 promising but the constraint of pythons 2.2 and 2.3 ruled that out.
 disadvantage of metakit is that it's not pure python, meaning possible
 integration problems.  the system has to be deployed at 200+ sites
 worldwide on a mix of RHEL 3 and 4 based systems, with some Debian
 clusters thrown in, and running real production ...
 
 hence my desire to find a pure-python solution if at all possible.
 it's looking grim.

The following may speed up things a bit if you have enough memory and your
data is queried more often than changed.

import sys

def generate_id():
for i in xrange(sys.maxint):
yield i
raise ImplementationRestriction

get_id = generate_id().next

class Record(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
assert not hasattr(self, _id)
self._id = get_id()
def __setitem__(self, key, value):
raise ImmutableException
def __hash__(self):
return self._id
def __str__(self):
items = self.items()
items.sort()
return , .join([%s: %s % p for p in items])

records = dict.fromkeys([
Record(user=jack, start=42, state=running),
Record(user=jack, start=47, state=running),
Record(user=jack, start=46, state=queued),
Record(user=jane, start=42, state=running),
Record(user=jane, start=7),
])

def fill_cache(records):
cache = {}
for record in records:
for p in record.iteritems():
cache.setdefault(p, {})[record] = None
return cache

_cache = fill_cache(records)

def select(*data, **kw):
[data] = data
result = data
for p in kw.iteritems():
try:
c = _cache[p]
except KeyError:
c = {}
if not c:
return {}
result = dict.fromkeys([k for k in result if k in c])
if not result:
break
return result

if __name__ == __main__:
for filter in [
dict(user=jack),
dict(state=running),
dict(user=jack, state=running),
dict(state=undefined),
dict(user=jane, state=queued)
]:
print --- %s --- % Record(filter)
result = select(records, **filter)
if result:
for record in result:
print record
else:
print #no matching records
print

The above code runs with Python 2.3; don't know about 2.2 as I don't have it
on my machine. Of course with sets it would look better...

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


Re: (beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 Thx
 but is there any simpleir way, if using not class, but just struct (or
 something like that, MATLAB equivalent for that one)?
 I'm thinking of rewriting some optimization solvers (non-smooth,
 constrained, with (sub)gradients or patterns provided by user) to
 Python and I don't know currently is it possible to easy convert
 things like
 prob = [];
 prob.advanced.ralg.hs = 1 (so in this line all subfields are
 generating automatically in MATLAB or Octave)
 I have huge amount of such lines, and implementing separate class for
 each one is unreal.

Get used to thinking of a class as a lightweight construct written with
well-defined constraints rather than some know-it-all can-do-everything
unwieldy monster. You can of course use one class throughout

 class Struct:
... def __init__(self, **kw):
... self.__dict__.update(kw)
...
 a = Struct(f=42)
 b = Struct(x=1, y=2)
 a.f
42
 b.x, b.y
(1, 2)

but separate classes don't require much more effort and make your code both
more readable and more flexible.

Peter


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


ocaml to python

2007-02-19 Thread Gigs_
Is there any way to convert ocaml code to python? but not manually

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


World Funniest Video

2007-02-19 Thread sidoy


you can find here the World Funniest Video at

http://www.supperlaffn.blogspot.com

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


Re: (beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread openopt
Thx
but is there any simpleir way, if using not class, but just struct (or
something like that, MATLAB equivalent for that one)?
I'm thinking of rewriting some optimization solvers (non-smooth,
constrained, with (sub)gradients or patterns provided by user) to
Python and I don't know currently is it possible to easy convert
things like
prob = [];
prob.advanced.ralg.hs = 1 (so in this line all subfields are
generating automatically in MATLAB or Octave)
I have huge amount of such lines, and implementing separate class for
each one is unreal.
Thank you in advance, Dmitrey


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


Free Url submission, Forum, Free Ebooks, Articles etc

2007-02-19 Thread mona_jamil2000
Free Url submission, Forum, Free Ebooks, Articles etc.. 
http://www.aonearticles.com

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


Re: ANN: java2python 0.2

2007-02-19 Thread Troy Melhase
 Hi Troy. What is the rationale for your project?

Hi Kay,

I maintain a python port of a java library.  It finally got too
complicated to do by hand, so I wrote java2python to make my life
easier.  I wrote more extensively about the library and this tool in
my blog:

http://blog.melhase.net/articles/2007/02/15/automated-translation-of-java-to-python

I haven't documented the tool and all of it's configuration options in
detail; please let me know if I can explain something further.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I create an array of functions?

2007-02-19 Thread Steven D'Aprano
On Mon, 19 Feb 2007 00:16:39 -0800, Rob Wolfe wrote:

 
 Steven W. Orr wrote:
 I have a table of integers and each time I look up a value from the table
 I want to call a function using the table entry as an index into an array
 whose values are the different functions.  I haven't seen anything on how
 to do this in python.
 
 Do you mean something like that?
 
 # test.py
 
 def fun1(): return fun1
 def fun2(): return fun2
 def fun3(): return fun3
 
 # list of functions
 dsp = [f for fname, f in sorted(globals().items()) if callable(f)]

Hmmm... when I try that, I get dozens of other functions, not just fun1,
fun2 and fun3. And not just functions either; I also get classes.

Does Python have a function that will read my mind and only return the
objects I'm thinking of?



-- 
Steven.

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


Re: How do I create an array of functions?

2007-02-19 Thread Rob Wolfe

Steven D'Aprano wrote:
 On Mon, 19 Feb 2007 00:16:39 -0800, Rob Wolfe wrote:

 
  Steven W. Orr wrote:
  I have a table of integers and each time I look up a value from the table
  I want to call a function using the table entry as an index into an array
  whose values are the different functions.  I haven't seen anything on how
  to do this in python.
 
  Do you mean something like that?
 
  # test.py
 
  def fun1(): return fun1
  def fun2(): return fun2
  def fun3(): return fun3
 
  # list of functions
  dsp = [f for fname, f in sorted(globals().items()) if callable(f)]

 Hmmm... when I try that, I get dozens of other functions, not just fun1,
 fun2 and fun3. And not just functions either; I also get classes.

Oh, really? Where are these _other_ functions and classes
in *MY* example?

 Does Python have a function that will read my mind and only return the
 objects I'm thinking of?

Your sarcasm is unnecessary.
Using of `globals` function was easier to write this example.
That's all.

--
Rob

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


Re: How do I create an array of functions?

2007-02-19 Thread John Machin
On Feb 19, 11:47 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Mon, 19 Feb 2007 00:16:39 -0800, Rob Wolfe wrote:

  Steven W. Orr wrote:
  I have a table of integers and each time I look up a value from the table
  I want to call a function using the table entry as an index into an array
  whose values are the different functions.  I haven't seen anything on how
  to do this in python.

  Do you mean something like that?

  # test.py

  def fun1(): return fun1
  def fun2(): return fun2
  def fun3(): return fun3

  # list of functions
  dsp = [f for fname, f in sorted(globals().items()) if callable(f)]

 Hmmm... when I try that, I get dozens of other functions, not just fun1,
 fun2 and fun3. And not just functions either; I also get classes.

 Does Python have a function that will read my mind and only return the
 objects I'm thinking of?

Yup.

Stevens_mind = rfun[1-3]$

After if callable(f), put

and re.match(Stevens_mind, fname)
and not isinstance(f, type)






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


Re: Building Python Pagage for Newer Python Version

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

 Hi,
 
 I have just downloaded the source for PyXML-0.8.4, which I would like
 to build for Python 2.5. How exactly do I go about doing this?


python2.5 setup.py install usually does the trick.

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


Re: PyDev on Mac

2007-02-19 Thread Ahmer
On Feb 18, 12:01 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Ahmer schrieb:



  On Feb 18, 4:50 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Ahmer schrieb:

  I've been trying to set up PyDev on my new MacBook Pro, but i have not
  had an success.
  Could you please help!
  Just wait until my crystal ball comes back from the cleaners, and I will
  start looking at your problem.

  As you can lay back and do nothing while that happens, I suggest you
  take this highly entertaining read:

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

  Diez

  The main problem seems to be locating Python.

  Even though I installed the official python for mac, it says the
  interpreter is invalid.
  So I tried jPython, no succes on that either. It always tells me I am
  using an invlaid interpreter.

 crystal ball still not available.

 Who tells you what exactly when you do what? Is there a shell-script
 involved, what happens if you enter python at the commandline and
 press return?

 All this are uneccessary guessing games because you don't give enough
 context. Which is one of the many things mentioned on the site I
 suggested you to read. So I think you should read it again.

 Diez

Pythin runs but PyDev won't use the inerpreter. It gives me an error
saying I'm using an invalid interpreter.

Is there a way to do this using jPython?

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Muntasir Azam Khan
On Feb 17, 3:22 am, [EMAIL PROTECTED] wrote:
 I am VB6 programmer and wants to start new programming language but i
 am unable to deciced.

 i have read about Python, Ruby and Visual C++. but i want to go
 through with GUI based programming language like VB.net

 so will you please guide me which GUI based language has worth with
 complete OOPS Characteristics

 will wait for the answer

 hope to have a right direction from you Programmer

 Regards
 Iftikhar
 [EMAIL PROTECTED]

There is no other GUI based programming language like VB. That's
because there is no such thing as a GUI based programming language. If
you want to learn a real general purpose programming language try
learning python. If you are only interested in making GUI's for
windows applications, better stick with VB or any of the other .NET
languages.

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


Re: search cursor in pythonwin 2.1

2007-02-19 Thread GISDude
On Feb 18, 2:19 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Sun, 18 Feb 2007 13:12:20 -0300, GISDude [EMAIL PROTECTED]
 escribió:

  I am a GIS(geographic information systems) Analyst and in our
  software(ESRI ARCGIS 9.1) ESRI has implemented Python 2.1 as the
  scripting language of choice.

  In my script I'm going thru a dbf file and extracting NON-NULL values
  in a field. What I need to do with that is create a new dbf table with
  the values I found in it.

 I think you should either read the ArcGis documentation, or post your
 question in a specilized forum.
 Your problem is not about Python itself, but on how to use the
 esriGeoprocessing object.

  GP.Select_Analysis(neighborhoods.shp, neighborhoods_names.shp, '
  Names  \ null\ ')

 #at this point I'm stuck. how do I query out a NON-
  NULL value?
 #or a value in the Names field?

 As a side note, on a standard SQL database, the condition would read
 Names IS NOT NULL, but I don't know if this is applicable or not.

 --
 Gabriel Genellina

Gabriel,

Thanks for the reply. After looking at the docs again, you are correct
NAMES IS NOT NULL would be the correct syntax.

I thought it was NAMES  NULL

Thanks again

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


Re: Python Threads

2007-02-19 Thread Sick Monkey

Great, thanks for the tip Gabriel!

On 2/18/07, Gabriel Genellina [EMAIL PROTECTED] wrote:


En Sun, 18 Feb 2007 23:37:02 -0300, Sick Monkey [EMAIL PROTECTED]
escribió:

 Well if this cannot be done, can a thread call a function in the main
 method?
 I have been trying and have not been successive.  Perhaps I am using
 thread
 incorrectly.

The safe way to pass information between threads is to use Queue. From
inside the working thread, you put() an item with enough state
information. On the main (GUI) thread, you use after() to check for any
data in the queue, and then update the interfase accordingly.
I think there is a recipe in the Python Cookbook
http://aspn.activestate.com/ASPN/Cookbook/Python

--
Gabriel Genellina

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

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

Re: Help Required for Choosing Programming Language

2007-02-19 Thread Steve Holden
Muntasir Azam Khan wrote:
 On Feb 17, 3:22 am, [EMAIL PROTECTED] wrote:
 I am VB6 programmer and wants to start new programming language but i
 am unable to deciced.

 i have read about Python, Ruby and Visual C++. but i want to go
 through with GUI based programming language like VB.net

 so will you please guide me which GUI based language has worth with
 complete OOPS Characteristics

 will wait for the answer

 hope to have a right direction from you Programmer

 Regards
 Iftikhar
 [EMAIL PROTECTED]
 
 There is no other GUI based programming language like VB. That's
 because there is no such thing as a GUI based programming language. If
 you want to learn a real general purpose programming language try
 learning python. If you are only interested in making GUI's for
 windows applications, better stick with VB or any of the other .NET
 languages.
 
It's also worth remembering that you can use COM to drive a VB interface 
from Python, and of course there's now IronPython that allows you to use 
.NET-based interfaces directly.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Andy Dingley
On 16 Feb, 21:22, [EMAIL PROTECTED] wrote:
 I am VB6 programmer and wants to start new programming language

Why?  What is causing you to do this, and what do you need to achieve
by doing it?

 i want to go through with GUI based programming language like VB.net

GUI-based is fairly unimportant as it's just how you build your
programs, not what they do afterwards. VB is GUI-based, Python can be
GUI-based but is usually fairly text-based.

What's probably more significant here is whether the resulting program
runs in a GUI or not. VB obviously does, on the Windows desktop. Java
also has a sizable market for cross-platform GUI applications. In many
ways Java is more capable than VB, but also far less easy to work with
for rapid simple applications (I'd take 10 year old VB over GridBag
any time!).

GUI programs are less important now than they were a few years ago,
owing to the huge importance of the web and HTML. Although HTML can
still be seen as GUI, it really needs to be worked with at the raw
HTML source level (at least for quality work). This doesn't need any
sort of GUI built into the language, so Python (or Ruby or Perl) are
ideal.

With the rise of AJAX toolkits, we're finally seeing HTML as a GUI
turn into a workable choice for building sophisticated GUI apps in a
sensible amount of time. Finally!  The tools used here depend
significantly on the toolkits used and it's still early days to pick
winners.

If I had to write Windows-only desktop GUI apps, then I'd stick with
VB6 (which I wrote for years) or whatever M$oft decree to be its moral
successor. Actually I'd probably stick with VB6

If I had to write cross-platform GUI desktop apps, then I'd be looking
at whatever the favoured toolkit for Java is this week. Maybe Swing,
if I wanted to get a paid job using it. Java Web Start needs looking
at too.

If I just had to make a sophisiticated GUI app appear on a lot of
corporate desktops, then it would probably be based on Java Server
Faces.


For nearly all of the choices above, the language part of the task
is minor in comparison to tiresome GUI building. That's just the way
commerce works, and why we don't all get to write everything in Scheme
or Haskell.


If I had a free hand in writing better shell scripts, or in writing
moderately complex algorithms with no visible UI, then I have chosen
Python. It beats the hell out of Perl and is (AFAICS) better than
Ruby.

For building web reporting apps that generate HTML, then I'm also
choosing to use my sparse Python knowledge rather than my substantial
Java / JSP knowledge. Seems to be working so far.

For web-hosted GUI apps, I don't know enough about Python to say.
Doesn't look like it beats JSF though.


There's also the question of what OOP means. For the mainstream
languages, then classic statically-typed OO is done best by writing in
Java. This has a cleaner OOP language design than C++, the benefit of
a decade's hindsight and a clean slate.

Dynamically or duck-typed languages like Python and Ruby are quite
different from this. It's still OOP, but not how your uncle Bjarne
knew it. Quite a culture shock too.

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


Re: Does Python have equivalent to MATLAB varargin, varargout, nargin, nargout?

2007-02-19 Thread Robert Kern
[EMAIL PROTECTED] wrote:
 Ok, thx
 But can I somehow determing how many outputs does caller func require?
 for example:
 MATLAB:
 function [objFunVal firstDerive secondDerive] = simpleObjFun(x)
 objFunVal = x^3;
 if nargout1
 firstDerive = 3*x^2;
 end
 if nargout2
 secondDerive = 6*x;
 end
 
 So if caller wants only
 [objFunVal firstDerive] = simpleObjFun(15)
 than 2nd derivatives don't must to be calculated with wasting cputime.
 Is something like that in Python?

Return an object with each of the results objFunVal, firstDerive, and
secondDerive as attributes (or a dictionary). Use keyword arguments to inform
the function of which ancillary computations it needs to perform.

If at all possible, don't change the number of return values. It's annoying to
deal with such an API.

-- 
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: (beginners question) howto set self.field4.subfield8='asdf'?

2007-02-19 Thread Stargaming
[EMAIL PROTECTED] wrote:
 Thx
 but is there any simpleir way, if using not class, but just struct (or
 something like that, MATLAB equivalent for that one)?

Use this::

  A = type('', (), {})
  a = A()
  a
__main__. object at 0x009E8490
  a.foo = 42
  a.foo
42

But perhaps using this (with a better name) would be more sensible 
(according to readability)::

  class B: pass
...
  b = B()
  b.foo = 42
  b.foo
42

 I'm thinking of rewriting some optimization solvers (non-smooth,
 constrained, with (sub)gradients or patterns provided by user) to
 Python and I don't know currently is it possible to easy convert
 things like
 prob = [];
 prob.advanced.ralg.hs = 1 (so in this line all subfields are
 generating automatically in MATLAB or Octave)

Perhaps something like this would be suitable::

  class Autocreating(object):
...   def __getattr__(self, attr):
... if hasattr(self, attr)
...   setattr(self, attr, Autocreating())
... return getattr(self, attr)
...
  a = Autocreating()
  a.foo = 42
  a.foo
42
  a.hello.world = 23
  a.hello
__main__.Autocreating object at 0x...
  a.hello.world
23

But this is perhaps not a good way because it's way too implicite.

 I have huge amount of such lines, and implementing separate class for
 each one is unreal.

You don't have to implement a separate class for *each one*. Use one 
class for every attribute, you can reuse it. But perhaps something like 
a dict is better for your purposes, anyways.

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


Re: timeout in urllib.open()

2007-02-19 Thread Steve Holden
Stefan Palme wrote:
 [Peter]
 I believe this can only be set globally:

 import socket
 socket.setdefaulttimeout(seconds)

 [Stefan]
 ...
 But when there is a default timeout (as indicated by
 the method name) - isn't there a per-socket timeout
 too?
 [Peter]
 Yes, but it isn't as easily available...

 Perhaps you find some ideas here:

 http://mail.python.org/pipermail/python-dev/2007-February/070897.html
 
 Thanks, will have a look at this.
 
This has recently been discussed on python-dev. It's likely that certain 
libraries will acquire a timeout keyword argument in the next release, 
but only if someone is concerned enough to develop the appropriate 
patches - the principle appears to be accepted.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: PyDev on Mac

2007-02-19 Thread Fabio Zadrozny


Pythin runs but PyDev won't use the inerpreter. It gives me an error
saying I'm using an invalid interpreter.

Is there a way to do this using jPython?



Pydev usually outputs something into your error log when it says you've
specified an invalid interpreter... can you check it? (see
http://pydev.sourceforge.net/faq.html#ref_0 for details on how to find it)
-- your problem might be that you're specifying a link to the interpreter
and not the actual interpreter (unfortunately java does not deal well with
symlinks).

It should also work with jython (jython 2.1 is the officially supported
version).

Cheers,

Fabio

p.s. I also recommend that you take a look at the getting started manual:
http://fabioz.com/pydev/manual_101_root.html
-- 
http://mail.python.org/mailman/listinfo/python-list

Declare a variable global

2007-02-19 Thread [EMAIL PROTECTED]
Hi,

I have the following code:

colorIndex = 0;

def test():
 print colorIndex;

This won't work.   But it works if i do this:

colorIndex = 0;

def test():
 global colorIndex;
 print colorIndex;

My question is why do I have to explicit declaring 'global' for
'colorIndex'?  Can't python automatically looks in the global scope
when i access 'colorIndex' in my function 'test()'?

Thank you.

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


Re: Declare a variable global

2007-02-19 Thread Jean-Paul Calderone


On 19 Feb 2007 09:04:19 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hi,

I have the following code:

colorIndex = 0;

def test():
 print colorIndex;

This won't work.

Are you sure?

[EMAIL PROTECTED]:~$ cat foo.py
colorIndex = 0

def test():
print colorIndex

test()
[EMAIL PROTECTED]:~$ python foo.py
0
[EMAIL PROTECTED]:~$   

The global keyword lets you rebind a variable from the module scope.  It
doesn't have much to do with accessing the current value of a variable.

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


Re: timeout in urllib.open()

2007-02-19 Thread Paul Rubin
Stefan Palme [EMAIL PROTECTED] writes:
 is there a way to modify the time a call of
 
   urllib.open(...)
 
 waits for an answer from the other side? Have a tool which
 automatically checks a list of websites for certain content. The
 tool hangs when one of the contacted websites behaves badly and
 never answers...

Other than by using socket timeouts, at least in Un*x, you can also
use signal.alarm.  You can only have one OS-provided alarm pending at
a time, so if you want multiple overlapping timeouts you have to
schedule them yourself with a single alarm.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Declare a variable global

2007-02-19 Thread [EMAIL PROTECTED]
On Feb 19, 11:09 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 19 Feb 2007 09:04:19 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi,

 I have the following code:

 colorIndex = 0;

 def test():
  print colorIndex;

 This won't work.

 Are you sure?

 [EMAIL PROTECTED]:~$ cat foo.py
 colorIndex = 0

 def test():
 print colorIndex

 test()
 [EMAIL PROTECTED]:~$ python foo.py
 0
 [EMAIL PROTECTED]:~$

 The global keyword lets you rebind a variable from the module scope.  It
 doesn't have much to do with accessing the current value of a variable.

 Jean-Paul

Thanks. Then I don't understand why I get this error in line 98:

 Traceback (most recent call last):
  File ./gensvg.py, line 109, in ?
outdata, minX, minY, maxX, maxY = getText(data);
  File ./gensvg.py, line 98, in getText
print colorIndex;
UnboundLocalError: local variable 'colorIndex' referenced before
assignment


Here is my complete script:
#!/usr/bin/python

import re
import sys
import time
import os
import shutil

colors = [#FF,  #00FF00, #FF,
#00 ,#FFA500 ,#DA70D6]
colorIndex = 0

def getText( intputstr):
rc = 

maxX = 0;
maxY = 0;
minX = 1000;
minY = 1000;


for str in intputstr:

print str;

if str != :
pattern = x:(\d+) y:(\d+) w:(\d+) h:(\d+) (.*)

match = re.findall(pattern, str)

if match:
x, y, width, height, area = match[0]

colorIndex = colorIndex + 1

rc = rc + rect x=\%(x)s\ y=\%(y)s\ width=\%
(width)s\ height=\%(height)s\  % locals()

rc = rc + fill=\%s\ stroke=\#00\ stroke-width=
\1px\ fill-opacity=\.5\ /\n  % colors[colorIndex  % len(colors)]

_x = int(x)
_y = int(y)
_width = int(width)
_height = int(height)

minX = min(minX, _x);
minY = min(minY, _y);

maxX = max(maxX, _x+ _width);
maxY = max(maxY, _y+_height);



else:
pattern = \((\d+),(\d+)\)\((\d+),(\d+)\)(.*)

match = re.findall(pattern, str)

if match:
x1, y1, x2, y2, ignore = match[0]

rc = rc + line x1=\%(x1)s\ y1=\%(y1)s\ x2=\%
(x2)s\ y2=\%(y2)s\ style=\stroke:rgb(99,99,99);stroke-width:2\ /
 % locals()
rc = rc + \n

_x1 = int(x1)
_y1 = int(y1)
_x2 = int(x2)
_y2 = int(y2)

minX = min(_x1, _x2);
minY = min(_y1, _y2);

maxX = max(_x1, _x2);
maxY = max(_y1, _y2);

print colorIndex;

print  match 2!


return rc, minX, minY, maxX, maxY;

fileName = sys.argv[1]

inputFile = open(fileName, 'r')
data = inputFile.readlines();
outdata, minX, minY, maxX, maxY = getText(data);

print  minX, minY, maxX, maxY

outputFile = open(fileName + '.svg', 'w')

print  outputFile, svg xmlns=\http://www.w3.org/2000/svg\;
xmlns:xlink=\http://www.w3.org/1999/xlink\; id=\body\

outputFile.write(outdata);

print outputFile, /svg


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


Raw Imager

2007-02-19 Thread Andrew
Im looking at building a tool for previewing raw images as Thumbnails no 
editing really just viewing in a simple Tkinter GUI however from what I 
can tell Pil does not support raw images

Does anyone have a link to a module that would allow this

I guess I would need support for as many different raw types as 
possible... if possible.


Cheers


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


Re: Declare a variable global

2007-02-19 Thread Gary Herron
[EMAIL PROTECTED] wrote:
 Hi,

 I have the following code:

 colorIndex = 0;

 def test():
  print colorIndex;

 This won't work.   But it works if i do this:
   
Yes, it does work. Can you be more explicit about why you think it doesn't?

(Also, this is Python not C/C++. Get *RID* of the semi-colons after your 
statements!)

 colorIndex = 0;

 def test():
  global colorIndex;
  print colorIndex;
   
If you wish to change the value of colorIndex inside test, then this 
won't work

colorIndex = 0

def test():
 colorIndex=123   # creates a new variable within test

In the above case you'll end up with two variables of that name, one in the 
global context, and the other within test's context.

However, this code might be more what you want:

colorIndex = 0

def test():
 global colorIndex
 colorIndex=123   # changes the value of the global


Better yet, restructure your code to not rely on the global statement.  Do 
something like this if you can:


def test():
return 123

colorIndex = test() 

Gary Herron

 My question is why do I have to explicit declaring 'global' for
 'colorIndex'?  Can't python automatically looks in the global scope
 when i access 'colorIndex' in my function 'test()'?

 Thank you.

   

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Mark Morss
On Feb 16, 4:22 pm, [EMAIL PROTECTED] wrote:
 I am VB6 programmer and wants to start new programming language but i
 am unable to deciced.

 i have read about Python, Ruby and Visual C++. but i want to go
 through with GUI based programming language like VB.net

 so will you please guide me which GUI based language has worth with
 complete OOPS Characteristics

 will wait for the answer

 hope to have a right direction from you Programmer

 Regards
 Iftikhar
 [EMAIL PROTECTED]

Good grief.  I suppose it is Microsoft to whom we owe the idea that
there could be such a thing as a GUI based programming language.

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


Re: Declare a variable global

2007-02-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 On Feb 19, 11:09 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 19 Feb 2007 09:04:19 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED]
 wrote:

 Hi,

 I have the following code:

 colorIndex = 0;

 def test():
  print colorIndex;

 This won't work.

 Are you sure?

 [EMAIL PROTECTED]:~$ cat foo.py
 colorIndex = 0

 def test():
 print colorIndex

 test()
 [EMAIL PROTECTED]:~$ python foo.py
 0
 [EMAIL PROTECTED]:~$

 The global keyword lets you rebind a variable from the module scope.  It
 doesn't have much to do with accessing the current value of a variable.

 Jean-Paul
 
 Thanks. Then I don't understand why I get this error in line 98:
 
  Traceback (most recent call last):
   File ./gensvg.py, line 109, in ?
 outdata, minX, minY, maxX, maxY = getText(data);
   File ./gensvg.py, line 98, in getText
 print colorIndex;
 UnboundLocalError: local variable 'colorIndex' referenced before
 assignment

When there is an assignment python assumes that the variable is in the local
scope (unless you explicitly declare it as global):

 v = 42
 def f():
... print v
...
 f()
42
 def g():
... print v
... v = won't get here anyway
...
 g()
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in g
UnboundLocalError: local variable 'v' referenced before assignment
 def h():
... global v
... print v
... v = for all the world to see
...
 h()
42
 v
'for all the world to see'

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


Re: Declare a variable global

2007-02-19 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

 I have the following code:
 
 colorIndex = 0;
 
 def test():
  print colorIndex;

Don't use ;. It's redundant.
 
 This won't work.   But it works if i do this:
 
 colorIndex = 0;
 
 def test():
  global colorIndex;
  print colorIndex;
 
 My question is why do I have to explicit declaring 'global' for
 'colorIndex'?

Because you could want to have an identifier called colorIndex in
test's scope. Globals are infrequently used in Python, thus the
more common case is assumed by default.

 Can't python automatically looks in the global scope when i
 access 'colorIndex' in my function 'test()'? 

No, it can't looks.

Regards,


Björn

-- 
BOFH excuse #66:

bit bucket overflow

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


Re: What is more efficient?

2007-02-19 Thread Karlo Lozovina
Gabriel Genellina [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 It doesn't matter whether you have 0 or a million  instances,
 methods do not occupy more memory.

That's what I was looking for! 
Thanks, to you and all the others.

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function class

2007-02-19 Thread Bjoern Schliessmann
jupiter wrote:

 I am getting this error when I am using sql command within
 class.function accessing from another class
 
 how can I create seperate instance for sqlite objects ???

Trying to help you gets boring. I suggest reading the material
that's being offered.

Regards,


Björn

-- 
BOFH excuse #241:

_Rosin_ core solder? But...

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


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Peter Decker
On 19 Feb 2007 09:56:06 -0800, Mark Morss [EMAIL PROTECTED] wrote:

 Good grief.  I suppose it is Microsoft to whom we owe the idea that
 there could be such a thing as a GUI based programming language.

Who do we blame for the idea that everyone in the world should be able
to express themselves in perfect English without confusion?

It was obvious what the OP meant. He's looking for something akin to
VB, but in Python.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to detect closing of wx.Panel?

2007-02-19 Thread Jacol
Morpheus wrote:

 On Mon, 19 Feb 2007 01:18:11 +, Jacol wrote:
 
 Hi everybody,
 
 I have poblem with detecting closing of wx.Panel by user. How to detect
 that event?
 
 Don't know why you want to do that, but you could register with the
 enclosing (hosting) widget.

In my program a panel is related to a plugin's object. I mean if a panel is
closed the object have to be deleted also. Currently it doesn't work  i
have e memory leak. But i think i'll fixed a panel with its object
directly. 

Currently i did it like that:


mainframe(wx.Frame)
subobject--- pluginsmanager --object (a hash session=object )
subobject--- panel

The panel send to pluginsmanager its own session no and received from that
XRC. But it is too complicated. I have to do it more simpler.

More @ pentrezy.cvs.sf.net// 

Best wishes,
Jacek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyDev on Mac

2007-02-19 Thread Ahmer
On Feb 18, 4:50 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Ahmer schrieb:

  I've been trying to set up PyDev on my new MacBook Pro, but i have not
  had an success.

  Could you please help!

 Just wait until my crystal ball comes back from the cleaners, and I will
 start looking at your problem.

 As you can lay back and do nothing while that happens, I suggest you
 take this highly entertaining read:

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

 Diez

The error I am getting is:

 Check your error log for more details.

More info can also be found at the bug report:
http://sourceforge.net/tracker/index.php?func=detailaid=1523582group_id=85796atid=577329


I am trying to use Jython since I am mainly a Java programmer.

The bug report is not very helpful

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


Re: PyDev on Mac

2007-02-19 Thread Fabio Zadrozny

On 19 Feb 2007 10:41:41 -0800, Ahmer [EMAIL PROTECTED] wrote:


On Feb 18, 4:50 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Ahmer schrieb:

  I've been trying to set up PyDev on my new MacBook Pro, but i have not
  had an success.

  Could you please help!

 Just wait until my crystal ball comes back from the cleaners, and I will
 start looking at your problem.

 As you can lay back and do nothing while that happens, I suggest you
 take this highly entertaining read:

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

 Diez

The error I am getting is:

Check your error log for more details.

More info can also be found at the bug report:

http://sourceforge.net/tracker/index.php?func=detailaid=1523582group_id=85796atid=577329


I am trying to use Jython since I am mainly a Java programmer.



And what's in your error log?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Declare a variable global

2007-02-19 Thread Terry Reedy
| Here is my complete script:
| #!/usr/bin/python
|
| import re
| import sys
| import time
| import os
| import shutil
|
| colors = [#FF,  #00FF00, #FF,
| #00 ,#FFA500 ,#DA70D6]
| colorIndex = 0
|
| def getText( intputstr):
|rc = 
|
|maxX = 0;
|maxY = 0;
|minX = 1000;
|minY = 1000;
|
|
|for str in intputstr:
|
|print str;
|
|if str != :
|pattern = x:(\d+) y:(\d+) w:(\d+) h:(\d+) (.*)
|
|match = re.findall(pattern, str)
|
|if match:
|x, y, width, height, area = match[0]
|
|colorIndex = colorIndex + 1
|
|rc = rc + rect x=\%(x)s\ y=\%(y)s\ width=\%
| (width)s\ height=\%(height)s\  % locals()
|
|rc = rc + fill=\%s\ stroke=\#00\ stroke-width=
| \1px\ fill-opacity=\.5\ /\n  % colors[colorIndex  % len(colors)]
|
|_x = int(x)
|_y = int(y)
|_width = int(width)
|_height = int(height)
|
|minX = min(minX, _x);
|minY = min(minY, _y);
|
|maxX = max(maxX, _x+ _width);
|maxY = max(maxY, _y+_height);
|
|
|
|else:
|pattern = \((\d+),(\d+)\)\((\d+),(\d+)\)(.*)
|
|match = re.findall(pattern, str)
|
|if match:
|x1, y1, x2, y2, ignore = match[0]
|
|rc = rc + line x1=\%(x1)s\ y1=\%(y1)s\ x2=\%
| (x2)s\ y2=\%(y2)s\ style=\stroke:rgb(99,99,99);stroke-width:2\ /
|  % locals()
|rc = rc + \n
|
|_x1 = int(x1)
|_y1 = int(y1)
|_x2 = int(x2)
|_y2 = int(y2)
|
|minX = min(_x1, _x2);
|minY = min(_y1, _y2);
|
|maxX = max(_x1, _x2);
|maxY = max(_y1, _y2);
|
|print colorIndex;
|
|print  match 2!
|
|
|return rc, minX, minY, maxX, maxY;
|
| fileName = sys.argv[1]
|
| inputFile = open(fileName, 'r')
| data = inputFile.readlines();
| outdata, minX, minY, maxX, maxY = getText(data);
|
| print  minX, minY, maxX, maxY
|
| outputFile = open(fileName + '.svg', 'w')
|
| print  outputFile, svg xmlns=\http://www.w3.org/2000/svg\;
| xmlns:xlink=\http://www.w3.org/1999/xlink\; id=\body\
|
| outputFile.write(outdata);
|
| print outputFile, /svg
|
|
| -- 
| http://mail.python.org/mailman/listinfo/python-list
| 



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


Re: ocaml to python

2007-02-19 Thread Jon Harrop
Gigs_ wrote:
 Is there any way to convert ocaml code to python? but not manually

Translating between dissimilar high-level languages is very difficult, so
difficult that it is hard to do such a task justice by hand, let alone
automating the procedure.

If you must do it then write a compiler that converts OCaml's intermediate
representation into Python (after pattern match compilation), or write an
OCaml bytecode interpreter in Python.

For example, the following simple OCaml code is difficult to write in
Python:

let rec ( +: ) f g = match f, g with
  | `Q n, `Q m - `Q (n +/ m)
  | `Q (Int 0), e | e, `Q (Int 0) - e
  | f, `Add(g, h) - f +: g +: h
  | f, g - `Add(f, g)

let rec ( *: ) f g = match f, g with
  | `Q n, `Q m - `Q (n */ m)
  | `Q (Int 0), e | e, `Q (Int 0) - `Q (Int 0)
  | `Q (Int 1), e | e, `Q (Int 1) - e
  | f, `Mul(g, h) - f *: g *: h
  | f, g - `Mul(f, g)

let rec simplify = function
  | `Q _ | `Var _ as e - e
  | `Add(f, g) - simplify f +: simplify g
  | `Mul(f, g) - simplify f *: simplify g;;

OCaml compiles the pattern matches first, which gives an intermediate
representation much closer to something Python/Lisp can handle:

(seq
  (letrec
(+:/71
   (function f/72 g/73
 (catch
   (catch
 (if (isint f/72) (exit 3)
   (if (!= (field 0 f/72) 81) (exit 3)
 (let (n/74 (field 1 f/72))
   (catch
 (if (isint g/73) (exit 4)
   (if (!= (field 0 g/73) 81) (exit 4)
 (makeblock 0 81
   (apply (field 0 (global Num!)) n/74
 (field 1 g/73)
with (4)
 (switch n/74
  case tag 0: (if (!= (field 0 n/74) 0) (exit 3) g/73)
  default: (exit 3))
with (3)
 (if (isint g/73) (exit 2)
   (let (variant/113 (field 0 g/73))
 (if (!= variant/113 81)
   (if (!= variant/113 3254785) (exit 2)
 (let (match/112 (field 1 g/73))
   (apply +:/71 (apply +:/71 f/72 (field 0 match/112))
 (field 1 match/112
   (let (match/110 (field 1 g/73))
 (switch match/110
  case tag 0:
   (if (!= (field 0 match/110) 0) (exit 2) f/72)
  default: (exit 2)))
  with (2) (makeblock 0 3254785 (makeblock 0 f/72 g/73)
(apply (field 1 (global Toploop!)) +: +:/71))
  (letrec
(*:/83
   (function f/84 g/85
 (catch
   (catch
 (catch
   (catch
 (catch
   (if (isint f/84) (exit 10)
 (if (!= (field 0 f/84) 81) (exit 10)
   (let (n/86 (field 1 f/84))
 (catch
   (if (isint g/85) (exit 11)
 (if (!= (field 0 g/85) 81) (exit 11)
   (makeblock 0 81
 (apply (field 5 (global Num!)) n/86
   (field 1 g/85)
  with (11)
   (switch n/86
case tag 0:
 (if (!= (field 0 n/86) 0) (exit 10) (exit 5))
default: (exit 10))
  with (10)
   (if (isint g/85) (exit 9)
 (if (!= (field 0 g/85) 81) (exit 9)
   (let (match/121 (field 1 g/85))
 (switch match/121
  case tag 0:
   (if (!= (field 0 match/121) 0) (exit 9) (exit 5))
  default: (exit 9))
with (9)
 (if (isint f/84) (exit 8)
   (if (!= (field 0 f/84) 81) (exit 8)
 (let (match/124 (field 1 f/84))
   (switch match/124
case tag 0:
 (if (!= (field 0 match/124) 1) (exit 8) g/85)
default: (exit 8))
  with (8)
   (if (isint g/85) (exit 7)
 (let (variant/130 (field 0 g/85))
   (if (!= variant/130 81)
 (if (!= variant/130 3855332) (exit 7)
   (let (match/129 (field 1 g/85))
 (apply *:/83 (apply *:/83 f/84 (field 0 match/129))
   (field 1 match/129
 (let (match/127 (field 1 g/85))
   (switch match/127
case tag 0:
 (if (!= (field 0 match/127) 1) (exit 7) f/84)
default: (exit 7)))
with (7) (makeblock 0 3855332 (makeblock 0 f/84 g/85)))
  with (5) [0: 81 [0: 0]])))
(apply (field 1 

Forking SocketServer daemon -- updating state

2007-02-19 Thread Reid Priedhorsky
Hi folks,

I am implementing a forking SocketServer daemon that maintains significant
internal state (a graph that takes ~30s to build by fetching from a SQL
database, and eventually further state that may take up to an hour to
build).

I would like to be able to notify the daemon that it needs to update its
state. Because it forks for each new request, a request handler can't
update the state because then only the child would have the new state.

One idea I had was to use signals. Is it safe to write a signal handler
that does extensive work (several seconds)? Seems like even so, it might
be tricky to do this without race conditions.

Another possibility is that the signal handler simply sets a needs_update
flag, which I could check for in a handle_request() loop. The disadvantage
here is that the update wouldn't happen until after the next request is
handled, and I would like the state to be available for that next request.
A solution might be to send a signal followed by a dummy request, which
seems a bit awkward.

Any other ideas or suggestions?

Thanks in advance,

Reid

p.s. This group's help on A* search was very much appreciated -- just the
ticket!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forking SocketServer daemon -- updating state

2007-02-19 Thread Irmen de Jong
Reid Priedhorsky wrote:

 Another possibility is that the signal handler simply sets a needs_update
 flag, which I could check for in a handle_request() loop. The disadvantage
 here is that the update wouldn't happen until after the next request is
 handled, and I would like the state to be available for that next request.
 A solution might be to send a signal followed by a dummy request, which
 seems a bit awkward.
 
 Any other ideas or suggestions?

Just send a special type of request that signifies that an update is 
wanted, and act on that?

Basically you need to find a way to let two processes talk to each 
other. There are a lot of possibilities here (IPC). The simplest
would be to reuse the one you already have (the request handler!).
Another solution might be to use Pyro.
Or just open a custom socket yourself to send messages.
Or stick with your idea of using a signal handler. But I don't know
if you can let a signal handler run for a long time (as you already
asked yourself), and it won't be portable to Windows for instance.

You could maybe use threads instead, and then use some form of
thread synchronization primitives such as threading.Event
(threads would remove the need to do IPC).

Hope this helps a bit,

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


How to call a function defined in another py file

2007-02-19 Thread silverburgh . meryl
Hi,

I have a function called 'test' defined in A.py.
How can I call that function test in my another file B.py?

Thank you.

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


Re: How to call a function defined in another py file

2007-02-19 Thread Martin Blume
[EMAIL PROTECTED] schrieb 
 
 I have a function called 'test' defined in A.py.
 How can I call that function test in my another file B.py?
 
In B.py:

import A

A.test()


HTH
Martin


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


Re: Getting a class name

2007-02-19 Thread Fuzzyman
On Feb 19, 5:11 am, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman [EMAIL PROTECTED] escribió:



  [somebody] wrote:
def getCodeName(deap=0):
return sys._getframe(deap+1).f_code.co_name

class MyClass (object):
name = getCodeName() + '!'

   What's the advantage over MyClass.__name__?
   I were asking, why do you want a name attribute since __name__
   already  exists and has the needed information. And worst, using an
   internal  implementation function to do such task.

  This might be useful to avoid metaclass hacks when trying to initialize
  a class attribute that would require the class name. (my 2 cents)

  It's still an ugly hack. :-)
  (But a nice implementation detail to know about none-the-less.)

 Having class decorators would be nice...


Yes - and Guido said he wouldn't be opposed to the idea when it was
poitned out that they would be very useful for both IronPython and
Jython to implement features of their underlying platforms.

I haven't heard anyone (other than you) mention them recently
though...

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml

 --
 Gabriel Genellina


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


Re: How to call a function defined in another py file

2007-02-19 Thread silverburgh . meryl
On Feb 19, 2:22 pm, Martin Blume [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] schrieb

  I have a function called 'test' defined in A.py.
  How can I call that function test in my another file B.py?

 In B.py:

 import A

 A.test()

 HTH
 Martin

But Do I need to put A.py and B.py in the same directory?
if not, where does python look for A.py ?
And do I need to compile A.py before I can import it to B.py?

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


Re: bluetooth on windows.......

2007-02-19 Thread M�ta-MCI
Hi! 

 try to find a PyBluez version already built for your Python 2.5

On the site : 
  http://org.csail.mit.edu/pybluez/release/PyBluez-0.9.1.win32-py2.5.exe



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


Re: How to call a function defined in another py file

2007-02-19 Thread Jeremy Gransden
from a import test


be sure a is in your path.


jeremy

On Feb 19, 2007, at 3:20 PM, [EMAIL PROTECTED] wrote:

 Hi,

 I have a function called 'test' defined in A.py.
 How can I call that function test in my another file B.py?

 Thank you.

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

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


Re: How to call a function defined in another py file

2007-02-19 Thread Jeremy Gransden

On Feb 19, 2007, at 3:27 PM, [EMAIL PROTECTED] wrote:

 On Feb 19, 2:22 pm, Martin Blume [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] schrieb

 I have a function called 'test' defined in A.py.
 How can I call that function test in my another file B.py?

 In B.py:

 import A

 A.test()

 HTH
 Martin

 But Do I need to put A.py and B.py in the same directory?
 if not, where does python look for A.py ?
No, they do not have to be in the same directory. A.py needs to be in  
your path.

 And do I need to compile A.py before I can import it to B.py?

No




jeremy


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


Re: How to call a function defined in another py file

2007-02-19 Thread Martin Blume
[EMAIL PROTECTED] schrieb

 I have a function called 'test' defined in A.py.
 How can I call that function test in my another file B.py?

 In B.py:
   import A
   A.test()

 
 But Do I need to put A.py and B.py in the same directory?
No, but then you have to take certain precautions. (*)

 if not, where does python look for A.py ?
In the path defined by the (IIRC) PYTHONPATH (*)

 And do I need to compile A.py before I can import it to B.py?
No.

(*) you might want to read the fine documentation at
http://docs.python.org/tut/node8.html
which tells it much better than I do, and might give you 
some more ideas for googling.
I haven't had yet the necessity for cross-directory imports.

HTH
Martin



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


Re: How to call a function defined in another py file

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Hi,
 
 I have a function called 'test' defined in A.py.
 How can I call that function test in my another file B.py?
 
 Thank you.
 

# b.py

import A
A.test()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Declare a variable global

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 Hi,
 
 I have the following code:
 
 colorIndex = 0;

You don't need the ;

 
 def test():
  print colorIndex;

Idem.

 This won't work.

Why ?

Or more exactly : for which definition of won't work ? (hint: this 
code prints 0 on sys.stdout - I don't know what else you where expecting...)

   But it works if i do this:
 
 colorIndex = 0;
 
 def test():
  global colorIndex;
  print colorIndex;

Have mercy : keep those ; out of here.

 My question is why do I have to explicit declaring 'global' for
 'colorIndex'?  Can't python automatically looks in the global scope
 when i access 'colorIndex' in my function 'test()'?

It does. You only need to declare a name global in a function if you 
intend to rebind the name in the function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Bruno Desthuilliers
Hendrik van Rooyen a écrit :
  Bruno Desthuilliers [EMAIL PROTECTED] wrote:
 
 
 
Stef Mientki a écrit :
(snip)

I've been using Python for just 2 months, and didn't try any graphical
design,

So how can you comment on GUI programming with Python ?
 
 
 I think we have a language problem here (no pun intended)
 
 When Stef says Gui Programming he means using something like
 Delphi or Boa to do the Graphical Layout, while on this group it
 normally means writing the python code to make your own windows
 etc., using Tkinter or better...

It's now the *3rd* time I mention Glade, wxGlade and QTDesigner in this 
thread. Hendrik, I know *exactly* what Stef is talking about - been 
here, done that.

 So from Stef's perspective he is right when he claims that Python's
 Gui Programming is poor - in the standard library it is non existent,
 as there are no Delphi-, Glade- or Boa-like tools available.
 
 And one can argue that something like Boa or the WX.. packages are
 not Python, as they are not included in the standard library...
 

Then ObjectPascal his poor too. All the GUI part of Delphi is to 
ObjectPascal what wxPython etc are to Python.

 From thiw POV, Python is much richer than ObjectPascal : you have at 
least 3 or 4 usable GUI toolkits, at least two of them being 
full-featured and cross-platform.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 On Feb 16, 4:22 pm, [EMAIL PROTECTED] wrote:
 
I am VB6 programmer and wants to start new programming language but i
am unable to deciced.

i have read about Python, Ruby and Visual C++. but i want to go
through with GUI based programming language like VB.net

so will you please guide me which GUI based language has worth with
complete OOPS Characteristics

will wait for the answer

hope to have a right direction from you Programmer

Regards
Iftikhar
[EMAIL PROTECTED]
 
 
 Despite what real programmers and various apologists might say,
 there isn't much out there that comes close to the ease-of-use and
 functionality of VB when it comes to designing a GUI.  

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


Re: Declare a variable global

2007-02-19 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
 On Feb 19, 11:09 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 
On 19 Feb 2007 09:04:19 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


Hi,

I have the following code:

colorIndex = 0;

def test():
print colorIndex;

This won't work.

Are you sure?

[EMAIL PROTECTED]:~$ cat foo.py
colorIndex = 0

def test():
print colorIndex

test()
[EMAIL PROTECTED]:~$ python foo.py
0
[EMAIL PROTECTED]:~$

The global keyword lets you rebind a variable from the module scope.  It
doesn't have much to do with accessing the current value of a variable.

Jean-Paul
 
 
 Thanks. Then I don't understand why I get this error in line 98:
 
  Traceback (most recent call last):
   File ./gensvg.py, line 109, in ?
 outdata, minX, minY, maxX, maxY = getText(data);
   File ./gensvg.py, line 98, in getText
 print colorIndex;
 UnboundLocalError: local variable 'colorIndex' referenced before
 assignment
 
 
 Here is my complete script:
 #!/usr/bin/python
 
 import re
 import sys
 import time
 import os
 import shutil
 
 colors = [#FF,  #00FF00, #FF,
 #00 ,#FFA500 ,#DA70D6]
 colorIndex = 0
 
 def getText( intputstr):
 rc = 
 
 maxX = 0;
 maxY = 0;
 minX = 1000;
 minY = 1000;
 
 
 for str in intputstr:

don't use str as an indentifier unless it's ok for you to shadow the 
builtin type str.

 print str;
 
 if str != :
   if str:
 pattern = x:(\d+) y:(\d+) w:(\d+) h:(\d+) (.*) 
 match = re.findall(pattern, str)

Move loop invariants (here, your pattern) outside of the loop. And while 
you're at it, compile it.

 if match:
 x, y, width, height, area = match[0]
 
 colorIndex = colorIndex + 1

You're not reading colorIndex, you're rebinding it. In this case, you do 
need to declare it global (or better, to rethink your code to avoid 
globals).

 rc = rc + rect x=\%(x)s\ y=\%(y)s\ width=\%
 (width)s\ height=\%(height)s\  % locals()

Using augmented assignment (ie : +=) may be more readable here (MHO).
Also, if you use single quotes for the template string, you can save the 
escapes:
   rc += 'rect x=%(x)s y=%(y)s width=%
  (width)s  height=%(height)s'  % locals()

And FWIW, you might want to define the template string outside the loop.

 rc = rc + fill=\%s\ stroke=\#00\ stroke-width=
 \1px\ fill-opacity=\.5\ /\n  % colors[colorIndex  % len(colors)]

idem

(snip)


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


Re: Declare a variable global

2007-02-19 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 On Feb 19, 11:09 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On 19 Feb 2007 09:04:19 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi,
 I have the following code:
 colorIndex = 0;
 def test():
 print colorIndex;
 This won't work.
 Are you sure?

 [EMAIL PROTECTED]:~$ cat foo.py
 colorIndex = 0

 def test():
 print colorIndex

 test()
 [EMAIL PROTECTED]:~$ python foo.py
 0
 [EMAIL PROTECTED]:~$

 The global keyword lets you rebind a variable from the module scope.  It
 doesn't have much to do with accessing the current value of a variable.

 Jean-Paul
 
 Thanks. Then I don't understand why I get this error in line 98:
 
  Traceback (most recent call last):
   File ./gensvg.py, line 109, in ?
 outdata, minX, minY, maxX, maxY = getText(data);
   File ./gensvg.py, line 98, in getText
 print colorIndex;
 UnboundLocalError: local variable 'colorIndex' referenced before
 assignment
 
 
 Here is my complete script:
[... script elided ...]

Well, now I've seen the error message I don't even need to see the 
script to explain what's going on. Unfortunately in your (entirely 
creditable) attempt to produce the shortest possible script that showed 
the error you presented a script that *didn't* have the error.

Python determines whether names inside a function body are local to the 
function or global to the module by analyzing the function source. If 
there are bindings (assignments) to the name inside the body then the 
name is assumed to be local to the function unless a global statement 
declares otherwise.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: How do I create an array of functions?

2007-02-19 Thread Steven D'Aprano
On Mon, 19 Feb 2007 05:17:03 -0800, Rob Wolfe wrote:

  # test.py
 
  def fun1(): return fun1
  def fun2(): return fun2
  def fun3(): return fun3
 
  # list of functions
  dsp = [f for fname, f in sorted(globals().items()) if callable(f)]

 Hmmm... when I try that, I get dozens of other functions, not just fun1,
 fun2 and fun3. And not just functions either; I also get classes.
 
 Oh, really? Where are these _other_ functions and classes
 in *MY* example?

I ran your example, word for word. Copied it and pasted it into my Python
session.


 
 Does Python have a function that will read my mind and only return the
 objects I'm thinking of?
 
 Your sarcasm is unnecessary.
 Using of `globals` function was easier to write this example. That's all.

Actually, it wasn't easier to write at all.

Your version:
dsp = [f for fname, f in sorted(globals().items()) if callable(f)]

Sensible version:
dsp = [fun1, fun2, fun3] 

Not only is your version brittle, but it is also about three times as
much typing.



-- 
Steven.

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


FPE: Add bindings to exception tracebacks.

2007-02-19 Thread Nathan
Hi folks!

Throughout my python development career, I've occasionally made
various developer tools to show more information about assertions or
exceptions with less hassle to the programmer.  Until now, these tools
didn't pass a utility vs pain-to-use threshold.

Now I've created a tool I believe to have passed that threshold, which
I call binding annotated exception tracebacks.  In short, this tool
adds text showing relevant local bindings to each level in a stack
trace print out.

I consider it to be so useful that it should be part of the standard
library.  I'm not sure the best process to propose this (shall I make
a PEP?  -is this already an FPE?), so I thought I'd start with a
published early/often patch, then point people to it.

I've submitted a patch against the 2.6 head on the sf tracker as
ticket 1654974, or try this url:

http://sourceforge.net/tracker/index.php?func=detailaid=1654974group_id=5470atid=305470

The patch modifies the traceback module.  It's also entirely
reasonable to have this functionality in a new, separate module (and
also it may be implemented in earlier python versions), but for my
personal build I wanted all programs to use this new feature.

Here's an example to clarify.  Consider the following script:

#! /usr/bin/env python2.6

import sys
import traceback

# Install annotated exception printing:
sys.excepthook = lambda t, v, b: traceback.print_exception(t, v, b,
annotate=True)

def f(c):
d = 2*c
return g(c)

def g(x):
return (lambda z: z+'foo')(x)

f(42)


-The output (with the patch of course) is:

Traceback (most recent call last):
  File /home/n/tmp/demo-bindann.py, line 16, in module
# With bindings:
# f = function f at 0x300f12f0
# Source:
f(42)
  File /home/n/tmp/demo-bindann.py, line 11, in f
# With bindings:
c = 42
# g = function g at 0x300f1330
# Source:
return g(c)
  File /home/n/tmp/demo-bindann.py, line 14, in g
# With bindings:
x = 42
# Source:
return (lambda z: z+'foo')(x)
  File /home/n/tmp/demo-bindann.py, line 14, in lambda
# With bindings:
z = 42
# Source:
return (lambda z: z+'foo')(x)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyDev on Mac

2007-02-19 Thread Mark
On Sun, 18 Feb 2007 10:50:37 +0100, Diez B. Roggisch wrote:
 Just wait until my crystal ball comes back from the cleaners, and I
 will start looking at your problem.

 As you can lay back and do nothing while that happens, I suggest you
 take this highly entertaining read:

Now that is an entertaining twist to the standard RTFM response!
Hadn't seen that one before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie help looping/reducing code

2007-02-19 Thread Lance Hoffmeyer
Hey all,


Can someone help me reduce this code?  It sure seems
like there ought to be a way to loop this or combine
things so that there is only 1 or 3 lines to this
instead of 6.  I've been scratching my head over this
for a while though I can't come up with anything.
Just as a note, I need even_odd_round left alone because
it is not always used.  I just included for clarity.

As always, thanks in advance,

Lance

T2B = even_odd_round(float(str(T2B)))   
VS  = even_odd_round(float(str(VS)))
SS  = even_odd_round(float(str(SS)))
sh.Cells(21,lastcol+1).Value = float(str(T2B))/100
sh.Cells(22,lastcol+1).Value = float(str(VS))/100
sh.Cells(23,lastcol+1).Value = float(str(SS))/100



def even_odd_round(num):
if(round(num,2) + .5 == int(round(num,2)) + 1):
if num  .5:
 if(int(num) % 2):
num = round(num,2) + .1 #an odd number
 else:
num = round(num,2) - .1 #an even number
else:
   num = 1
rounded_num = int(round(num,0))
return rounded_num
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help Required for Choosing Programming Language

2007-02-19 Thread Stef Mientki
 
 It's now the *3rd* time I mention Glade, wxGlade and QTDesigner in this 
 thread. Hendrik, I know *exactly* what Stef is talking about - been 
 here, done that.

Doubt, that know what I'm talking about ...
... Glade, wxGlade, QTDesigner are not my choice ;-)
... at the moment I tend towards VisualWX + openGL for the future.

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


Free Flash Games

2007-02-19 Thread Flash Games
Free Flash Games http://www.clipplay.com/ fun videos games and more.
Fun flash games. Free flash games...

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


Re: Newbie help looping/reducing code

2007-02-19 Thread Paul Rubin
Lance Hoffmeyer [EMAIL PROTECTED] writes:
 T2B = even_odd_round(float(str(T2B))) 
 VS  = even_odd_round(float(str(VS)))  
 SS  = even_odd_round(float(str(SS)))  
 sh.Cells(21,lastcol+1).Value = float(str(T2B))/100
 sh.Cells(22,lastcol+1).Value = float(str(VS))/100
 sh.Cells(23,lastcol+1).Value = float(str(SS))/100

First of all, I don't understand float(str(VS)) and so forth; if VS is
(say) an integer, you can say float(VS) directly.  Second, even_odd_round
is written in a way that it can accept either an int or a float.

So assuming you need to keep those variables around, I'd write the
first three lines of the above as:

   T2B = even_odd_round(T2B)
   VS = even_odd_round(VS)
   SS = even_odd_round(SS)

or you could get fancier and say

   T2B, VS, SS = map(even_odd_round, (T2B, VS, SS))

Then you could write the next three lines as a loop:

   for i,v in ((21, T2B), (22, VS), (23,SS)):
 sh.Cells(i, lastcol+1) = float(v) / 100.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Checking for EOF in stream

2007-02-19 Thread GiBo
Hi!

Classic situation - I have to process an input stream of unknown length
until a I reach its end (EOF, End Of File). How do I check for EOF? The
input stream can be anything from opened file through sys.stdin to a
network socket. And it's binary and potentially huge (gigabytes), thus
for line in stream.readlines() isn't really a way to go.

For now I have roughly:

stream = sys.stdin
while True:
data = stream.read(1024)
process_data(data)
if len(data)  1024:## (*)
break

I smell a fragile point at (*) because as far as I know e.g. network
sockets streams may return less data than requested even when the socket
is still open.

I'd better like something like:

while not stream.eof():
...

but there is not eof() method :-(

This is probably a trivial problem but I haven't found a decent solution.

Any hints?

Thanks!

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


Re: cmd all commands method?

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 00:08:45 -0300, placid [EMAIL PROTECTED] escribió:

 If anyone can provide a suggestion to replicate the following Tcl
 command in Python, i would greatly appreciate it.

 namespace eval foo {
 variable bar 12345
 }

 what this does is create a namespace foo with the variable bar set to
 12345.

Python namespaces are simple dictionaries. See the eval function.

py s = 3+x**2
py freevars = {x: 2}
py eval(s, {}, freevars)
7

-- 
Gabriel Genellina

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


Re: Pep 3105: the end of print?

2007-02-19 Thread Peter mayne
Steven D'Aprano wrote:
 If Python 3 dropped the print
 statement and replaced it with official_print_function(), how would that
 help you in your goal to have a single code base that will run on both
 Python 2.3 and Python 3, while still using print?

Is there any reason why official_print_function isn't sys.stdout.write?

I can't remember the last time I used print in actual code (apart from 
short-lived debugging lines), so I'm bewildered as to why print seems to 
be so important.

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


Re: Building Python Pagage for Newer Python Version

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 11:00:18 -0300, Diez B. Roggisch [EMAIL PROTECTED]  
escribió:

 I have just downloaded the source for PyXML-0.8.4, which I would like
 to build for Python 2.5. How exactly do I go about doing this?

 python2.5 setup.py install usually does the trick.

Beware of this message, from the project front page: PyXML is no longer  
maintained

-- 
Gabriel Genellina

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


Re: writing a file:newbie question

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 08:02:29 -0300, kavitha thankaian  
[EMAIL PROTECTED] escribió:

 Hi,
  i have a file test.txt and it contains a list of strings say,,,
  a,b,c,d,a1,b1,c1,d1,a2,b2,c2,d2,
  i would like to write the file as
  a,b,c,d
   a1,b1,c1,d1
   a2,b2,c2,d2
  and would like to delete the comma at the end.

Not enough info...
Does the input file contain only one line, or many lines?
Always exactly 12 items? Including a trailing , ?

The following may work for 12 items. Use the csv module to read the file:

import csv
reader = csv.reader(open(test.txt, r))
writer = csv.writer(open(output.txt, w))
for row in reader:
 writer.writerow(row[:4])
 writer.writerow(row[4:8])
 writer.writerow(row[8:])

-- 
Gabriel Genellina

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


Re: Checking for EOF in stream

2007-02-19 Thread Grant Edwards
On 2007-02-19, GiBo [EMAIL PROTECTED] wrote:
 Hi!

 Classic situation - I have to process an input stream of unknown length
 until a I reach its end (EOF, End Of File). How do I check for EOF? The
 input stream can be anything from opened file through sys.stdin to a
 network socket. And it's binary and potentially huge (gigabytes), thus
 for line in stream.readlines() isn't really a way to go.

 For now I have roughly:

 stream = sys.stdin
 while True:
   data = stream.read(1024)
if len(data) == 0:
 break  #EOF
   process_data(data)

-- 
Grant Edwards   grante Yow!  CALIFORNIA is where
  at   people from IOWA or NEW
   visi.comYORK go to subscribe to
   CABLE TELEVISION!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: search cursor in pythonwin 2.1

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 12:21:27 -0300, GISDude [EMAIL PROTECTED]  
escribió:

 Thanks for the reply. After looking at the docs again, you are correct
 NAMES IS NOT NULL would be the correct syntax.

 I thought it was NAMES  NULL

Python has some gotchas like default mutable arguments, that will catch  
the novice. SQL has its NULL behavior on expressions...

-- 
Gabriel Genellina

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


Re: Newbie help looping/reducing code

2007-02-19 Thread Paul Rubin
Lance Hoffmeyer [EMAIL PROTECTED] writes:
 def even_odd_round(num):
   if(round(num,2) + .5 == int(round(num,2)) + 1):
   if num  .5:
if(int(num) % 2):
   num = round(num,2) + .1 #an odd number
else:
   num = round(num,2) - .1 #an even number
   else:
  num = 1
   rounded_num = int(round(num,0))
   return rounded_num

I would also rewrite this function.  It's quite hard to figure out
what it's intended to do.  At minimum it should be carefully
documented.  I have the impression it's supposed to be something like
the IEEE rounding mode, that rounds floating point numbers to the
nearest integer, rounding to the even neighbor if the fractional
part (sometimes called the mantissa) is close to 0.5.

   if(round(num,2) + .5 == int(round(num,2)) + 1):

The above is true if the mantissa is = 0.495.  So you're going to
round 3.495 up to 4, even though it's actually closer to 3.  Is that
really what you want?  You're rounding based on a printed
representation rather than on the actual number.

   if num  .5:

It looks like for display purposes you're trying to avoid displaying
positive numbers as zero if they're slightly below 0.5.  However, that
doesn't prevent the round-to-even behavior if the number is slightly
above 0.5.  So you get the anomaly that even_odd_round(0.499) = 1,
but even_odd_round(0.501) = 0.  My guess is that's not what you wanted
and that it's a bug.

if(int(num) % 2):
   num = round(num,2) + .1 #an odd number
else:
   num = round(num,2) - .1 #an even number

If the integer part is odd, round upward, else round downward, ok.
So basically you're going to round to the even neighbor if the
mantissa is close to 0.5, otherwise round to the nearest integer.

I notice also that when num is negative, your function rounds to
the odd neighbor (at least sometimes), differing from IEEE rounding.

I think it's clearer to just separate out the integer and fractional
parts and branch on the fractional part directly.  I'll ignore the
issue with negative inputs since I'm guessing you only care about
positive ones:

def even_odd_round(num):
   assert num = 0

   # separate the number's integer and fractional parts
   intpart, fracpart = int(num), num % 1.0

   # decide what to do based on the fractional part
   if fracpart  0.495:
  return intpart# round downward
   elif fracpart  0.505 or intpart==0:
  return intpart+1  # round upward
   else:
  return intpart + intpart % 2  # round to even
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >