Re: Python script + v4lctl

2008-10-20 Thread Gabriel Genellina

En Mon, 20 Oct 2008 06:15:34 -0200, Gatis <[EMAIL PROTECTED]> escribió:


I wrote script that in case of some event takes picture using usb
webcam [Creative Live! Cam Vista IM (VF0420)] and command line utility
v4lctl (from package xawtv).
Problem1:
To catch error and info messages from script I used:
sys.stdout = open('/tmp/log','a')
sys.stderr=sys.stdout
All writes to log file well, except v4lctl error messages. If script
is run from commandline, than v4lctl error messages are shown there.
How to catch these messages?


Use the subprocess module to invoke the external program; see  
http://docs.python.org/library/subprocess.html specially the examples at  
the end.



Problem2:
When script is run from /etc/init.d (in runlevel 2) during boot, no
pictures are taken. I can't tell error message, because of Problem1.
If I execute now v4lctl from commandline (while my script is running
in background), picture is taken.


Once you start using subprocess, you could write to some file what you get  
from the communicate() method - the error messages, if any, should be  
there.


--
Gabriel Genellina

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


RE: I want to release the GIL

2008-10-20 Thread Delaney, Timothy (Tim)
Piotr Sobolewski wrote:

> Hello,
> I have such program:
> 
> import time
> import thread
> def f():
>     global lock
>     while True:
>         lock.acquire()
>         print thread.get_ident()
>         time.sleep(1)
>         lock.release()
> lock=thread.allocate_lock()
> thread.start_new_thread(f,())
> thread.start_new_thread(f,())
> time.sleep(60)

1. You should use the threading module.

2. No need for the "global lock" statement here - you're not rebinding the name 
"lock".

3. These aren't daemon threads, so your program will never exit. You will need 
to set a flag or something after the time.sleep(60).

> As you can see, I start two threads. Each one works in an infinite
> loop.
> Inside that loop it acquires lock, prints its own id, sleeps a bit and
> then
> releases lock.

4. Because you are holding the lock while sleeping, the other thread does not 
get the chance to run. Sleeping does not release any locks held.

Instead try something like:

while True:
with lock:
print thread.get_ident()
time.sleep(1)

Note that to use the "with lock:" idiom, you need to be using Python 2.6, or 
Python 2.5 with a "from __future__ import with_statement".

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


Re: I want to release the GIL

2008-10-20 Thread Chris Rebert
On Mon, Oct 20, 2008 at 10:12 PM, Piotr Sobolewski
<[EMAIL PROTECTED]> wrote:
> Hello,
> I have such program:
>
> import time
> import thread
> def f():
> global lock
> while True:
> lock.acquire()
> print thread.get_ident()
> time.sleep(1)
> lock.release()
> lock=thread.allocate_lock()
> thread.start_new_thread(f,())
> thread.start_new_thread(f,())
> time.sleep(60)
>
> As you can see, I start two threads. Each one works in an infinite
> loop.
> Inside that loop it acquires lock, prints its own id, sleeps a bit and
> then
> releases lock.
>
> When I run it, I notice that only one thread works and the other one
> never
> has a chance to run. I guess it is because the thread don't have a
> chance
> to release the GIL - after it releases the lock, it almost immediately
> (in
> the very next bytecode command) reacquires it. I know I can
> put "time.sleep(0.01)" command after between release and reacquire,
> but it
> doesn't seem elegant - why should I make my program sleep instead of
> work?

You let *one thread* sleep so that the *other thread* can wake, grab
the lock, and *work*.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

>
> Is there any simple way to release the GIL? Like:
> lock.release()
> thread.release_gil()
> ?
>
> Thanks in advance!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating single .exe file without py2exe and pyinstaller

2008-10-20 Thread oyster
you can try jungle ( http://www.suda-chen.biz/?page_id=21 ) also

> -- 已转发邮件 --
> From: MRAB <[EMAIL PROTECTED]>
> To: python-list@python.org
> Date: Mon, 20 Oct 2008 15:47:55 -0700 (PDT)
> Subject: Re: Creating single .exe file without py2exe and pyinstaller
> On Oct 20, 4:48 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> > Tino Wildenhain wrote:
> > > Abah Joseph wrote:
> > > 2) use a python to C(++) compiler and compile the result to .exe,
> > >works pretty well for simple applications:
> > >http://shed-skin.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute a makefile from LINUX system.

2008-10-20 Thread Ben Finney
gaurav kashyap <[EMAIL PROTECTED]> writes:

> How to run the makefile using some python function.

A makefile is not a program to be run; it contains a declarative
(*not* procedural) data set for the ‘make’ program. You need to invoke
the ‘make’ command, tell it which file to read, and specify which
target you want it to achieve.

An example:

$ make -f /tmp/foo/makefile spam

where ‘/tmp/foo/makefile’ is the path to the file containing the data
set, and ‘spam’ is the target you want ‘make’ to achieve.

How do you know which target you want? You'll need that information
from the author of the makefile, such as in the documentation that
comes with the makefile.

-- 
 \ “I put contact lenses in my dog's eyes. They had little |
  `\   pictures of cats on them. Then I took one out and he ran around |
_o__)  in circles.” —Steven Wright |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute a makefile from LINUX system.

2008-10-20 Thread gaurav kashyap
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute a makefile from LINUX system.

2008-10-20 Thread Chris Rebert
On Mon, Oct 20, 2008 at 10:32 PM, gaurav kashyap
<[EMAIL PROTECTED]> wrote:
> Hi all,
> I am using Link-41b parser in my program.
> The windows version of it has an .exe file that can be executed using
> os.system command
> On Linux version,I have a makefile.
>
> so my question is:
> How to run the makefile using some python function.

Use the 'subprocess' module
(http://docs.python.org/library/subprocess.html#module-subprocess) to
run the 'make' command in the same working directory as the Makefile
with the appropriate target as an option.

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com

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


Re: How to get all variables of some module in that module

2008-10-20 Thread Steven D'Aprano
On Tue, 21 Oct 2008 11:56:30 +0700, Alex Gusarov wrote:

> Here I want to get all Table instances of current module and put them
> into dictionary by names, but I don't know how I can get all variables
> of current module in the end of this module. Please, give me a hint.

>>> import math
>>> dir(math)
['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 
'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 
'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']


Note that dir() gives you a list of "interesting" names. You can also use 
math.__dict__.keys() or the inspect module.

Once you have a key, you can get the actual object you want with getattr:

>>> key = 'acos'
>>> getattr(math, key)






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


Re: Abnormal Interpreter Shutdown

2008-10-20 Thread k3xji
> If you mean detecting abnormal shutdown after the fact, as opposed to
> catching it while happening, you could create an empty temp file when
> the program starts and delete it upon normal termination.

I have a server application, and I want to take some actions *before*
the shutdown. I assumed to have some kind of event or Exception being
raised when Interpreter is closed abnormally.

I will take a look at the links.

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


Re: How to transfer data structure or class from Python to C/C++?

2008-10-20 Thread Gabriel Genellina
En Fri, 17 Oct 2008 20:03:44 -0300, Aaron "Castironpi" Brady  
<[EMAIL PROTECTED]> escribió:



On Oct 16, 9:10 am, Hongtian <[EMAIL PROTECTED]> wrote:

Not exactly.

In my C/C++ application, I have following function or flow:

void func1()
{
    call PyFunc(struct Tdemo, struct &Tdemo1);

}

I mean I want to invoke Python function 'PyFunc' and transfer a data
structure 'Tdemo' to this function. After some process in Python, I
want it return 'Tdemo1' back to the C/C++ application.

I research boost.python and think it is not a reasonable solution
because it make the C/C++ application too complex.

Thanks.

snip

Solution produced here.  Includes dirty kludge, which will welcome
correction.

/C file:

#include 

typedef struct {
int a;
float b;
} TypeA;

static PyObject *
methA(PyObject *self, PyObject *args) {
TypeA a;
TypeA b;
PyObject* fun;
PyObject* res;

PyArg_ParseTuple( args, "O", &fun );
a.a= 10;
a.b= 20.5;

res= PyObject_CallFunction( fun, "II", &a, &b );

printf( "%i %f\n", b.a, b.b );
Py_DECREF( res );

return PyInt_FromLong( 0 );
}

static PyMethodDef module_methods[] = {
{"methA", methA, METH_VARARGS, "No doc"},
{NULL, NULL, 0, NULL}  /* Sentinel */
};


#ifndef PyMODINIT_FUNC  /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
initng27ext(void)
{
PyObject* m;
m = Py_InitModule3("ng27ext", module_methods,
   "Custom.");
if (m == NULL)
  return;
}

/Py file:

import ng27ext

import ctypes as c
class TypeA( c.Structure ):
_fields_= [
( 'a', c.c_int ),
( 'b', c.c_float )
]

from _ctypes import _cast_addr
_data_cast= c.PYFUNCTYPE( c.py_object, c.c_void_p, c.py_object,
c.py_object)( _cast_addr ) #dirty kludge

def exposed( obj1, obj2 ):
cob1= _data_cast( obj1, None, c.POINTER( TypeA ) )
cob2= _data_cast( obj2, None, c.POINTER( TypeA ) )
print cob1.contents.a, cob1.contents.b
cob2.contents.a= c.c_int( 60 )
cob2.contents.b= c.c_float( 70.5 )
print cob2.contents.a, cob2.contents.b

print ng27ext.methA( exposed )

/Compile & link:

c:/programs/mingw/bin/gcc ng27ext.c -c -Ic:/programs/python25/include
c:/programs/mingw/bin/gcc -shared ng27ext.o -o ng27ext.pyd -Lc:/
programs/python25/libs -lpython25

/Output:

10 20.5
60 70.5
60 70.50
0
Press any key to continue . . .

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





--
Gabriel Genellina

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


Re: indentation

2008-10-20 Thread Terry Reedy

Steven D'Aprano wrote:

On Mon, 20 Oct 2008 14:25:17 -0400, Terry Reedy wrote:


If I type *hypothetical* code for a post, *I* have to
type all the spaces, and I often use 2 per indent level.  If I type in
IDLE, *it* adds the spaces (4 per indent) automatically.


But of course you would never post code without testing it first, right? 
That would an Abomination Unto Nuggan.


*wink*


I have learned at least three times to either test or specify 
*untested*, except when testing is impossible, as when discussing 
unimplemented syntax or answering questions based on unposted input.  I 
have learned much from posting *tested* code snippets.


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


How to execute a makefile from LINUX system.

2008-10-20 Thread gaurav kashyap
Hi all,
I am using Link-41b parser in my program.
The windows version of it has an .exe file that can be executed using
os.system command
On Linux version,I have a makefile.

so my question is:
How to run the makefile using some python function.

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


Re: Abnormal Interpreter Shutdown

2008-10-20 Thread Terry Reedy

Tim Golden wrote:

k3xji wrote:

Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?


"Task Manager" suggests you're using Windows, on which basis
you've got a few options open to you, but fundamentally if
someone pulls the plug on the PC you're not going to spot it.

Look at the SetConsoleCtrlHandler API[1], which is available
in the pywin32 package, and the WMI power events[2]. I don't
know exactly how far each one will go if someone stomps on
your process, but they're definitely worth looking at.

TJG

[1] http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/aa394362(VS.85).aspx


If you mean detecting abnormal shutdown after the fact, as opposed to 
catching it while happening, you could create an empty temp file when 
the program starts and delete it upon normal termination.


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


Re: hiding modules in __init__.py

2008-10-20 Thread Gabriel Genellina
En Sat, 18 Oct 2008 16:03:19 -0300, Brendan Miller <[EMAIL PROTECTED]>  
escribió:



How would I implement something equivalent to java's package private in
python?

Say if I have

package/__init__.py
package/utility_module.py

and utility_module.py is an implementation detail subject to change.

Is there some way to use __init__.py to hide modules that I don't want
clients to see? Or is the best practice just to name the module you don't
want clients to use _utility_module and have it private by convention?


If you don't import utility_module in __init__ (or delete the name after  
using it), it won't show up if someone does "from package import *", nor  
in dir(package). Plus if you don't menction it in the docs, the only way  
to discover it would be to look at the directory contents - to "peek the  
implementation", I'd say.
You could always name it _utility_module.py if you want to make perfectly  
clear that it's for internal use only, but I've seldom seen such module  
names.


--
Gabriel Genellina

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


I want to release the GIL

2008-10-20 Thread Piotr Sobolewski
Hello,
I have such program:

import time
import thread
def f():
    global lock
    while True:
        lock.acquire()
        print thread.get_ident()
        time.sleep(1)
        lock.release()
lock=thread.allocate_lock()
thread.start_new_thread(f,())
thread.start_new_thread(f,())
time.sleep(60)

As you can see, I start two threads. Each one works in an infinite
loop.
Inside that loop it acquires lock, prints its own id, sleeps a bit and
then
releases lock.

When I run it, I notice that only one thread works and the other one
never
has a chance to run. I guess it is because the thread don't have a
chance
to release the GIL - after it releases the lock, it almost immediately
(in
the very next bytecode command) reacquires it. I know I can
put "time.sleep(0.01)" command after between release and reacquire,
but it
doesn't seem elegant - why should I make my program sleep instead of
work?

Is there any simple way to release the GIL? Like:
lock.release()
thread.release_gil()
?

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


How to get all variables of some module in that module

2008-10-20 Thread Alex Gusarov
Hello, I have a following module and in its end I want to initalize
collection of tables:

Module:

from sqlalchemy import *

metadata = MetaData()

calendars_table = Table('calendars', metadata,
Column('id', Integer, primary_key=True),
Column('title', Unicode(50)),
Column('color', Unicode(6)),
)

events_table = Table('events', metadata,
Column('id', Integer, primary_key=True),
Column('calendar', Integer, ForeignKey('calendars.id')),
Column('date', Date),
Column('title', Unicode(50)),
Column('description', Unicode(1000)),
Column('color', Unicode(6)),
)

tables_collection = {}

Here I want to get all Table instances of current module and put them
into dictionary by names, but I don't know how I can get all variables
of current module in the end of this module. Please, give me a hint.

--
Best regards, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python equivalent for C module

2008-10-20 Thread Derek Martin
On Mon, Oct 20, 2008 at 10:28:15AM -0700, Gary Herron wrote:
> > The other weird behavior was, once I changed the value of DEBUG,
> > dprint() started to behave oddly.  No matter what I passed as an
> > argument (and no matter what I set the value of DEBUG to be), it
> > started printing the exact literal string:
> >
> > DEBUG: %s
[...]
> I don't believe it -- send your *actual* code, and we'll all have a look.

When I finally had access to my code again, my error was immediately
obvious.  I'd typed: 

  print("DEBUG: %s")

Weird thing was, I remembered it actually working.  And it had... In
between testing the two cases, I'd accidentally deleted the module and
had to recreate it.  The first time no bug, second time, well,
resutled in this thread.  I'm chalking the whole thing up to coding
when not sufficiently awake to do so. ;-)

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpPHO8fo3dXL.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: What was that, what was it?

2008-10-20 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>, Aaron
Brady wrote:

> If Python was a car, I think it would be a hybrid...

I hope not. They're only good in the city, a waste of time once you get over
50 km/h.

> Plus there's nothing about sarcasm in the Zen.

That's why it's the Zen. :)

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


Re: indentation

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> Here's Jamie Zawinski:
> http://www.jwz.org/doc/tabs-vs-spaces.html
> 
> "On defaultly-configured Unix systems, and on ancient dumb terminals and
> teletypes, the tradition has been for the TAB character to mean ``move to
> the right until the current column is a multiple of 8.''

Actually, I think that should be "multiple of 8 plus 1". If you're in column
1, pressing tab will move the equivalent of 8 spaces, which takes you
column 9, not 8.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python equivalent for C module

2008-10-20 Thread Derek Martin
On Mon, Oct 20, 2008 at 10:43:55PM +, Steven D'Aprano wrote:
> All of this is just splitting hairs, 

Indeed... :)

> because you don't really mean Python is making a copy of the name
> 'DEBUG', but of the *data* that DEBUG refers to, namely the object
> True. 

Well, as long as we're having semantic discussions...  If you reread
my post, it should be clear that what you wrote above can not possibly
be the case.  If you recall, my intent was to make a copy of a means
of accessing the value known by the name "DEBUG" contained in the
debug module, which could be accessed from any module in the program.
Clearly the data itself *must not* be a copy, or else what I was
trying to do would never have worked.  What I was refering to as a
copy was in fact essentially the name, or more accurately (as regards
my conception of purpose) a reference to the data.

> > The *object* very much is: it is immutable.
> 
> So what? The *name* DEBUG is not read-only.

You may have missed where I explained that the name refers to two
different things, and that I, speaking in loose terms, was refering to
both things simultaneously but in different contexts.  I was speaking
loosely -- I was using "read-only" as a figure of speech of sorts, and
elaborated *correctly* what actually happens.   Again, if you reread
my original post with that explanation in mind, I think you'll find
that this is the only sensible interpretation for what I wrote.

> Actually it is a very common convention in Python circles. I often use it 
> myself. However it's not the only one, and from time to time I use 
> others. I would consider using DEBUG unusual, but not excessively so.

To be honest, same here.  My post contained throw-away C code that I
typed up on the fly, and the same goes for the Python -- I simply
translated the C code literally, so to speak.  As has been pointed out
in a different thread (by Bruno himself, if I'm not mistaken), the
code hastily posted here need not represent the code that one would
write in "real" programs.  But I find it offensive that certain people
here can't resist lambasting some posters who have simple questions,
because the code they posted isn't up to their particular favorite
coding "standards" (i.e. conventions), and I will speak out about it,
especially when it's done to me.  I didn't ask about coding
conventions, but Bruno's response was roughly 75% about how my code
sucks, and maybe 25% about answering my question.  And what part did
answer my question was completely redundant.  It was roughly 95% a
waste of time and energy for both him and me, though I did learn about
the logging module...
 
> Deary deary me... you come along here, asking noob Python questions, and 
> then get shirty when people give you friendly and perfectly good answers. 

Well, we disagree that the answer Bruno provided was either friendly
or perfectly good.  I did receive perfectly good answers, and if you
read the whole thread, you saw me accept such answers graciously.
Bruno's answer smacked of a superiority and arrogance that is not
uncommon among certain frequent posters.  He has no idea what my
program does, or what my real code looks like, but apparently deigns
himself the Code Police, and finds it necessary to punnish people for
posting code which does not conform to his idea of Programming Law.  

I can't deny that I should have been able to answer my own question
with only a few more moments thought...  Though I don't think it's
quite right to characterize questions about scope as "noob" questions.
I suspect actual noobs don't yet know enough to ask such questions.

> Are you trying to ensure that the next question you ask remains 
> unanswered?

Not at all, just trying to preempt the pound of attitude that often
goes with the ounce of answers.  But if the choice is between no
answer, and an answer that barely manages to avoid calling me an idiot
(especially over coding style), I'd rather have no answer.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgp1spA6WQhn4.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is the logical processing being done for strings like 'Dog' and 'Cat'

2008-10-20 Thread Tim Roberts
Sumitava Mukherjee <[EMAIL PROTECTED]> wrote:

>Hi all,
>I am a novice programmer in Python.
>Please could you explain me the results (regarding logical operators).
>
>I get this:
>
 print bool('God' and 'Devil')
>True
>
>[This is ok because (any) string is True, so; (True and True) gives
>True]

Your statement is accurate, but that's not why it returns true.

 print('God' and 'Devil')
>Devil

Right.  And bool('Devil') is True, because a non-empty string is a true
value.

>[This is what I don't get ]
>and for that matter,I also checked out this:
>
 01 and 10
>10
>
>What is python doing when we type in ('God' and 'Devil') or key in (01
>and 10) ?

"and" and "or" are a bit more than logical operators.  The exact definition
of "x and y" is "if x has a false value, return x, otherwise return y".  If
both sides are booleans, this does exactly what you expect.

Similarly, "x or y" is actually done as "if x has a true value, return x,
otherwise return y".

This allows for one of the cuter Python hacks:
xxx = x and y or z
which is essentially the same as the C ternary operator:
xxx = x ? y : z;
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is the logical processing being done for strings like 'Dog' and 'Cat'

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 18:41:23 -0700, Sumitava Mukherjee wrote:

> What is python doing when we type in ('God' and 'Devil') or key in (01
> and 10) ?


There are two important things you need to know:

(1) All Python objects have a boolean context.

(2) Python's boolean operators are short-circuit operators.


Point (1) means that you can say this:


if x:
   print 'x has a true value'
else:
   print 'x has a false value'

and it will work for any x, not just True and False.

As a general rule, false values are empty:

- the empty string is false: ''
- empty lists are false: []
- empty tuples are false: ()
- zeroes are false: 0, 0.0
- None is false
- etc.

and everything else is true.

So you can do this:

if alist:
# alist is not empty
x = alist[0]  # so this is safe
else:
print 'alist is empty'


config = get_config_parser()  # whatever that is...
if config:
   do_stuff_with_config
else:
   print "config is empty"




Point (2) means that Python will only evaluate the least number of 
objects needed. So for example:

42 or 19

Since 42 is a true object, looking at the second item is pointless, and 
Python short-circuits by returning 42.

0 or 19

Since 0 is a false object, Python must look at the second item. Since 19 
is true, it returns 19.

And similarly for and.


This is especially useful with the or operator. Instead of this:

astring = something()
if len(astring) == 0:
astring = ''
do_something_with(astring)


you can do this:

astring = something() or ''
do_something_with(astring)



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


Re: dumping in destructor

2008-10-20 Thread Gabriel Genellina

En Mon, 20 Oct 2008 10:01:07 -0200, Митя <[EMAIL PROTECTED]> escribió:


Thank you for your answers!

my g_register is a global object, and it lives all the program's
lifetime, so 'with' is not appliable. Am I right?


Why not? You could use a with statement (or try/finally) around your main  
entry point.



I tried to use atexit and wrote following:

class _Register(object):
   def dump(self):
 

class Registerable(object):
   

g_register = _Register()
atexit.register(g_register.dump)
...
...
g_register.add(Registerable('aa'))

But now I get:

cPickle.PicklingError: Can't pickle :
attribute lookup __main__.Registerable failed

Does that mean that by the time of atexit execution my Registerable
class is already dead?


No, at least not due to using atexit. When atexit functions are executed,  
the interpreter is still in a fully working state. From pythonrun.c,  
function Py_Finalize:


/* The interpreter is still entirely intact at this point, and the
 * exit funcs may be relying on that.  In particular, if some thread
 * or exit func is still waiting to do an import, the import machinery
 * expects Py_IsInitialized() to return true.  So don't say the
 * interpreter is uninitialized until after the exit funcs have run.
 * Note that Threading.py uses an exit func to do a join on all the
 * threads created thru it, so this also protects pending imports in
 * the threads created via Threading.
 */

Probably you have another problem in your code; try to use pickle alone  
(not within atexit) and see what happens.


--
Gabriel Genellina

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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Steven D'Aprano
On Tue, 21 Oct 2008 11:22:56 +0800, Peter Wang wrote:

> Nathan Seese <[EMAIL PROTECTED]> writes:
> 
>>> #! /bin/sh
>>> python -c "import sys;exec(sys.stdin)"
>>
>> I know this isn't your question, but I think you could write that more
>> cleanly with:
>>
>> #!/usr/bin/python
>> import sys
>> exec(sys.stdin)
>
> thanks.
> What's the difference between this and mine?

Yours launches an new shell, which then calls python, which then executes 
whatever it finds in stdin as Python code.

The second one just launches Python directly.



> I think what i need actually is a python function like
> `file_get_contents' in php:)


I think that would be:

contents = open(filename).read()




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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Peter Wang
Nathan Seese <[EMAIL PROTECTED]> writes:

>> #! /bin/sh
>> python -c "import sys;exec(sys.stdin)"
>
> I know this isn't your question, but I think you could write that more 
> cleanly with:
>
> #!/usr/bin/python
> import sys
> exec(sys.stdin)
thanks.
What's the difference between this and mine? 

I think what i need actually is a python function like
`file_get_contents' in php:)
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Python Imaging Library (PIL) question

2008-10-20 Thread Darcy Mason
On Oct 20, 2:14 pm, Sid <[EMAIL PROTECTED]> wrote:
> Hi,
>
>   I am tryin to copy an image into my own data structure(a sort of 2d array  
> for further FFT). I've banged my head over the code for a couple of hours  
> now. The simplified version of  my problem is below.
>
> #-Code
>
> import Image
> pic = Image.open("Images/a.jpg")
> (picdata,width,height)  = (pic.load(),pic.size[0],pic.size[1])
>
> picMap = [[0] * width ] * height        #matrix needed for FFT
>
> print "--Printing PIC MAP--"
> for h in range(0,height):
>      for w in range(0,width):
>          print picMap[h][w]," ", #everything initialized to ZERO...this is  
> ok
>      print "\n"
>
> print "--Copying to  PIC MAP--"
> for h in range(0, height):
>      for w in range(0, width):
>          picMap[h][w] = picdata[w,h] #problem lies here
>          print picMap[h][w]," ",  #Seems to copy perfectly here as the  
> output shows
>      print "\n"
>
> print "--Printing PIC MAP AGAIN--"
> for h in range(0,height):
>      for w in range(0,width):
>          print picMap[h][w]," ",  #Should print the values as above, but  
> doesn't
>      print "\n"
>
> #-Code End
>
> Hopefully someone would take a look and let me know what i'm doing  
> something wrong here.
>
> Thanks a lot
> -Sid

The problem is likely to do with the line
picMap = [[0] * width ] * height

The first [0]*width creates a list, then the *height repeats the
reference to the same list. See, for example
http://mail.python.org/pipermail/tutor/2001-December/010414.html. It
prints okay in the middle section because the items have just been
stored. Later iterations in that same loop are replacing array
elements that have already been printed. The link explains the problem
and shows a way to avoid this. You might also consider using Numpy, it
has explicit functions to zero any dimension array.

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


Compare Files and Cat File Difference Question

2008-10-20 Thread zw
Hi

I have 2 log files, each with a timestamp on the first 2 fields.
However, when I do a
awk '/ / {print $1,$2}' logs/x.log
on a log file,

it is complicated by the fact that I also get other non timestamp
column,
2008-10-20 15:00:06,113
2008-10-20 15:00:06,113
2008-10-20 14:59:48,828
javax.naming.CommunicationException: Could
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectStub(MultiJndiLookup.java:
377)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectRef(MultiJndiLookup.java:
130)
at
com.cm.common.util.jndi.JndiLookup.getRemoteObjectRef(JndiLookup.java:
88)
at
com.cm.system.SystemInfoTopicManager.init(SystemInfoTopicManager.java:
91)
at
com.cm.system.SystemInfoTopicManager.reconnect(SystemInfoTopicManager.java:
181)
at
com.m.system.SystemInfoTopicManager.onException(SystemInfoTopicManager.java:
216)
at org.jboss.mq.Connection
$ExceptionListenerRunnable.run(Connection.java:1348)
at java.lang.Thread.run(Thread.java:595)
Caused by:
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385)
... 11
2008-10-20 14:59:49,800

Unix diff gives extra output like
1,38c1,2
< 2008-10-20 15:00:09,890 WARN [EMAIL PROTECTED]:***:***:***]
[ExceptionListener Connection@
323[token=ConnectionToken:ID:93/1003454235 rcvstate=STARTED]]
com.cm.system.SystemInfoTopicManager - Jms server not reachable..it
may be down. Deatils:Could not obtain
connection to any of these urls:
172.16.70.1:1100,172.16.70.2:1100,172.16.70.3:1100,172.16.70.4:1
100,172.16.70.5:1100

I like to generate a 3rd file after comparing 2 files with format like
the other 2 files but containing only the difference between 1st and
2nd files.
ie

suppose the file contains
file1 file2
2008-10-20 15:00:06,113 ... 2008-10-20
15:00:06,113 ...
2008-10-20 15:00:06,113 ... 2008-10-20
15:00:06,113
2008-10-20 14:59:48,828 ...
2008-10-20 14:58:48,900 ...
javax.naming.CommunicationException...
at org.jnp.interfaces.NamingContext.ch...

I'm hoping to get in file3
2008-10-20 14:59:48,828 ...plus rest of line
2008-10-20 14:58:48,900 ...plus rest of line

I suppose I also need to read in the 1 field of the timestamp and
convert time to unix time to compare and then convert that unix time
to this timestamp format.

It looks like filecmp.cmp isn't enough to cope with my requirements
cuz it only gives a boolean value of 0 or 1,
not the actual print out of the differences between 2 files into a new
file.
Can this be done with Python quickly ?
Could someone be kind enough to show me steps to accomplish this ?


Any help is appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating single .exe file without py2exe and pyinstaller

2008-10-20 Thread Gabriel Genellina
En Sun, 19 Oct 2008 01:45:16 -0200, Abah Joseph <[EMAIL PROTECTED]>  
escribió:


I have written a small application of about 40-45 lines which is about  
4KB,

so I want to create a single .exe file from it, using py2exe it created
unnecessary files, that just increase the size of the program and also  
less

portable to me. What else can I use?
I am on windows XP.
Python 2.5


You may explore using the "excludes" and "dll_excludes" options if you are  
absolutely sure certain modules would never be used. Also you might use  
the "ascii" option if you never use any kind of encoding.


--
Gabriel Genellina

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


Re: How is the logical processing being done for strings like 'Dog' and 'Cat'

2008-10-20 Thread zaarg
On Oct 20, 9:41 pm, Sumitava Mukherjee <[EMAIL PROTECTED]> wrote:
> Hi all,
> I am a novice programmer in Python.
> Please could you explain me the results (regarding logical operators).
>
> I get this:
>
> >>> print bool('God' and 'Devil')
>
> True
>
> [This is ok because (any) string is True,
Not quite so.  Be careful with this.  The empty string gets False:
print bool("") --> False
Any *non-empty* string gets True.

> so; (True and True) gives
> True]
>
> >>> print('God' and 'Devil')
>
> Devil
>
> [This is what I don't get ]
> and for that matter,I also checked out this:
>
> >>> 01 and 10
>
> 10
Note that AND is a boolean operator, not a bit operator.  If you want
to hack bits of an integer, use the "binary bitwise operators"
   http://docs.python.org/reference/expressions.html#binary-bitwise-operations
e.g.
>>> 01 & 10
0
>>> 01 | 10
11

>
> What is python doing when we type in ('God' and 'Devil') or key in (01
> and 10) ?

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


Re: Py++ - 1.0

2008-10-20 Thread alex23
"Roman Yakovenko" <[EMAIL PROTECTED]> wrote:
> * Algorightm, which defines what virtual functions should be redefined
> was improved.

Always a handy feature, much better than using an algowrongm ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: search for a python compiler program whose name is jingle

2008-10-20 Thread alex23
On Oct 20, 3:46 pm, oyster <[EMAIL PROTECTED]> wrote:
> I don't remember its name very clear, it may be 'jingle' or not
> this program runs on windows and can compile a python program into exe
> file without gcc

I haven't heard of 'jingle' but there are a number of tools for
achieving this:

http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm
--
http://mail.python.org/mailman/listinfo/python-list


Re: How is the logical processing being done for strings like 'Dog' and 'Cat'

2008-10-20 Thread Benjamin
On Oct 20, 8:41 pm, Sumitava Mukherjee <[EMAIL PROTECTED]> wrote:
> Hi all,
> I am a novice programmer in Python.
> Please could you explain me the results (regarding logical operators).
>
> I get this:
>
> >>> print bool('God' and 'Devil')
>
> True
>
> [This is ok because (any) string is True, so; (True and True) gives
> True]
>
> >>> print('God' and 'Devil')
>
> Devil
>
> [This is what I don't get ]
> and for that matter,I also checked out this:
>
> >>> 01 and 10
>
> 10
>
> What is python doing when we type in ('God' and 'Devil') or key in (01
> and 10) ?

This is an interesting property of python's logical operators. They
don't have to return a boolean object. (It's documented here:
http://docs.python.org/reference/expressions.html#boolean-operations)

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


Re: PyGUI - Couple of questions - TextField callbacks and drop down list....

2008-10-20 Thread greg

Hugh wrote:


TextField callbacks... I want to be able to generate a callback when a
textfield is modified. It doesn't appear to have an "action" member...


I haven't got around to adding any actions to text fields
yet.

In the meantime, you could put a key_down method on the
containing window that catches the Return or Enter key.


Is there anything I can do here? Or should I maybe subclass the
TextField class.


Unfortunately that's not easy to do at the moment. Due to
disparities in the way events are handled by the underlying
toolkits, PyGUI doesn't promise to let you intercept events
on the built-in control types by overriding methods.

I really need to rethink the whole event handling stragegy,
as it's rather a mess at the moment.


Drop-down lists...


That's another thing for the future. If you're feeling
adventurous, you could have a go at rolling your own based
on a View.

Anyway, glad you're finding it useful. Feel free to ask if
you have any more questions.

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


Re: indentation

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 18:55:46 -0400, J. Clifford Dyer wrote:

> On Mon, 2008-10-20 at 13:29 +, Steven D'Aprano wrote:
>> On Mon, 20 Oct 2008 11:01:19 +0200, Bruno Desthuilliers wrote:
>> 
>> > Steven D'Aprano a écrit :
>> >> On Sun, 19 Oct 2008 19:03:29 +0200, Bruno Desthuilliers wrote:
>> >> 
>> >>> Steven D'Aprano a écrit :
>> >>>
>> >>> (snip)
>> >>>
>>  You can use tabs, or spaces. If you use spaces, you can choose 4
>>  spaces, or 8, or any number,
>> >>> By all means, make it 4 spaces - that's the standard.
>> >> 
>> >> It's *a* standard. I believe it is the standard for the Python
>> >> standard library, but there are other standards.
>> > 
>> > I can't remember having seen any other "standard" so far.
>> 
>> 
>> How about PEP 8? It's not even hidden deep in the bowels of the PEP --
>> it's almost at the top.
>> http://www.python.org/dev/peps/pep-0008/
>> 
>> "For really old code that you don't want to mess up, you can continue
>> to use 8-space tabs."
>> 
>> 
> Fair, but limited to old code, so doesn't apply to instructions for new
> code.

I didn't say it does. But it's a standard, one of many.


>> Then there's string.expandtabs():
>> 
>> expandtabs(...)
>> S.expandtabs([tabsize]) -> string
>> 
>> Return a copy of S where all tab characters are expanded using
>> spaces. If tabsize is not given, a tab size of 8 characters is
>> assumed.
>> 
>> 
> The default for a tab does not imply anything about how python code
> should be indented.

But it implies that 8 spaces is a standard.


[snip]
> Not python.  I think when Bruno says it's *the* standard, we can assume
> he means "for python."

When you make an assumption, you make an ASS out of U and MPTION.

*wink*

I didn't think my post was terribly difficult to understand or that it 
would be so controversial. It is a simple objective fact that there is no 
such "THE" standard, not even for Python. Certainly it is true that 4-
space indents is a very common standard, and that it is recommended by 
Guido and required for the standard library, but it is not the only 
standard, not even for Python code.

I managed to avoid all the tedious arguments about which braces style 
(for C programmers) or BEGIN/END positioning (for Pascal programmers) was 
"THE" standard. I would have hoped that in the 21st century we'd got past 
that nonsense. By all means argue that interoperability with others is 
generally a good thing, and 4-space indents is sufficiently common that 
it maximizes your ability to interoperate. You won't get any arguments 
from me. (That's why I use 4-space indents, even though they are an 
Abomination Unto Nuggan.)

But let's not pretend that Windows is "THE" standard operating system, 
vanilla "THE" standard ice cream flavour, and 4-spaces "THE" standard for 
indents. If interoperability is not important to you, go right ahead and 
use any standard you like, or even pick something non-standard like 17-
space indents. There's no Indent Police who will arrest you for failing 
to live up to the standard.



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


How is the logical processing being done for strings like 'Dog' and 'Cat'

2008-10-20 Thread Sumitava Mukherjee
Hi all,
I am a novice programmer in Python.
Please could you explain me the results (regarding logical operators).

I get this:

>>> print bool('God' and 'Devil')
True

[This is ok because (any) string is True, so; (True and True) gives
True]



>>> print('God' and 'Devil')
Devil

[This is what I don't get ]
and for that matter,I also checked out this:

>>> 01 and 10
10


What is python doing when we type in ('God' and 'Devil') or key in (01
and 10) ?

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


Re: search for a python compiler program whose name is jingle

2008-10-20 Thread Nathan Seese
> I don't remember its name very clear, it may be 'jingle' or not this
> program runs on windows and can compile a python program into exe file
> without gcc
> it has no webspace but is announced on the author's blog when I find it
> some times ago.
> I can't find the link now. I there anybody else know it and tell me?
> Thanx in advance

I don't know where you're getting the name "Jingle", but I think there's 
a similar program called "Shedskin" that translates Python to C++. 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Nathan Seese
> #! /bin/sh
> python -c "import sys;exec(sys.stdin)"

I know this isn't your question, but I think you could write that more 
cleanly with:

#!/usr/bin/python
import sys
exec(sys.stdin)
--
http://mail.python.org/mailman/listinfo/python-list


Re: (relative) import trouble, sometimes it works, sometimes it doesn't ...

2008-10-20 Thread Gabriel Genellina
En Sat, 18 Oct 2008 05:52:04 -0300, Stef Mientki <[EMAIL PROTECTED]>  
escribió:


I'm running Python 2.5 and want my programs to run at least under  
Windows and Linux (preferable also Mac).

So I guess I should always use relative paths.

 From most modules I can call a global function,
that should import a dictionary from path deeper than the module itself.
The import is done in the global function.
In that global function, I get the modules path by

  SourceFile = sys._getframe(1).f_code.co_filename


Why don't you let the caller tell you its own location, using __file__?  
The above code is too much magic for me.


now to be sure to succeed the import (at least I was thinking this would  
always be successful  :-(

I need to
1- add the path of the module to be imported to sys.path
(or do a dot import)


Yes.


2- keep track of already done imports, to give a reload the next time
(or maybe always do an import followed by an reload ?)


A reload is only required if the module was changed on disk and you want  
to get the later version.



Now what I don't understand is what relative path should I use in 1:
- relative to the main application
- relative to the working directory were I started the application
- relative to the current working directory
- relative to the module that is doing the import
- relative to the module that called the global function


Relative imports assume you are inside a *package*, and they're relative  
to the current module location, each dot being one level above. See  
http://www.python.org/dev/peps/pep-0328/



I would be pleased if someone could enlighten me,
because this information is hard to find.


Yes. How import works is very poorly documented, unfortunately. You'll  
have to dig into the various PEPs and the bug tracker.


--
Gabriel Genellina

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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Peter Wang
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> Peter Wang a �crit :
>> 
>> #! /bin/sh
>> python -c "import sys;exec(sys.stdin)"
>> 
>>
>> Emacs has a function `shell-command-on-region', which takes region as
>> input for the evaluator (script above), and output its result. I have
>> tried and found it works, is there any problems for this, or any other
>> better solution for it? Thanks.
>>
> If your problem is to eval a region of a python buffer and output the
> result to another buffer, then python-mode.el (the one that comes with
> Python, not the python.el bundled with recent emacs versions) already
> know how to do so.
Yes, I want eval a region, but likely not a python buffer, for example, 
in a *w3m* buffer.
>
> Else please explain what you're trying to do ?
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: indentation

2008-10-20 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>,
Gandalf wrote:

> every time I switch editor all the script  indentation get mixed up ...

Mixed up in what way? Are you configuring your editors to do automatic
space/tab conversion in inconsistent ways?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Grant Edwards
On 2008-10-20, Stef Mientki <[EMAIL PROTECTED]> wrote:

>> I don't think I'm feeding the troll, but - ever took a look at
>> PyQt?
>
> I wanted to go from Delphi to a free / open source
> environment, for both open source and commercial applications.
>
> So the Qt license stopped me from looking any further.

The Qt license is still free/open-source for commercial
applications as long as you license your app under the GPL.

Did you mean to say for both open source and closed source
applications?

-- 
Grant

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


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> Still has some things that I would dearly love in python... like "skinned"
> gui applications.

That's a function of the GUI toolkit, not of the language. Python doesn't
make you use any GUI toolkit, nor does it prevent you from using any GUI
toolkit. It concentrates on the stuff a language should do, nothing more,
nothing less.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python certification

2008-10-20 Thread Grant Edwards
On 2008-10-20, Eric Wertman <[EMAIL PROTECTED]> wrote:

> I'm not advocating some kind of licensing for programmers.  I
> just really wish there was some reasonable gauge that could be
> used to evaluate information professionals.

It would be nice if there was, but there isn't.  AFAICT,
certification for other things in software (whether it's RedHat
or Microsoft) has proven completely worthless. There's no
reason to think certification for Python would be any
different.  As soon as there's a certification test, there are
going to be courses and study guides to allow useless people to
temporarily memorized enough to pass the test without becoming
useful.

You've still got to interview them and see what sort of
questions they ask.  I find the questions people ask to be more
revealing than the questions they answer.

-- 
Grant

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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> And 75% [1] of average Windows users will either delete the file, move it
> to a more convenient[2] location, or edit the file name to remove the dot.

Doesn't seem very likely to me. Experienced Dimdows users would well know
that stuffing around with files they don't understand is liable to break
some application or another, so they shouldn't do it.

> [2] And they are right to do so. Programs that dump config files and
> directories, hidden or not, in the top level of the user's home directory
> are incredibly rude. It may have been a Unix standard for as long as
> there has been a Unix, but it's still the programming equivalent of
> coming into somebody's house and throwing your tools all over their
> living room floor.

Hmm, actually you have a point there. There's also the security issue, in
that other users can tell what apps you've been using based on the dotfiles
present in your home directory.
--
http://mail.python.org/mailman/listinfo/python-list


What was that, what was it?

2008-10-20 Thread Aaron Brady
The bartender said I have to talk.  Actually, she didn't.

Python's a darned good comp. language.  Versatile, elegant, refined.

The Pythoneers on the newsgroup are half-way decent, too.  Attentive,
judicious.

I feel like there's a "but", but that's probably my own traumatic past
personal life.  Besides, there just was.  Anybody not get out much?

I was really impressed by the new multiprocessing module.  Good
progress.  Shows improvement.

I feel like it's just any old language, or some "garage band" language
or something.  Which is weird, because I don't have a reason to.

Is it the secretive aspect?  Am I spoiled on IDEs?  Is it the absence
of pomp, per se?  Closed-source, proprietary, up-hyped languages,
frameworks, environments and stuff certainly make one feel special.
Python proves that if it comes from anywhere at all, i.e. isn't purely
imaginary, it's not from the language.  Well, maybe not proves

If Python was a car, I think it would be a hybrid, which I'm all in
favor of, of which I'm all in favor.  Either that, or total electric.
Which makes sense because I have to plug in a laptop if I'm doing any
graphics, just like an electric.

Forgive the sentence fragments, whoever it was that called Bruno on
the its-it's problem.  Possessive vs. contracted.  Could we add
contractions in Python?  The object membership operator, "dot", has
possessives already.

I'm 27, and trying to quit smoking.  It's hard.  I keep wanting
cigarettes.  I'm not totally unconditional, stonewall, hard-line
quitting, just more like dabbling in quitting.  There's at least a
behavioral in addition to chemical factor in it, almost social factor,
as though it's a part of my identity.  I don't want to smoke forever,
if anybody does, but I'm in no hurry.  I'm a vegetarian and in fine
health, so whatever.

Enough of the personal.  I think it's hard to tell when people are
being sarcastic on Usenet.  It's not just me, sorry.  They get all
kinds of people at the restaurant, so you can only imagine who shows
up to Usenet.  Well, I can only, at any rate.  I think there are
plenty of people who could say a lot of the stuff seriously.  That's
what sarcasm is, though, essentially.  No it doesn't come through very
well.  It's hard enough with people one knows in text, to start with,
so with strangers it's mostly guessing.  And yeah, even after 6, 8
months, I still have no clue what any of the regulars believe on the
outside, in real life, so detecting sarcasm is made impossible by
consequence ("impossiblized").

Plus there's nothing about sarcasm in the Zen.

One of the servers said, "True 'dat," about the smoking thing.  This
isn't comp.blogs.python, but this is my peer group and I need to
interact.  So refer to my other posts if you have complaints.  Or call
my lawyer.  Or get me one.  Speaking of which, this isn't
old.and.bitter.python /either/, so in some cases, "Eat it, pal."  All
due respect, but no more.

In other news, it's not like the Microsoft documentations suck
exactly, but they still make some omissions at the very least, if not
commissions.  See, from my perspective, favoritism is always sarcastic
anyway, so I stand no chance of telling what is and what isn't.
Either way, does volume excuse quality?  Is one error in 100 correct
pages better than 1 error in 10 correct ones?

Lastly, I think the 'dict of dicts' questions over the past few months
have been the most interesting.  Someone should study it.  The for
loop of partial calls of 'defaultdict' was probably the best, IMO.
But on that note, back to you at the station.


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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> Do you really think there are Linux or Mac systems with a C: drive?

And what about files on Dimdows systems kept on a drive other than C?

> This whole question is based on the ludicrous assumption that general
> file system paths can be platform-independent.

There is supposed to be a POSIX-compliant layer somewhere underneath all the
Dimdows crud. You could write to that.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Ross Ridge wrote:

> However, the normal place to store settings on Windows is in the registry.

Which becomes a single point of failure for the whole system.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Stef
Mientki wrote:

> I (again) wonder what's the perfect way to store, OS-independent,
> filepaths ?

URLs beginning file://.
--
http://mail.python.org/mailman/listinfo/python-list


Re: better scheduler with correct sleep times

2008-10-20 Thread greg

sokol wrote:


What was a surprise to me was that python sched.py makes the same
mistake as I did in my first version.


The sched module is *not* designed for multithreading. It
assumes that the thread waiting for events is the only one
putting events into the queue, so it's impossible for an
event to get scheduled while in the midst of a sleep. It
also doesn't take any measures to protect its data structures
from concurrent access.

The documentation could make this clearer, especially since
it confusingly talks about "allowing other threads to run".

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


Re: indentation

2008-10-20 Thread Ross Ridge
Terry Reedy  <[EMAIL PROTECTED]> wrote:
>Yes there is.  If I type *hypothetical* code for a post, *I* have to 
>type all the spaces, and I often use 2 per indent level.  If I type in 
>IDLE, *it* adds the spaces (4 per indent) automatically.

Hmm... I have doubt then how much it really can be *the* standard if
it's only being followed it when it's convenient.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python equivalent for C module

2008-10-20 Thread Aaron Brady
On Oct 20, 3:08 pm, [EMAIL PROTECTED] (Ville M.
Vainio) wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> > STDOUT is for *normal* program outputs. Debug informations,
> > warnings, and all verbosity should go to STDERR.
>
> Actually, stderr is for errors, by convention. It's rather impolite to
> dump trivial debug info to stderr, which often "alerts" the user more
> than stdout.
snip

Indeed.  Just dump to STDTRIVIAL.
--
http://mail.python.org/mailman/listinfo/python-list


Re: indentation

2008-10-20 Thread J. Clifford Dyer
On Mon, 2008-10-20 at 13:29 +, Steven D'Aprano wrote:
> On Mon, 20 Oct 2008 11:01:19 +0200, Bruno Desthuilliers wrote:
> 
> > Steven D'Aprano a écrit :
> >> On Sun, 19 Oct 2008 19:03:29 +0200, Bruno Desthuilliers wrote:
> >> 
> >>> Steven D'Aprano a écrit :
> >>>
> >>> (snip)
> >>>
>  You can use tabs, or spaces. If you use spaces, you can choose 4
>  spaces, or 8, or any number,
> >>> By all means, make it 4 spaces - that's the standard.
> >> 
> >> It's *a* standard. I believe it is the standard for the Python standard
> >> library, but there are other standards.
> > 
> > I can't remember having seen any other "standard" so far.
> 
> 
> How about PEP 8? It's not even hidden deep in the bowels of the PEP -- 
> it's almost at the top.
> http://www.python.org/dev/peps/pep-0008/
> 
> "For really old code that you don't want to mess up, you can continue to 
> use 8-space tabs."
> 

Fair, but limited to old code, so doesn't apply to instructions for new
code.

> 
> Then there's string.expandtabs():
> 
> expandtabs(...)
> S.expandtabs([tabsize]) -> string
> 
> Return a copy of S where all tab characters are expanded using spaces.
> If tabsize is not given, a tab size of 8 characters is assumed.
> 

The default for a tab does not imply anything about how python code
should be indented.

> 
> Here's Jamie Zawinski:
> http://www.jwz.org/doc/tabs-vs-spaces.html
> 
> "On defaultly-configured Unix systems, and on ancient dumb terminals and 
> teletypes, the tradition has been for the TAB character to mean ``move to 
> the right until the current column is a multiple of 8.'' (As it happens, 
> this is how Netscape interprets TAB inside  as well.) This is also 
> the default in the two most popular Unix editors, Emacs and vi."
> 

Again, refers to the interpretation of a tab, rather than indentation
conventions.

> 
> This page is a little old (2002), but it states that the standards for 
> OpenBSD and Linux (presumably the kernels) are 8 space indents:
> 
> http://xarg.net/writing/tabs
> 

Not python.  I think when Bruno says it's *the* standard, we can assume
he means "for python."

> Here's a style guide that recommends 2, 3 or 4 space indents:
> 
> http://www.cs.bris.ac.uk/Teaching/Resources/COMS12100/style/
> 

Again, it's for java and C, not python.

> 
> And of course, whenever there's a difference of opinion, we can turn to 
> the ultimate source of all knowledge: Googlefight!  *wink*
> 
> http://www.googlefight.com/index.php?lang=en_GB&word1=tab+8
> +spaces&word2=tab+4+spaces

> Nearly 50 million hits for "tab 8 spaces" versus a piddly 762 thousand 
> hits for "tab 4 spaces".
> 
> 

And I still don't care how many spaces are in a tab. ;D

Cheers,
Cliff



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


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Stef Mientki

Ville M. Vainio wrote:

Stef Mientki <[EMAIL PROTECTED]> writes:


  

Sorry but for GUI design, Python is pre-historic ;-)


Time to show the "don't feed the troll" sign, I guess.
  

Even without the smiley, I'm convinced of my statement.
cheers,



I don't think I'm feeding the troll, but - ever took a look at PyQt?
  

I wanted to go from Delphi to a free / open source environment,
for both open source and commercial applications.
So the Qt license stopped me from looking any further.

cheers,
stef

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


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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Eric Wertman
> Do you really think there are Linux or Mac systems with a C: drive?
>
> This whole question is based on the ludicrous assumption that general
> file system paths can be platform-independent. That's a bit like trying
> to write code that is programming language-independent.


That's sort of where I was going originally... just pick a way to
store the path elements and write some simple functions (yes, many of
them will just be os.path calls) to reconstruct them based on the
actual needs of the application.  If your root element is in
ascii.letters  then it's most likely windows machine, so adding a ':'
and using os.path.join would be appropriate in the function.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Ville M. Vainio
Stef Mientki <[EMAIL PROTECTED]> writes:


> >> Sorry but for GUI design, Python is pre-historic ;-)
> >
> > Time to show the "don't feed the troll" sign, I guess.
> Even without the smiley, I'm convinced of my statement.
> cheers,

I don't think I'm feeding the troll, but - ever took a look at PyQt?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 23:56:22 +0200, Stef Mientki wrote:

> Bruno Desthuilliers wrote:
>> Eric Wertman a écrit :
> I (again) wonder what's the perfect way to store, OS-independent,
> filepaths ?
>>>
>>> I'm in agreement that perfect probably isn't applicable.  If I were
>>> doing this myself, I might store the information in a tuple:
>>>
>>> base = 'some root structure ('/' or 'C')
>>
>> make it "C:\"
> wouldn't " C:/"  be more universal and therefor better ?


Do you really think there are Linux or Mac systems with a C: drive?

This whole question is based on the ludicrous assumption that general 
file system paths can be platform-independent. That's a bit like trying 
to write code that is programming language-independent.


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


Re: Creating single .exe file without py2exe and pyinstaller

2008-10-20 Thread MRAB
On Oct 20, 4:48 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> Tino Wildenhain wrote:
> > Hi,
>
> > Abah Joseph wrote:
> >> I have written a small application of about 40-45 lines which is about
> >> 4KB, so I want to create a single .exe file from it, using py2exe it
> >> created unnecessary files, that just increase the size of the program
> >> and also less portable to me. What else can I use?
>
> > the "unneccessary files" you say, are what your 40-45 lines bring to
> > life.
>
> > 1) just distribute the 40-45 lines - but this requires python
> >    installation on users end
>
> > 2) use a python to C(++) compiler and compile the result to .exe,
> >    works pretty well for simple applications:
>
> >    http://shed-skin.blogspot.com/
>
> > Regards
> > Tino
>
> 3) Stop worrying about the size of the distribution.  In today's world 4Mb is
> trivial to download.
>
Unless you're still on dialup...
--
http://mail.python.org/mailman/listinfo/python-list


Re: windows / unix path

2008-10-20 Thread MRAB
On Oct 20, 4:47 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> Marcin201 wrote:
> > Is there an built-in functionality in python to convert Windows paths
> > to Unix paths?  I am running into problems when creating data files on
> > Windows and the running them on a Unix platform.  I create paths using
> > os.path.join.
>
> > os.path.join('Pictures', '01.jpg') returns 'Pictures\\01..jpg' on
> > Win.  When I read files created on Win under Unix this is a problem,
> > python cannot open 'Pictures\\01.jpg'
>
> > Thanks,
>
> > Marcin
>
> I use posixpath when I want to "force" forward slashes that I know will work 
> on
> Linux.  Actually the forward slashes work fine on Windows also (undocumented
> feature of Windows).
>
FYI, in Windows the standard is for commandline options to begin with
a slash, eg dir /b, but as long as the path doesn't begin with one
you'll be OK. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python equivalent for C module

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 17:09:25 -0400, Derek Martin wrote:

> On Mon, Oct 20, 2008 at 07:29:16PM +0200, Bruno Desthuilliers wrote:
>> This should have been:
>> 
>> fprintf(STDERR, "DEBUG: %s", msg);
> 
> No, it shouldn't have.  If I turn on debugging, I  want the debug
> messages to go to stdout, so that they can be captured along with the
> output (of which there is almost none anyway) to clearly indicate when
> they happened.

I agree with this: debugging messages aren't errors, and shouldn't go to 
stderr.


[...]
>> >Then in the modules that wanted to use it, I did:
>> >
>> >from debug import DEBUG, dprint
>> >But I got some weird behavior.  The imported copy
>> 
>> It's not a copy.
> 
> Actually, I'm pretty sure it is; i.e. there are two copies of the name:
> one in the namespace of the module, and one in the namespace of the file
> into which I imported it.  

Names are not first class Python objects. You can't pass a name to a 
function and say "do something to this *name*, not the object".

(Of course you can pass a string that happens to match the name to exec, 
but that's not the same thing.)

If you dig around in globals() or locals(), you will find strings 'DEBUG' 
and 'dprint', but they aren't "names". They're just the strings that 
represents the names, and it turns out that CPython caches many (all?) 
such strings which look like identifiers, so there probably is literally 
one and only one string 'DEBUG' no matter how many times you import the 
module.

All of this is just splitting hairs, because you don't really mean Python 
is making a copy of the name 'DEBUG', but of the *data* that DEBUG refers 
to, namely the object True. And it turns out that True is a singleton: 
there is only ever one object True.

But even if DEBUG was set to some other value, say [1, 2, 3, 'x'], you'd 
still be wrong, because Python promises never to copy objects unless you 
explicitly tell it to. There are a number of ways to prove this, but 
perhaps this is the simplest:

DEBUG = [True]  # a mutable list

Now from your calling code, do this:

from module import DEBUG
DEBUG[0] = False  # mutate the object, don't rebind the name


> At the time they are created, they both point
> to the same object.  Is that not the very definition of a copy?

No. It would be a copy if they pointed to different objects, where one 
object was a copy of the other.


> The
> object itself may exist only in one place, 

which is exactly why there is no copy. It's the same object.


> but it has two names; one in each namespace.
> 
>> >of DEBUG is
>> >read-only;
>> 
>> It's not read-only.
> 
> The *object* very much is: it is immutable.

So what? The *name* DEBUG is not read-only.


> The name of that object is
> DEBUG, and thus DEBUG is read-only.

But it clearly isn't read-only, because as you yourself point out:

> You can make DEBUG point to a
> different object by binding a different value to it


[...]
> Right, several people have already pointed this out.  Which leads me to
> believe that the point of your reply was to berate me into following
> your conventions, which I have no interest in doing, in part because
> they are counterproductive to my goals, and in part because they are
> counter to the way I've been programming for 25 years. Fortunately, it's
> not your call how I write my code.

No, and it's not your call what advice people give you. If you refuse to 
follow good Pythonic advice because you prefer the way you learned 
programming a quarter century ago (before Python even existed), please go 
right ahead, but don't be surprised if people consider you a lousy Python 
programmer.

 
>> Now note that ALL_UPPER names are - by convention - considered
>> 'constants'. If this is supposed to be altered, don't write it
>> ALL_UPPER.
> 
> YOUR convention, not mine.

Actually it is a very common convention in Python circles. I often use it 
myself. However it's not the only one, and from time to time I use 
others. I would consider using DEBUG unusual, but not excessively so.


>> Also and FWIW, Python has a logging module in it's stdlib. Please use
>> it instead of any half-backed squared-wheel homegrown solution.
> 
> Note that the correct possessive form of "it" is "its" with no
> apostrophe.  This was the only thing of value which you contributed,
> though really, using that is way overkill for my needs.  If I've written
> bad code, by all means, please correct it.  If I've written code in a
> style that you happen not to like, please feel free to keep that to
> yourself.

Deary deary me... you come along here, asking noob Python questions, and 
then get shirty when people give you friendly and perfectly good answers. 
Are you trying to ensure that the next question you ask remains 
unanswered?




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


Re: subprocess.Popen on Windows

2008-10-20 Thread Eric Carlson

Werner F. Bruhin wrote:

I am trying to use subprocess - it basically works but.

   command =  'ping ' + '-n '+ str(count) + ' -l ' + 
str(size) + ' ' + str(node)

   print command
   p = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
   pout = p.stdout.read()

This works for me but I see the Windows command window, is there a way 
to call subprocess without a command window showing?


I am trying to replace:

fdout, fdin = popen2.popen4('ping -n '+ str(count)+ ' -l '+ str(size) +' 
'+node)


Which did not show the command window.

I did quit a bit of googling bug so far did not find an answer to my 
problem.


Appreciate any hints on how this can be accomplished.

Werner


Try:

p = subprocess.Popen(command, shell=True, tdin=subprocess.PIPE, 
stdout=subprocess.PIPE)


was working on xp and osx
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python certification

2008-10-20 Thread Eric Wertman
> I would hate to live in a world where you had to have three years of
> graduate professional training to write a for-loop for pay, or where
> scientists and mathematicians were prohibited from writing code (practicing
> software) without a license.  Or where someone who just wanted to practice
> Python had to first master assembly.
>
> I would be interested to hear if you know something about medical/legal
> exams, quite aside from there use as legal cudgels, that would contribute to
> (carefully) improving voluntary computer training and exams.

I think what I'm after is something not so extreme as this.  Obviously
there are numerous folks out there that don't have a boatload of
formal education and are quite competent, while the opposite is also
almost certainly true.  Maybe I'm just reacting negatively to the
constant advertisements I hear on the radio for '6 months to your
Microsoft certification' blah blah, and the general trend I see that
says you can ignore the need for 'expensive experts' if you just use
vendor X's solution.  The truth I perceive is that IT is an unusual
field where one good employee can accomplish more than any number of
mediocre ones ever will.  I'm not sure a lot of businesses grasp this,
they still think that if there's a problem with getting something
done, they just need more people, when in reality they would
accomplish more by removing the less competent ones than adding more
of any kind.

I'm not advocating some kind of licensing for programmers.  I just
really wish there was some reasonable gauge that could be used to
evaluate information professionals.  There are many people in the
field that are not only incompetent, but they are that way on purpose,
and they use the complexity of the field to deceive whoever they can.
They may or may not be 'certified' and they may or may not have
master's degrees.

I see your points.  Again, I think mostly this is just my frustration
in general.  My perception of the world lately is that the stupid and
apathetic have really begun to take over.  Maybe it was always like
that, or maybe I'm wrong.  Or... maybe it's just Monday :).
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick newbie syntax question

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 12:24:14 -0700, Robocop wrote:

> oops!   Sorry about that, i should have just copied my code directly. I
> actually did specify an int in range:
>> > year = '2008'
>> > month = '09'
>> > limit = '31'
>> > for i in range(1,int(limit)):
> 
> The code is currently failing due to the syntax in the filter,
> particularly the section "date = year'-'month'-'i"

Name binding ("date = something") is not an expression and must be on a 
line of its own. So you can't do something like:

function(y=x+1, 2, 3)

(Except of course for function default values, which is not quite the 
same thing.)


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


Re: what's the python for this C statement?

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 17:01:13 +, Lie Ryan wrote:

> On Mon, 20 Oct 2008 12:34:11 +0200, Hrvoje Niksic wrote:
> 
>> Michele <[EMAIL PROTECTED]> writes:
>> 
>>> Hi there,
>>> I'm relative new to Python and I discovered that there's one single
>>> way to cycle over an integer variable with for: for i in range(0,10,1)
>> 
>> Please use xrange for this purpose, especially with larger iterations.
>> range actually allocates a sequence.
> 
> Actually that doesn't really matter unless the loop is extremely big (>
> a million), since range is much faster than xrange for smaller values
> (which might be the more typical case). 


That hasn't been true for some time now:

>>> timeit.Timer('range(3)').repeat()
[1.8658630847930908, 0.89470076560974121, 0.88842916488647461]
>>> timeit.Timer('xrange(3)').repeat()
[0.71410012245178223, 0.69949698448181152, 0.69640421867370605]


That's on Python 2.5.



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


Re: Don't understand syntax error: unqualified exec is not allowed ..

2008-10-20 Thread Terry Reedy

Stef Mientki wrote:

hello,

I've syntax error which I totally don't understand:

## mainfile :
import test_upframe2

if __name__ == '__main__':
 var1 = 33
 code = 'print var1 + 3 \n'
 test_upframe2.Do_Something_In_Parent_NameSpace ( code )

### file = test_upframe2 :
class Do_Something_In_Parent_NameSpace ( object ) :
 def __init__ ( self, code ) :
 def do_more ( ) :
 nonvar = [3,4]
 while len ( nonvar ) > 0 :# <<<===
   nonvar.pop()# <<<===


Indendation is screwed. Is the above all do_more body?


   import sys
   p_locals  = sys._getframe(1).f_locals


Which locals does this get you? __init__'s? (locals()?)


   p_globals = sys._getframe(1).f_globals


Isn't this just the same as globals()?


   try :
 exec ( code, p_globals, p_locals )


This is 3.0 exec function syntax.  Postings should specify which 
interpreter you are running, especially when mucking with

internals.


   except :
 print 'ERROR'


gives me:
SyntaxError: unqualified exec is not allowed in function '__init__' it 
contains a nested function with free variables (gui_support.py, line 
408)   
"unqualified exec" : I thought that meant there is some ambiguity in the 
namespace, but  I explictly definied the namespace


The function "do_more"  is never called, so what does it matter what's 
in there ?


If I remove the while-loop (which of course I can't) the syntax error 
disappears.


I can place the function either as a class method or as a normal 
function outside the class,

which both works well.
But I want the method / function not to be hidden.


Since you are hiding it, I presume you mean to be, not not to be.


Why does the above syntax error appear ?
Are  there other ways to hide the function ?


Either use module level __all__ or name the function _do_more and anyone 
will know it is private to the module.


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


Re: indentation

2008-10-20 Thread Steven D'Aprano
On Mon, 20 Oct 2008 14:25:17 -0400, Terry Reedy wrote:

> If I type *hypothetical* code for a post, *I* have to
> type all the spaces, and I often use 2 per indent level.  If I type in
> IDLE, *it* adds the spaces (4 per indent) automatically.

But of course you would never post code without testing it first, right? 
That would an Abomination Unto Nuggan.

*wink*


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


Re: Python certification

2008-10-20 Thread Terry Reedy

Eric Wertman wrote:

Given the way that medical/legal licensing is used to stifle competition,
prevent innovation, and keep people from earning a living delivering simple
services that people need at prices they can afford, 'more like' would have
to be done very carefully.


To draw an analogy... imagine, if you will, a system where
pharmaceutical companies are the leading source of doctor
certifications.  While I'm sure there are many valid arguments that
would show today's system is far from perfect, I'm thinking that would
be a worse horror by some order of magnitude.


If pharmaceutical companies had more influence on licensing people to 
make drug suggestions/prescriptions, I suspect they would give more 
power to nurses and pharmacists to make such suggestions, to the 
improvement of health care in America.  America's legal care system is 
*way* far from perfect, especially in the civil sphere, though I read it 
is even more wretched elsewhere.


I would hate to live in a world where you had to have three years of 
graduate professional training to write a for-loop for pay, or where 
scientists and mathematicians were prohibited from writing code 
(practicing software) without a license.  Or where someone who just 
wanted to practice Python had to first master assembly.


I would be interested to hear if you know something about medical/legal 
exams, quite aside from there use as legal cudgels, that would 
contribute to (carefully) improving voluntary computer training and exams.


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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Stef Mientki

Bruno Desthuilliers wrote:

Eric Wertman a écrit :

I (again) wonder what's the perfect way to store, OS-independent,
filepaths ?


I'm in agreement that perfect probably isn't applicable.  If I were
doing this myself, I might store the information in a tuple:

base = 'some root structure ('/' or 'C')


make it "C:\"

wouldn't " C:/"  be more universal and therefor better ?



path = ['some','set','of','path','names']
filename = 'somefile.ext'

pathdata = (root,path,filename)

and write a couple of simple functions to reconstruct them based on 
the os.


like, err, os.path.join ?
Yes (because these functions don't function correctly with i.e pdb, 
which might be due to bugs in pdb).

cheers,
Stef

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


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


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Stef Mientki

Bruno Desthuilliers wrote:

Stef Mientki a écrit :

Lawrence D'Oliveiro wrote:

In message <[EMAIL PROTECTED]>, Dotan
Cohen wrote:

 

I often see mention of SMBs that either want to upgrade their Windows
installations, or move to Linux, but cannot because of inhouse VB
apps.



Probably best to leave those legacy VB apps alone and develop new
replacements in a more open, cross-platform language, like Python.
  

Sorry but for GUI design, Python is pre-historic ;-)


Time to show the "don't feed the troll" sign, I guess.

Even without the smiley, I'm convinced of my statement.
cheers,
Stef

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


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


Re: Mail reader & spam

2008-10-20 Thread Aaron Brady
On Oct 13, 2:19 pm, Cousin Stanley <[EMAIL PROTECTED]> wrote:
> > I'm hesitating to change news readers 
> > 
>
>   You might try the python-based  XPN  news client at 
>
>      http://xpn.altervista.org/index-en.html
>
>   I've used it for the past few years
>   and like it very much 
>
> --
> Stanley C. Kitching
> Human Being
> Phoenix, Arizona

Dear Human Being,

Hi, I tried it out.  I like the layout definitely, plus the feel of
it, colors, etc.  It doesn't do the things I named that I like
though.  It's threading is buggy and watch flags don't propagate
consistently.  And there isn't any less spam.

Google has a full screen of topics.  Click on one, and get the full
thread.  It's (contraction) a lot more bandwidth, which might be
important to people still on phone modems.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what's the python for this C statement?

2008-10-20 Thread Terry Reedy

Lie Ryan wrote:

(which might be the more typical case). And I think range will be an 
iterator in the future, imitating the behavior of xrange. So it doesn't 
really matter anyway.


In 3.0, range is a class and range(arg) is a re-iterable instance of 
that class.


>>> a = range(10,2,-3)
>>> a
range(10, 2, -3)
>>> list(a)
[10, 7, 4]
>>> list(a)
[10, 7, 4]

Re-iterablility is handy if you want to iterate twice over the same 
range, especially is the range object is computed elsewhere.


Map and filter, on the other hand, produce one-use iterators.  Filter 
takes one iterable as input and map takes many iterables.  Both make no 
presumption that the inputs are re-iterable rather than a one-time 
iterators.


Terry Jan Reedy

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


Re: Python certification

2008-10-20 Thread Bruno Desthuilliers

Eric Wertman a écrit :

Given the way that medical/legal licensing is used to stifle competition,
prevent innovation, and keep people from earning a living delivering simple
services that people need at prices they can afford, 'more like' would have
to be done very carefully.


To draw an analogy... imagine, if you will, a system where
pharmaceutical companies are the leading source of doctor
certifications.


Ain't that already the case ?

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


Re: Python equivalent for C module

2008-10-20 Thread Derek Martin
On Mon, Oct 20, 2008 at 07:29:16PM +0200, Bruno Desthuilliers wrote:
> This should have been:
> 
> fprintf(STDERR, "DEBUG: %s", msg);

No, it shouldn't have.  If I turn on debugging, I  want the debug
messages to go to stdout, so that they can be captured along with the
output (of which there is almost none anyway) to clearly indicate when
they happened.

> STDOUT is for *normal* program outputs. Debug informations, warnings, 
> and all verbosity should go to STDERR.

That's your opinion, and I disagree.  Besides which, if you're running
a program in debug mode, you're DEBUGGING... "normal" does not apply.
You're being rather presumptuous... you don't even know how my program
is being used.

> >Then in the modules that wanted to use it, I did:
> >
> >from debug import DEBUG, dprint
> >But I got some weird behavior.  The imported copy
> 
> It's not a copy.

Actually, I'm pretty sure it is; i.e. there are two copies of the
name: one in the namespace of the module, and one in the namespace of
the file into which I imported it.  At the time they are created, they
both point to the same object.  Is that not the very definition of a
copy?  The object itself may exist only in one place, but it has two
names; one in each namespace. 

> >of DEBUG is
> >read-only;
> 
> It's not read-only.

The *object* very much is: it is immutable.  The name of that object
is DEBUG, and thus DEBUG is read-only.  You can make DEBUG point to a
different object by binding a different value to it, but if that value
is of an immutable type, it will still be a read-only object.

In the sentence I wrote, as well as in general, "DEBUG" actually
refers to two different things: the object bound to the name, and the
name itself.  It's up to the reader to infer which sense is correct
given the thing being said about it.  It just so happens that the
English sentence I wrote refers to both simultaneously.

> Just use a fully qualified name, so you dont make DEBUG local:
> 
> import debug
> print debug.DEBUG
> debug.DEBUG = True
> print debug.DEBUG

Right, several people have already pointed this out.  Which leads me
to believe that the point of your reply was to berate me into
following your conventions, which I have no interest in doing, in part
because they are counterproductive to my goals, and in part because
they are counter to the way I've been programming for 25 years.
Fortunately, it's not your call how I write my code.

> Now note that ALL_UPPER names are - by convention - considered 
> 'constants'. If this is supposed to be altered, don't write it ALL_UPPER.

YOUR convention, not mine.

> Also and FWIW, Python has a logging module in it's stdlib. Please use it 
> instead of any half-backed squared-wheel homegrown solution.

Note that the correct possessive form of "it" is "its" with no
apostrophe.  This was the only thing of value which you contributed,
though really, using that is way overkill for my needs.  If I've
written bad code, by all means, please correct it.  If I've written
code in a style that you happen not to like, please feel free to keep
that to yourself.

> My 2 cents

Must be Zimbabwe currency...

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpcR9dOjsCO1.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


subprocess.Popen on Windows

2008-10-20 Thread Werner F. Bruhin

I am trying to use subprocess - it basically works but.

   command =  'ping ' + '-n '+ str(count) + ' -l ' + 
str(size) + ' ' + str(node)

   print command
   p = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
   pout = p.stdout.read()

This works for me but I see the Windows command window, is there a way 
to call subprocess without a command window showing?


I am trying to replace:

fdout, fdin = popen2.popen4('ping -n '+ str(count)+ ' -l '+ str(size) +' 
'+node)


Which did not show the command window.

I did quit a bit of googling bug so far did not find an answer to my 
problem.


Appreciate any hints on how this can be accomplished.

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


Re: quick newbie syntax question

2008-10-20 Thread Robocop
date = "%s-%s-%s" % (year, month, i) is exactly what i'd like to do.

The Table object will just be a mysql table, and the filter function
will yield a list filtered for those dates.
For my purposes the limit variable will not be static, depending on
which day of the month it is i will only want it to iterate up to that
date in the month (i use 31 here as an example as i would want it to
iterate through the 30th of september).  Thanks for the input!
On Oct 20, 1:21 pm, Larry Bates <[EMAIL PROTECTED]> wrote:


> Robocop wrote:
> > oops!   Sorry about that, i should have just copied my code directly.
> > I actually did specify an int in range:
> >>> year = '2008'
> >>> month = '09'
> >>> limit = '31'
> >>> for i in range(1,int(limit)):
>
> > The code is currently failing due to the syntax in the filter,
> > particularly the section "date = year'-'month'-'i"
>
> I believe you want something more like
>
> date = "%s-%s-%s" % (year, month, i)
>
> but then again I can't quite figure out what is is that you are wanting to do
> (Note: September doesn't have 31 days).
>
> Where did Table object come from and what does the table.objects.filter method
> do and what are the appropriate arguments to that method?  If it was "my"
> method, and I wanted to use it this way, I would think about changing it so 
> that
> it accepted a filtering function and returned only those objects that passed 
> the
> filtering function:
>
> def myFilter(obj):
>      return (obj.date >= '2008-09-01' and obj.date <= '2008-09-30')
>
> class objects(object):
>      def __init__(self):
>          self.objects = []
>
>      def filter(filterFunc):
>          return [x for x in self.objects if filterFunc(x)]
>
> Then
>
> temp = Table.objects.filter(myFilter)
>
> temp is a list of objects you can act on.
>
> -Larry



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


Don't understand syntax error: unqualified exec is not allowed ..

2008-10-20 Thread Stef Mientki

hello,

I've syntax error which I totally don't understand:

## mainfile :
import test_upframe2

if __name__ == '__main__':
 var1 = 33
 code = 'print var1 + 3 \n'
 test_upframe2.Do_Something_In_Parent_NameSpace ( code )

### file = test_upframe2 :
class Do_Something_In_Parent_NameSpace ( object ) :
 def __init__ ( self, code ) :
  
   def do_more ( ) :

 nonvar = [3,4]
 while len ( nonvar ) > 0 :# <<<===
   nonvar.pop()# <<<===

   import sys
   p_locals  = sys._getframe(1).f_locals
   p_globals = sys._getframe(1).f_globals
   try :
 exec ( code, p_globals, p_locals )
   except :
 print 'ERROR'


gives me:
SyntaxError: unqualified exec is not allowed in function '__init__' it 
contains a nested function with free variables (gui_support.py, line 
408)

"unqualified exec" : I thought that meant there is some ambiguity in the 
namespace, but  I explictly definied the namespace


The function "do_more"  is never called, so what does it matter what's 
in there ?


If I remove the while-loop (which of course I can't) the syntax error 
disappears.


I can place the function either as a class method or as a normal 
function outside the class,

which both works well.
But I want the method / function not to be hidden.

Why does the above syntax error appear ?
Are  there other ways to hide the function ?

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


Re: Python certification

2008-10-20 Thread Eric Wertman
> Given the way that medical/legal licensing is used to stifle competition,
> prevent innovation, and keep people from earning a living delivering simple
> services that people need at prices they can afford, 'more like' would have
> to be done very carefully.

To draw an analogy... imagine, if you will, a system where
pharmaceutical companies are the leading source of doctor
certifications.  While I'm sure there are many valid arguments that
would show today's system is far from perfect, I'm thinking that would
be a worse horror by some order of magnitude.
--
http://mail.python.org/mailman/listinfo/python-list


Re: a question about Chinese characters in a Python Program

2008-10-20 Thread Ben Finney
est <[EMAIL PROTECTED]> writes:

> IMHO it's even better to output wrong encodings rather than halt the
> WHOLE damn program by an exception

I can't agree with this. The correct thing to do in the face of
ambiguity is for Python to refuse to guess.

> When debugging encoding problems, the solution is simple. If
> characters display wrong, switch to another encoding, one of them
> must be right.

That's debugging problems not in the program but in the *data*, which
Python is helping with by making the problems apparent as soon as
feasible to do so.

> But it's tiring in python to deal with encodings, you have to wrap
> EVERY SINGLE character expression with try ... except ... just imagine
> what pain it is.

That sounds like a rather poor program design. Much better to sanitise
the inputs to the program at a few well-defined points, and know from
that point that the program is dealing internally with Unicode.

> Dealing with character encodings is really simple.

Given that your solutions are baroque and complicated, I don't think
even you yourself can believe that statement.

> Like I said, str() should NOT throw an exception BY DESIGN, it's a
> basic language standard.

Any code should throw an exception if the input is both ambiguous and
invalid by the documented specification.

> str() is not only a convert to string function, but also a
> serialization in most cases.(e.g. socket) My simple suggestion is:
> If it's a unicode character, output as UTF-8; other wise just ouput
> byte array, please do not encode it with really stupid range(128)
> ASCII. It's not guessing, it's totally wrong.

Your assumption would require that UTF-8 be a lowest *common*
denominator for most output devices Python will be connected to.
That's simply not the case; the lowest common denominator is still
ASCII.

I yearn for a future where all output devices can be assumed, in the
absence of other information, to understand a common Unicode encoding
(e.g. UTF-8), but we're not there yet and it would be a grave mistake
for Python to falsely behave as though we were.

-- 
 \ “I went to a fancy French restaurant called ‘Déjà Vu’. The head |
  `\  waiter said, ‘Don't I know you?’” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


cProfiler Question

2008-10-20 Thread Brian Stinar
Hello,

I am not certain if I understand the .enable() and .disable() methods
correctly, but it seems like they should make a profiling object stop
collecting profiling information. When I run the below python program,
I am seeing results that I am not expecting. If anyone has insight
into why my expectations and reality are not meeting up (just with
regards to the below program, not all my hopes and dreams), I would be
happy to hear them.


--- Begin Example Code

from cProfile import *
from pstats import *

p=Profile()

def foo():
  a=[]
  for i in xrange(1000):
  bar()
  a.append(i)
  #print a

def bar():
  d={}
  a=[]
  p.disable()
  for i in xrange(1000):
  d[i]=[i+1]
  a.append(i)
  p.enable()

def main():
  p.run("foo()")
  #p.print_stats()
  p.dump_stats("foo.prof")
  s=Stats("foo.prof")
  s.print_stats()
  s.print_callers()


if __name__ == "__main__":
  main()


--- End Example Code

OK, so I want to profile the a.append(i) within foo, and not profile
the a.append(i) within bar. Here are the results I receive:



--- Begin Results for Example

[EMAIL PROTECTED] ~/spider_project $ ./profiler_tester.py
Mon Oct 20 20:13:51 2008foo.prof

 3003 function calls in 0.002 CPU seconds

   Random listing order was used

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 10000.0010.0000.0010.000 ./profiler_tester.py:18(bar)
 10000.0000.0000.0000.000 {method 'append' of
'list' objects}
 10010.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}
10.0000.0000.0000.000 ./profiler_tester.py:11(foo)
10.0000.0000.0000.000 :1()


   Random listing order was used

Function  was called by...
  ncalls  tottime  cumtime
./profiler_tester.py:18(bar)  <-   10.000
  0.000  ./profiler_tester.py:11(foo)
{method 'append' of 'list' objects}   <-
{method 'disable' of '_lsprof.Profiler' objects}  <-10000.000
  0.000  ./profiler_tester.py:18(bar)
./profiler_tester.py:11(foo)  <-   10.000
  0.000  :1()
:1()  <-



--- End Results for Example

The results from s.print_stats() look OK. 1000 calls to append. This
makes sense, since foo is calling it 1000 times. However, when we look
at the s.print_callers() I become confused by append. The data for
append looks like it is missing.

When I comment out the disable and enable profiling commands, I get
what I am expecting:


--- Begin Results for
Commented Out disable and enable

Mon Oct 20 20:21:33 2008foo.prof

 1002003 function calls in 1.243 CPU seconds

   Random listing order was used

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 10000.8950.0011.1530.001 ./profiler_tester.py:18(bar)
  10010000.2580.0000.2580.000 {method 'append' of
'list' objects}
10.0000.0000.0000.000 {method 'disable' of
'_lsprof.Profiler' objects}
10.0890.0891.2431.243 ./profiler_tester.py:11(foo)
10.0000.0001.2431.243 :1()


   Random listing order was used

Function  was called by...
  ncalls  tottime  cumtime
./profiler_tester.py:18(bar)  <-10000.895
  1.153  ./profiler_tester.py:11(foo)
{method 'append' of 'list' objects}   <-10000.000
  0.000  ./profiler_tester.py:11(foo)
 1000.258
  0.258  ./profiler_tester.py:18(bar)
{method 'disable' of '_lsprof.Profiler' objects}  <-
./profiler_tester.py:11(foo)  <-   10.089
  1.243  :1()
:1()  <-



--- End Results for
Commend Out disable and enable


So, when I avoid using enable or disable, the results from everything
look like what we are expecting.


Am I doing something wrong (or excepting something wrong), or is
cProfile doing something wrong?

Thanks,

   -Brian J. Stinar-
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick newbie syntax question

2008-10-20 Thread Larry Bates

Robocop wrote:

oops!   Sorry about that, i should have just copied my code directly.
I actually did specify an int in range:

year = '2008'
month = '09'
limit = '31'
for i in range(1,int(limit)):


The code is currently failing due to the syntax in the filter,
particularly the section "date = year'-'month'-'i"


I believe you want something more like

date = "%s-%s-%s" % (year, month, i)

but then again I can't quite figure out what is is that you are wanting to do
(Note: September doesn't have 31 days).

Where did Table object come from and what does the table.objects.filter method
do and what are the appropriate arguments to that method?  If it was "my" 
method, and I wanted to use it this way, I would think about changing it so that 
it accepted a filtering function and returned only those objects that passed the 
filtering function:


def myFilter(obj):
return (obj.date >= '2008-09-01' and obj.date <= '2008-09-30')

class objects(object):
def __init__(self):
self.objects = []

def filter(filterFunc):
return [x for x in self.objects if filterFunc(x)]


Then

temp = Table.objects.filter(myFilter)

temp is a list of objects you can act on.

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


Re: Python certification

2008-10-20 Thread Terry Reedy

Eric Wertman wrote:

On Mon, Oct 20, 2008 at 3:52 AM, olive <[EMAIL PROTECTED]> wrote:

Certification prooves you're an idiot who needs to spend money to work
for another idiot who doesn't know enough about programming to know if
they hire competent programmers and need an idiot paper to make them
feel better and sleep better at night.


So true !
+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list



While in the current state of affairs I agree completely,  I do think
that IT in general would be a much better field to work in if there
were some industry standard certifications that were required.  More
like the medical and legal fields than the vendor specific ones we see
today from Microsoft, IBM, etc.


Given the way that medical/legal licensing is used to stifle 
competition, prevent innovation, and keep people from earning a living 
delivering simple services that people need at prices they can afford, 
'more like' would have to be done very carefully.


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


Re: Python equivalent for C module

2008-10-20 Thread Bruno Desthuilliers

Ville M. Vainio a écrit :

Bruno Desthuilliers <[EMAIL PROTECTED]> writes:


STDOUT is for *normal* program outputs. Debug informations,
warnings, and all verbosity should go to STDERR.


Actually, stderr is for errors, by convention. It's rather impolite to
dump trivial debug info to stderr, which often "alerts" the user more
than stdout.


If you "dump trivial debug infos" to stdout, you just break anything 
relying on stdout being for *normal* program outputs - IOW, you just can 
chain-pipe programs no more. As far as I'm concerned, it's *way* more 
impolite than "alerting" the user. Also and FWIW, most programs have 
--quiet and --verbose options that let the user specify verbosity.



Also and FWIW, Python has a logging module in it's stdlib. Please
use it instead of any half-backed squared-wheel homegrown solution.


Unfortunately these square-wheeled homegrown solutions are easier to
grok than the standard logging module. It seems to target more
"serious" applications at the cost of feeling a bit too clunky for
quick hack jobs.


If it's for a "quick hack job", you don't even need anything like what 
the OP describe. For anything more serious - anything that requires more 
than one .py script file with a couple functions and a main section -, 
the couple minutes spent setting up a default logger will very quickly 
pay off.


But YMMV, of course...

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


PyGUI - Couple of questions - TextField callbacks and drop down list....

2008-10-20 Thread Hugh
The PyGUI website specified this place as the place for general
discussion about it, so here goes

First off - thanks for something that is so straightforward to get
running on OSX... I've been migrating some relatively straight-forward
scripts-with-GUIs from Linux to OSX, and, while I used FLTK on Linux,
I could not get pyfltk to install on OSX. PyGUI was so
straightforward, though. Made me a very happy bunny.

Fortunately, I wrote most of the pyfltk-specific code in a helper
module, so I got that transferred over to PyGUI easily enough. But
there were a few things that I ran up against

So... A couple of questions for you all...

TextField callbacks... I want to be able to generate a callback when a
textfield is modified. The text field has to only allow a very
specific format in it, and in fltk, I'd just have the callback be a
validation function which would either reset it to the old value or
allow the current one. It doesn't appear to have an "action" member...
Is there anything I can do here? Or should I maybe subclass the
TextField class.

Drop-down lists... There's a menu, but, apparently, no drop-down list
class. For now, I've replaced it with a RadioGroup, which is okay, for
now, as I know that there aren't going to be any more than 3 items,
but I can see situations where I'd really rather have a drop-down list
a part of the GUI, rather than in the menu at the top of the screen.

Anyway, any advice on this would be much appreciated! For the kind of
thing that I'm doing, it's very appreciated that there's something
that's very straightforward to install.


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


Re: Python equivalent for C module

2008-10-20 Thread Ville M. Vainio
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> STDOUT is for *normal* program outputs. Debug informations,
> warnings, and all verbosity should go to STDERR.

Actually, stderr is for errors, by convention. It's rather impolite to
dump trivial debug info to stderr, which often "alerts" the user more
than stdout.

> Also and FWIW, Python has a logging module in it's stdlib. Please
> use it instead of any half-backed squared-wheel homegrown solution.

Unfortunately these square-wheeled homegrown solutions are easier to
grok than the standard logging module. It seems to target more
"serious" applications at the cost of feeling a bit too clunky for
quick hack jobs.
--
http://mail.python.org/mailman/listinfo/python-list


[ANN] Py++ - 1.0

2008-10-20 Thread Roman Yakovenko
Hello!

I'm pleased to announce the 1.0 release of Py++.

What is Py++?
=

Py++ is an object-oriented framework for creating a code generator for
Boost.Python library.

Where is Py++?
==

Site: http://language-binding.net/pyplusplus/pyplusplus.html

Download: http://language-binding.net/pyplusplus/download.html

What's new?


Features


* Algorightm, which defines what virtual functions should be redefined
was improved.

* Exposing "C" code became easier - Py++ is able to generate
``ctypes`` friendly code.

* Support for ``boost::python::make_constructor`` functionality was added.

* Support for unions and unnamed classes was added.

Bug fixes
-

* Indexing Suite V2 - few bugs were fixed.


Contributors:

* Julian Scheid
* Oliver Schweitzer


For a more complete list, with links to documentation, please see the news:
http://language-binding.net/pyplusplus/history/history.html


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


[ANN]pygccxml - 1.0

2008-10-20 Thread Roman Yakovenko
Hello!

I'm pleased to announce the 1.0 release of pygccxml.

What is pygccxml?
===

"...The purpose of the GCC-XML extension is to generate an XML description of a
C++ program from GCC's internal representation. "

-- Introduction to GCC-XML

The purpose of pygccxml is to read a generated file and provide a simple
framework to navigate C++ declarations, using Python classes.

Where is pygccxml?


Site: http://language-binding.net/pygccxml/pygccxml.html

Download: http://language-binding.net/pygccxml/download.html

What's new?
===

Features
-

* Support for ellipsis was added.

* New experimental back-end, based on ``.pdb`` (progam database file),
was added.

* New high-level API wrapper for ``.bsc`` (browse source code file) was added.


Bug fixes
-

* Search algorithm, for template instantiated classes, was improved.


For a more complete list, please see the news:
http://language-binding.net/pygccxml/history/history.html


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


Re: hiding modules in __init__.py

2008-10-20 Thread Chris Rebert
On Sat, Oct 18, 2008 at 12:03 PM, Brendan Miller <[EMAIL PROTECTED]> wrote:
> How would I implement something equivalent to java's package private in
> python?
>
> Say if I have
>
> package/__init__.py
> package/utility_module.py
>
> and utility_module.py is an implementation detail subject to change.
>
> Is there some way to use __init__.py to hide modules that I don't want
> clients to see? Or is the best practice just to name the module you don't
> want clients to use _utility_module and have it private by convention?

Generally the latter on account of Python's "we are all consenting
adults here" philosophy.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

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


Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-20 Thread Bruno Desthuilliers

Eric Wertman a écrit :

I (again) wonder what's the perfect way to store, OS-independent,
filepaths ?


I'm in agreement that perfect probably isn't applicable.  If I were
doing this myself, I might store the information in a tuple:

base = 'some root structure ('/' or 'C')


make it "C:\"


path = ['some','set','of','path','names']
filename = 'somefile.ext'

pathdata = (root,path,filename)

and write a couple of simple functions to reconstruct them based on the os.


like, err, os.path.join ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python equivalent for C module

2008-10-20 Thread Bruno Desthuilliers

Derek Martin a écrit :

I'd like to know if it's possible to code something in Python which
would be equivalent to the following C:

[Assume bool is typedef'd to int, and TRUE and FALSE are #defined to 1
and 0, respectively]

 debug.c 
#include 

bool DEBUG;

void dprint(char *msg)
{
if (DEBUG){
printf("DEBUG: %s", msg);
}
}



This should have been:

fprintf(STDERR, "DEBUG: %s", msg);

STDOUT is for *normal* program outputs. Debug informations, warnings, 
and all verbosity should go to STDERR.




 end of debug.c 

The idea being that all modules of the program would "import" this
code via the header file:

 debug.h 
extern bool DEBUG;
void dprint(char *msg);
 end of debug.h 

I'm specifically trying to avoid having to create a debug object and
pass it around... All modules should have visibility into the state of
whether DEBUG is turned on or off, and be able to use dprint().  Can
Python do this?


Yes, indeed.


I tried creating debug.py as such:

 debug.py 
DEBUG = True
def dprint(msg):
if DEBUG:
print("DEBUG: %s" % msg)
 end 


Same remark : please use sys.stderr



Then in the modules that wanted to use it, I did:

from debug import DEBUG, dprint
But I got some weird behavior.  The imported copy


It's not a copy.


of DEBUG is
read-only;


It's not read-only.


if you update it, the name DEBUG points to a different
object which the other modules can't see.


Indeed : the way you imported it explicitely made it a (module) local name.


 After doing some reading of
the docs, this behavior is explained and understood (though obviously
not what I want).  It just occured to me that I might be able to get
around that by using a setter function in the module itself...


Just use a fully qualified name, so you dont make DEBUG local:

import debug
print debug.DEBUG
debug.DEBUG = True
print debug.DEBUG

Now note that ALL_UPPER names are - by convention - considered 
'constants'. If this is supposed to be altered, don't write it ALL_UPPER.



The other weird behavior was, once I changed the value of DEBUG,
dprint() started to behave oddly.  No matter what I passed as an
argument (and no matter what I set the value of DEBUG to be), it
started printing the exact literal string:

DEBUG: %s

>

whenever it was called.  It was as if the function couldn't see the
parameter msg, which was passed via the call.  Most unexpected, and
definitely undesirable.


I just fail to see how the code you posted could expose such a 
behaviour. Please post actual code.



Also and FWIW, Python has a logging module in it's stdlib. Please use it 
instead of any half-backed squared-wheel homegrown solution.


My 2 cents
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick newbie syntax question

2008-10-20 Thread Robocop
oops!   Sorry about that, i should have just copied my code directly.
I actually did specify an int in range:
> > year = '2008'
> > month = '09'
> > limit = '31'
> > for i in range(1,int(limit)):

The code is currently failing due to the syntax in the filter,
particularly the section "date = year'-'month'-'i"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Abnormal Interpreter Shutdown

2008-10-20 Thread Tim Golden

k3xji wrote:

Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?


"Task Manager" suggests you're using Windows, on which basis
you've got a few options open to you, but fundamentally if
someone pulls the plug on the PC you're not going to spot it.

Look at the SetConsoleCtrlHandler API[1], which is available
in the pywin32 package, and the WMI power events[2]. I don't
know exactly how far each one will go if someone stomps on
your process, but they're definitely worth looking at.

TJG

[1] http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx
[2] http://msdn.microsoft.com/en-us/library/aa394362(VS.85).aspx
--
http://mail.python.org/mailman/listinfo/python-list


Re: quick newbie syntax question

2008-10-20 Thread Chris Rebert
On Mon, Oct 20, 2008 at 12:08 PM, Robocop <[EMAIL PROTECTED]> wrote:
> Is it possible to do something like this syntactically:
>
> year = '2008'
> month = '09'
> limit = '31'
> for i in range(1,limit):

This previous line will fail. range() takes numbers, not strings.
Change 'limit' to an int.

>  temp = Table.objects.filter(date = year'-'month'-'i) up syntax
>  ...do something with temp
> return
>
> I know that the syntax within the filter statement is wrong.  Is it
> even possible to do something like that?  Any help is always
> appreciated.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


quick newbie syntax question

2008-10-20 Thread Robocop
Is it possible to do something like this syntactically:

year = '2008'
month = '09'
limit = '31'
for i in range(1,limit):
  temp = Table.objects.filter(date = year'-'month'-'i)

Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Bruno Desthuilliers

Stef Mientki a écrit :
(snip)
I'm very satisfied with Python, and  must say it's much more beautiful 
language than Delphi, seen over the full width of programming.

Although both languages are Object Oriented,


I think you can lowercase those two last words - it's not a religion, 
you know ?-)


for some (unknown) reason it's 10 times easier to maintain and extend 
libraries in Python than in Delphi.

I WOULD BE MUCH OBLIGED, IF SOMEONE CAN EXPLAIN THAT DIFFERENCE !


Err... Dynamism ?-)

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


Abnormal Interpreter Shutdown

2008-10-20 Thread k3xji
Hi all,

Is there anyway to detect abnormal interpreter shutdown like (closing
from task manager, power shutdown of the PC..etc)?

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


Re: Porting VB apps to Python for Window / Linux use

2008-10-20 Thread Bruno Desthuilliers

Stef Mientki a écrit :

Lawrence D'Oliveiro wrote:

In message <[EMAIL PROTECTED]>, Dotan
Cohen wrote:

 

I often see mention of SMBs that either want to upgrade their Windows
installations, or move to Linux, but cannot because of inhouse VB
apps.



Probably best to leave those legacy VB apps alone and develop new
replacements in a more open, cross-platform language, like Python.
  

Sorry but for GUI design, Python is pre-historic ;-)


Time to show the "don't feed the troll" sign, I guess.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python certification

2008-10-20 Thread Bruno Desthuilliers

Eric Wertman a écrit :

On Mon, Oct 20, 2008 at 3:52 AM, olive <[EMAIL PROTECTED]> wrote:

Certification prooves you're an idiot who needs to spend money to work
for another idiot who doesn't know enough about programming to know if
they hire competent programmers and need an idiot paper to make them
feel better and sleep better at night.


So true !
+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list



While in the current state of affairs I agree completely,  I do think
that IT in general would be a much better field to work in if there
were some industry standard certifications that were required.  More
like the medical and legal fields than the vendor specific ones we see
today from Microsoft, IBM, etc.


I've seen my share of totally incompetent doctors and lawyers...  And 
given current "IT industry standards" (J2EE code monkeys anyone ?), I 
wouldn't bet a single cent on what kind of "certification" they could 
come with.



Eric

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


Re: indentation

2008-10-20 Thread Terry Reedy

Ross Ridge wrote:

Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:

I can't remember having seen any other "standard" so far.


Ross Ridge a écrit :

I've seen various indentation styles used in examples on this newsgroup.


Bruno Desthuilliers  <[EMAIL PROTECTED]> wrote:

I meant: in a real-life project.


So?  There's no reason to assume the styles people use on this newsgroup
don't reflect those they use in "real-life" projects.


Yes there is.  If I type *hypothetical* code for a post, *I* have to 
type all the spaces, and I often use 2 per indent level.  If I type in 
IDLE, *it* adds the spaces (4 per indent) automatically.


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


Re: Can i use this script as a python evaluator?

2008-10-20 Thread Bruno Desthuilliers

Peter Wang a écrit :


#! /bin/sh
python -c "import sys;exec(sys.stdin)"


Emacs has a function `shell-command-on-region', which takes region as
input for the evaluator (script above), and output its result. I have
tried and found it works, is there any problems for this, or any other
better solution for it? Thanks.

If your problem is to eval a region of a python buffer and output the 
result to another buffer, then python-mode.el (the one that comes with 
Python, not the python.el bundled with recent emacs versions) already 
know how to do so.


Else please explain what you're trying to do ?
--
http://mail.python.org/mailman/listinfo/python-list


Wierd problem with python sockets and threading

2008-10-20 Thread thrthr
I have two python "applications" (more like scripts, they're only
about 80 lines each) that are dumbed down http-servers: They accept a
connection, reads everything in the socket untill "\r\n\r\n" and then
responds with "HTTP/1.1 200 OK\r\n\r\nHello World!" and then closes
the connection.

There is one multiplexing single-threaded one and one multithreaded
one, when I use apache bench with something like "ab -n 5000 -c 5
http://localhost/"; everything works fine (about ~1500req/s each) - but
when I raise the concurrency (-c command in apache bench) of the bench
to something that is above the socket.listen(10) (ten in this case)
call in the server socket something strange happens: In the
multiplexing version everything still works fine, pulling ~1400req/s
or there about, but here is my problem:

In the multithreaded version of the code, when the concurrency level
in apache bench is raised above the socket.listen(10) call (say 11 or
100) performance dropps through the floor to something like ~10req/s.
But as long as the concurrency level stays less then or equal to the
socket.listen()-call everything works fine.

I've been staring at this problem for a day now, unable to figure it
out - I don't think I have any long locking times for the connection
queue used between the threads (and I can't see how they could occur
when the concurrency level is raised) and just can't see the reason.

Here's the code: http://paste2.org/p/89679 about 80 lines and it runs
as it is, no external deps. Any ideas/tips are greatly appriciated.

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


testing...(Sorry)

2008-10-20 Thread Sid


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


  1   2   >