Re: Wrapping stdout in a codec

2007-10-22 Thread Marc 'BlackJack' Rintsch
On Mon, 22 Oct 2007 02:41:17 +, JKPeck wrote:

 We want to wrap the stdout device in a codec in order to decode output
 transparently according to a particular code page (which might not be
 the system code page).  However, codec.open requires a filename, and
 stdout may be a tty or otherwise anonymous.  How can we accomplish
 this wrapping?

The `codecs` module has more than just the `codecs.open()` function.  Try
something like this::

  sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread iu2

Hi all,

I've copied the example of RPC usage from the Python's doc.
When the client and server were on the same PC (localhost) (I use
Windows)
it worked ok. But putting the server on a different PC raised the
error:

gaierror: (11001, 'getaddrinfo failed')
The error was raised upion accessing some function of the server,
i.e.,
print s.add_nums(1, 2, 3)  # server registered function

PCs in our organization are accessed by \\name so I used

s = xmlrpclib.Server(r'http://\\pc_name:8000')
I got the same error when I put some non-existing name.
Trying to remove the double-backslash from the PC's name raised the
error:
error: (10061, 'Connection refused')

I'll appreciate your help on this.

Thanks
iu2

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


a question about decorator

2007-10-22 Thread kyo guan
Hi:

please look at this code.

def A():
print 'warp in A'
def why(self, *arg, **kw):
print 'in A'
print self
print arg
print kw
#self(*arg, **kw)

return why

class T(object):
@A()
def test(g, out):
print 'in test', out

it will out put:

warp in A
in A
function test at 0x00BF0C70
()
{}

the function why will be called, why? there is no code to call it.

Kyo.

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


Re: a question about decorator

2007-10-22 Thread Marc 'BlackJack' Rintsch
On Mon, 22 Oct 2007 14:37:36 +0800, kyo guan wrote:

 def A():
   print 'warp in A'
   def why(self, *arg, **kw):
   print 'in A'
   print self
   print arg
   print kw
   #self(*arg, **kw)
   
   return why
   
 class T(object):
   @A()
   def test(g, out):
   print 'in test', out
 
 it will out put:
 
 warp in A
 in A
 function test at 0x00BF0C70
 ()
 {}
 
 the function why will be called, why? there is no code to call it.

There is: [EMAIL PROTECTED]()``.  Parenthesis means *calling* `A`.  Then `A` 
returns
`why` and that is then used as decorator function, i.e. called with
`T.test` as argument.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributed RVS, Darcs, tech love

2007-10-22 Thread Kay Schluehr
On 21 Okt., 19:34, Joachim Durchholz [EMAIL PROTECTED] wrote:

 These are small detractions from a large overall contribution.
 In particular, I find llothars characterization of TeX wrong: it is one
 of the least buggy typesetting programs ever written (not a small feat),
 and it *still* produces output that is as least as good as what other
 programs do, and in fact better than the vast majority.

Acording to the Legend Of The Great Knuth ( derived from personal
confessions ) Knuth used a Clean Room approach. He specified and
verified the entire program before he started hacking it into the
machine. The result is accordingly. What has changed since then is
computer power and easeness of tool usage. One would rather use an
incremental approach today and specify + hack + test the program in
tiny pieces without struggling too much with the programming
equipment. So it also just incrementally improves.

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


Re: Get the instance name from a list by Reflection

2007-10-22 Thread Gabriel Genellina

--- sccs cscs [EMAIL PROTECTED] escribió:

 Thank you, but i believe that i could get all
 variables names that reference an instance: i need
 it for a special debug tool... It seems that
 knowledge exists somewhere into the Python
 interpreter...

Please read first the FAQ item posted previously, and this article:
http://effbot.org/zone/python-objects.htm
Then it should be clear that any object may be referenced by one name,
many names, or no name at all. By example:

py a = [1, 2, 3]
py b = four
py a.append(b)
py a
[1, 2, 3, 'four']
py b = 5
py c = b
py id(b)
10049608
py id(c)
10049608
py b is c
True

In this case there is only one name referencing the list (a), two
names referencing the number 5 (b and c), and no name referencing the
string four, altough it was earlier known as b.
Python is built around namespaces: mappings FROM names TO objects. A
name refers to a single object, but the inverse is not true. You can
invert the relation examining possible namespaces and seeing if the
object is referenced, and by which names. Something like this:

py def invert(obj, namespace):
...   result = []
...   for key,value in namespace.iteritems():
... if value is obj:
...   result.append(key)
...   return result
...
py invert(a, globals())
['a']
py invert(5, globals())
['c', 'b']
py invert(123, globals())
[]
py invert([1, 2, 3, 'four'], globals())
[]

You can pass globals(), locals(), vars(some_object) as the namespace
argument.

--
Gabriel Genellina

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

Hi to every one

2007-10-22 Thread niket mhatre
Hello to every member of this list.
Can any one tell me where to find various python development in to linux
clustering? Just give me some startup info for searching such material. I m
starting to writing some patches in my existed cluster at my college. Just
look for python development held in this area.
Hey i was active member of this from last 2 year, i had just changed my
email address.
-- 
http://mail.python.org/mailman/listinfo/python-list

Fat Loss 4 Idiots

2007-10-22 Thread Alfonso


Learn the 10 Idiot proof rules of dieting and fat loss. Stop using low
carb diets.
Stop using low calorie diets. Stop using low fat diets. Be proud that
you could finally loose those pounds.

http://netsales77.4idiots.hop.clickbank.net

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


Re: Hi to every one

2007-10-22 Thread Amit Khemka
On 10/22/07, niket mhatre [EMAIL PROTECTED] wrote:
 Hello to every member of this list.
 Can any one tell me where to find various python development in to linux
 clustering? Just give me some startup info for searching such material. I m
 starting to writing some patches in my existed cluster at my college. Just
 look for python development held in this area.
 Hey i was active member of this from last 2 year, i had just changed my
 email address.

Have a look at : http://cheeseshop.python.org/pypi?%3Aaction=browse

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


RE: a question about decorator

2007-10-22 Thread Trent Nelson
 def A():
   print 'warp in A'
   def why(self, *arg, **kw):
   print 'in A'
   print self
   print arg
   print kw
   #self(*arg, **kw)
 
   return why
 
 class T(object):
   @A()
   def test(g, out):
   print 'in test', out
 
 it will out put:
 
 warp in A
 in A
 function test at 0x00BF0C70
 ()
 {}
 


 the function why will be called, why? there is no code to call it.

When Python first parses your code, every time it runs into '@A', it
calls A() in order to get the required decorator function.  A needs to
return a function object that accepts a single parameter (the function
we're decorating), and returns another function object that does the
actual work.  So, what you need is an extra level of inline functions:

def A(*args, **kwds):
# You can access the arguments passed to the decorator
# here, e.g. if we were called as @A('foo', timeout=10),
# args[0] would be 'foo', and kwds['timeout'] would be
# 10.  *args and **kwds are also accessible in the actual
# decorator 'body' _fn() below.  This allows you to alter
# the behaviour of the decorator based on the types that
# have been passed to it.
def _decorator(f):
# A decorator must always return a function object that
# takes a single parameter, which will be the function
# we're wrapping when we're actually invoked.  That's
# the purpose of _decorator(f).
def _fn(*_args, **_kwds):
# And here's where we define the actual decorator
# functionality, three levels deep.  *_args and
# **_kwds will represent the parameters passed to
# the actual function we're wrapping; i.e. in our
# case, _args[0] will always be self if we're
# decorating a class's instance method, and _args[1]
# will be either 'foo' or 'bar'.
self = _args[0]
name = self.__class__.__name__
print 'in A (calling class: %s)' % name
# The last responsibility of this method is to
# call the actual function we're wrapping. 
f(*_args, **_kwds)
return _fn
return _decorator

class T(object):
@A()
def test(self, out):
print 'in test T', out

class S(object):
@A()
def test(self, out):
print 'in test S', out

if __name__ == '__main__':
t = T()
t.test('foo')
s = S()
s.test('bar')

% python t.py
in A (calling class: T)
in test T foo
in A (calling class: S)
in test S bar


Regards,

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


package import question

2007-10-22 Thread Phoe6
Hi all,
I have the following directory structure:

wallpaper/
  -main.py
  -ng/
 -- __init__.py
 -- setdesktop.py
  -yb/
 -- __init__.py
 -- setdesktop.py

From main.py, I would like to do:
import ng
import yb
ng.setdesktop.run()
yb.setdesktop.run()

But it is not working! when I import the package, the modules present
inside the package are getting imported.

However, following the python document if I do
import ng.setdesktop
import yb.setdesktop

ng.setdesktop.run()
yb.setdesktop.run()
Works fine.

I would like to use the notation.
import my_package_name
and use the modules inside the package in the dotted module notation.
What should I do the enable such a kind of imports.

Please let me know.

Thank you.
Senthil

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


Re: dynamic invoke

2007-10-22 Thread Jarek Zgoda
Sushant napisał(a):

 getattr seems to be converting string into function pointer and I am just 
 saying that string cannot be used as a function pointer in Python as may be 
 in PHP.

It seems, but it does not. Getattr performs lookup on object's
attributes dict, it does not convert anything. The abstraction of
function pointer is also wrong here, it's a reference to an object
(any object, not just function). The result might seems similar, but
works quite differently.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

We read Knuth so you don't have to. (Tim Peters)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ACM SIGAPL / APL2007 Conference / Montreal / one week away

2007-10-22 Thread Gosi
On Oct 21, 10:35 am, Wade Ward [EMAIL PROTECTED] wrote:
 Gosi [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]



  On Oct 20, 10:46 pm, rbe [EMAIL PROTECTED] wrote:
  On Oct 15, 5:22 am, Mike Kent [EMAIL PROTECTED] wrote:

   Conference page
   // with links to program details //
   (updated Friday 10/12)

  http://www.sigapl.org/apl2007.html...

  At APL2007, I'll be announcing the release of the APEX APL compiler,
  version 0.0.0, under GPL Version 2.
  If you can't wait until then, you can download it for Dyalog Linux
  atwww.snakeisland.com.

  Bob

  Congratulations on your compiler.

  I looked through your pages and came across this

  [This article originally appeared in the ACM SIGAPL Quote Quad, vol.
  21, no.1, September 1990.]

  The APL character set has contributed, more than any other facet of
  the language, to its lack of acceptance in the computing community at
  large. The character set is a metaproblem -- not a problem in and of
  itself, but a creator of other recurring problems of hardware,
  software, ergonomics, and psychology. The adoption of new, ASCII-base
  dialects of APL, such as J, is suggested as one solution to the
  character set problem. 

  This is also the reason for why I will not be downloading your new
  compiler until there will be a J version of it, something I hope will
  be coming soon.

  I can not use the APL character set at all.
  It is too mixed up with my national characters.

 witch ones?
 --
 wade ward
 [EMAIL PROTECTED]
 Der Katze tritt die Treppe hoch;  Der Kater tritt sie krumm.%
 % De Teufel geit um; er bringt de menschen allet dumm.
 schau, schau

   4 10$a.i.'áðéíóúýþæöÁÐÉÍÓÚÝÞÆÖ'
195 161 195 176 195 169 195 173 195 179
195 186 195 189 195 190 195 166 195 182
195 129 195 144 195 137 195 141 195 147
195 154 195 157 195 158 195 134 195 150

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

Re: Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread Diez B. Roggisch
iu2 wrote:

 
 Hi all,
 
 I've copied the example of RPC usage from the Python's doc.
 When the client and server were on the same PC (localhost) (I use
 Windows)
 it worked ok. But putting the server on a different PC raised the
 error:
 
 gaierror: (11001, 'getaddrinfo failed')
 The error was raised upion accessing some function of the server,
 i.e.,
 print s.add_nums(1, 2, 3)  # server registered function
 
 PCs in our organization are accessed by \\name so I used
 
 s = xmlrpclib.Server(r'http://\\pc_name:8000')
 I got the same error when I put some non-existing name.
 Trying to remove the double-backslash from the PC's name raised the
 error:
 error: (10061, 'Connection refused')
 
 I'll appreciate your help on this.

Maybe using the IP-address helps?

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


Re: package import question

2007-10-22 Thread Diez B. Roggisch
Phoe6 wrote:

 Hi all,
 I have the following directory structure:
 
 wallpaper/
   -main.py
   -ng/
  -- __init__.py
  -- setdesktop.py
   -yb/
  -- __init__.py
  -- setdesktop.py
 
From main.py, I would like to do:
 import ng
 import yb
 ng.setdesktop.run()
 yb.setdesktop.run()
 
 But it is not working! when I import the package, the modules present
 inside the package are getting imported.
 
 However, following the python document if I do
 import ng.setdesktop
 import yb.setdesktop
 
 ng.setdesktop.run()
 yb.setdesktop.run()
 Works fine.
 
 I would like to use the notation.
 import my_package_name
 and use the modules inside the package in the dotted module notation.
 What should I do the enable such a kind of imports.
 
 Please let me know.

You need to import the setdesktop-module in the respective __init__.py-files
to make them part of the names known in there.

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


Re: package import question

2007-10-22 Thread Peter Otten
Phoe6 wrote:

 Hi all,
 I have the following directory structure:
 
 wallpaper/
   -main.py
   -ng/
  -- __init__.py
  -- setdesktop.py
   -yb/
  -- __init__.py
  -- setdesktop.py
 
From main.py, I would like to do:
 import ng
 import yb
 ng.setdesktop.run()
 yb.setdesktop.run()
 
 But it is not working! when I import the package, the modules present
 inside the package are getting imported.
 
 However, following the python document if I do
 import ng.setdesktop
 import yb.setdesktop
 
 ng.setdesktop.run()
 yb.setdesktop.run()
 Works fine.
 
 I would like to use the notation.
 import my_package_name
 and use the modules inside the package in the dotted module notation.
 What should I do the enable such a kind of imports.

Put the line

from . import setdesktop

into both __init__.py files. Importing the package will then trigger the
submodule to be imported.

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


Re: using request variable in python web program

2007-10-22 Thread sami
 See the library reference for information on how to get the value of
 form/request parameters from the CGI environment:

 http://docs.python.org/lib/node561.html

 Paul

Thanks again Paul - now I can see that the request object is a
string of name/value pairs that occurs after a ? in a url e.g.
url.com/index.cgi?name=samilang=python - is that correct? Googling
for this information is useless since the word request is so common
on the www

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


python 2.5 scripting in vim on windows: subprocess problem

2007-10-22 Thread Dmitry Teslenko
Hello!
I'm using subprocess.Popen in python script in vim.
It called this way:
def some_func():
p = subprocess.Popen( command , stdout = subprocess.PIPE, 
stderr =
subprocess.STDOUT)
while True:
s = p.stdout.readline()
if not s:
break
self.__output( '... %s' % s )
return p.wait()

It filters command's output and re-ouputs it in stdout.
Being called from console, it works fine.
Being called from vim with :python some_func() it says:
file ...subprocess.py, line 586 in __init__
...
file ...subprocess.py, line 699, in _get_handles
...
file ...subprocess.py, line 744 in _make_inheritable
DUPLICATE_SAME_ACCESS
WindowsError: [Error 6]
-- 
http://mail.python.org/mailman/listinfo/python-list


calling a function from string

2007-10-22 Thread james_027
hi,

i have a function that I could like to call, but to make it more
dynamic I am constructing a string first that could equivalent to the
name of the function I wish to call. how could I do that? the string
could might include name of the module.

for example

a_string = 'datetime.' + 'today()'

how could I call a_string as function?

Thanks
james

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


Need help parsing with pyparsing...

2007-10-22 Thread Just Another Victim of the Ambient Morality
I'm trying to parse with pyparsing but the grammar I'm using is somewhat 
unorthodox.  I need to be able to parse something like the following:

UPPER CASE WORDS And Title Like Words

...into two sentences:

UPPER CASE WORDS
And Title Like Words

I'm finding this surprisingly hard to do.  The problem is that pyparsing 
implicitly assumes whitespace are ignorable characters and is (perhaps 
necessarily) greedy with its term matching.  All attempts to do the 
described parsing either fails to parse or incorrectly parses so:

UPPER CASE WORDS A
nd Title Like Words

Frankly, I'm stuck.  I don't know how to parse this grammar with 
pyparsing.
Does anyone know how to accomplish what I'm trying to do?
Thank you...



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


Re: Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread iu2
On Oct 22, 10:21 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 iu2 wrote:

  Hi all,

  I've copied the example of RPC usage from the Python's doc.
  When the client and server were on the same PC (localhost) (I use
  Windows)
  it worked ok. But putting the server on a different PC raised the
  error:

  gaierror: (11001, 'getaddrinfo failed')
  The error was raised upion accessing some function of the server,
  i.e.,
  print s.add_nums(1, 2, 3)  # server registered function

  PCs in our organization are accessed by \\name so I used

  s = xmlrpclib.Server(r'http://\\pc_name:8000')
  I got the same error when I put some non-existing name.
  Trying to remove the double-backslash from the PC's name raised the
  error:
  error: (10061, 'Connection refused')

  I'll appreciate your help on this.

 Maybe using the IP-address helps?

 Diez- Hide quoted text -

 - Show quoted text -

No, that doesn't help either.
May be I don't use it right.
I tried http://1.2.3.4:8000;
and
rhttp://\\1.2.3.4:8000;

with no success.

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


Re: package import question

2007-10-22 Thread Phoe6
On Oct 22, 1:24 pm, Peter Otten [EMAIL PROTECTED] wrote:
 Phoe6 wrote:
  Hi all,
  I have the following directory structure:

  wallpaper/
-main.py
-ng/
   -- __init__.py
   -- setdesktop.py
-yb/
   -- __init__.py
   -- setdesktop.py

 From main.py, I would like to do:
  import ng
  import yb
  ng.setdesktop.run()
  yb.setdesktop.run()

  But it is not working! when I import the package, the modules present
  inside the package are getting imported.

  However, following the python document if I do
  import ng.setdesktop
  import yb.setdesktop

  ng.setdesktop.run()
  yb.setdesktop.run()
  Works fine.

  I would like to use the notation.
  import my_package_name
  and use the modules inside the package in the dotted module notation.
  What should I do the enable such a kind of imports.

 Put the line

 from . import setdesktop

 into both __init__.py files. Importing the package will then trigger the
 submodule to be imported.


Thanks a lot for your replies. I had a thought that I can do this way,
but as Python Documentation did not mention it, I was 'thinking' that
submodules will automatically get imported and __init__.py usually
blank.

Thanks again,
Senthil


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


Re: calling a function from string

2007-10-22 Thread Francesco Guerrieri
On 10/22/07, james_027 [EMAIL PROTECTED] wrote:
 hi,

 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.

 for example

 a_string = 'datetime.' + 'today()'

 how could I call a_string as function?

you could use getattr:

function_name = 'time'  # this is a string
module_name = 'time'   # this is a string, too

my_function = getattr(module_name, function_name) # this is the
function object,
# equivalent to my_function = time.time
my_function() # This is the function call, equivalent to time.time()

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


python with braces pre-processor

2007-10-22 Thread Paul Brauner
Hi, I'm working on a project that outputs several languages including 
(hopefully) python. My problem is that the generic backend architecture 
has not been designed to output correctly indented code, and that would 
be helpful if there were somewhere a python pre-processor that would take 
python with braces as an input and output regular python code. I thought 
that it must exists because everyone generating python code will 
encounter more or less the same problem, but I didn't find any 'official' 
thing on the subject. I mean that I wonder if there is a special mode of 
the offcial parser that does such a thing. If not, do you know the most 
reliable project that would do this ?

Thanks a lot.

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


Re: python with braces pre-processor

2007-10-22 Thread Ant
On Oct 22, 10:44 am, Paul Brauner [EMAIL PROTECTED] wrote:
 Hi, I'm working on a project that outputs several languages including
 (hopefully) python. My problem is that the generic backend architecture
 has not been designed to output correctly indented code, and that would
 be helpful if there were somewhere a python pre-processor that would take
 python with braces as an input and output regular python code. I thought
 that it must exists because everyone generating python code will
 encounter more or less the same problem, but I didn't find any 'official'

There's a tool in the standard Python distribution that processes code
with commented end statements. eg:

def my_funct():
pass
# end


or similar, and indents it correctly. This may be a possibility for
your purposes.



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


Problems in using wxPython in a multithreaded context‏

2007-10-22 Thread mec2paris

For my C application, I use many interpreters (withh the fonction
Py_NewInterpreter()). For my needs, I create many GUI with wxPython
and I have problems. Here is My C Code:

{
PyEval_InitThreads();
Py_Initialize();
PyImport_ImportModule(myModule);//it creates a wxApp and a GUI
..


Py_NewInterpreter();
PyImport_ImportModule(anotherModule);//it should create a new
wxApp and a new GUI

Unfortunately this code does not work. In fact, My C application which
use many interpreters is seen by wxPython as a single application, and
as wxPython is thread safe, it is not possible to create a second
App.
I have to use many interpreters to separate variables and to avoid
links between modules.

What could I do to create many GUI in different interpreters (each GUI
have to be in a separate environment)???

Thanks.

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


Re: python with braces pre-processor

2007-10-22 Thread Paul Brauner
I'll look at that. Thanks a lot !
-- 
http://mail.python.org/mailman/listinfo/python-list


Check File Change Every 10 Seconds

2007-10-22 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I've got a requirement to check a file for a change every 10 seconds or so,
and if the file has been modified since the last time I parsed its content
into the application then I need to parse it in again. However, I need this
process to not interrupt the rest of my application flow.

 

What is the best way to handle this? Is there some form of file watcher
module for python which can watch the file for me and then parse any changes
into the application memory? Or should I be spawning and unjoined thread
which contains and infinite loop which checks a date/time the file was
modified against an internal date/time variable for when the application
last parsed the file into memory?

 

I'll be interested to hear your ideas guys,

 

Thanks,

 

Rob

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

Re: python with braces pre-processor

2007-10-22 Thread Marc 'BlackJack' Rintsch
On Mon, 22 Oct 2007 09:44:27 +, Paul Brauner wrote:

 Hi, I'm working on a project that outputs several languages including 
 (hopefully) python. My problem is that the generic backend architecture 
 has not been designed to output correctly indented code, and that would 
 be helpful if there were somewhere a python pre-processor that would take 
 python with braces as an input and output regular python code. I thought 
 that it must exists because everyone generating python code will 
 encounter more or less the same problem, but I didn't find any 'official' 
 thing on the subject.

Maybe (almost) nobody feels the need to generate Python source code.  The
language is so dynamic that there are almost always ways to avoid
source code generation.

Maybe you can generate a token stream and use `tokenize.untokenize()` to
generate the source code!?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting URLs

2007-10-22 Thread Paul Boddie
On 22 Okt, 03:53, Tim Chase [EMAIL PROTECTED] wrote:

 This seems to be intentional, rather than a bug.  In my
 python2.4/urlparse.py file, there's a uses_netloc list which
 clearly does not have 'mailto' in it.  I can't give an
 explanation/justification for it, but it seems to me (IMHO) that
 there is a netloc involved in a mail address.

As is often the case with the standard library, there are various open
issues around the functionality:

http://bugs.python.org/issue?%40filter=statusstatus=-1%2C1%2C3%40search_text=RFC+3986

This proposed module (in the above search results) attempts to
implement RFC 3986:

http://bugs.python.org/issue1500504

I'm not sure whether itools.uri goes as far as you might like:

http://download.ikaaro.org/doc/itools/chapter--uri.html

Either way, after listening to Ron Stephens' most recent Python411
podcast, where he mentions that it's apparently up to the community to
fix the standard library (according to GvR and the core developers),
perhaps there's some demand for a Python 300 which just cleans up
the standard library in a potentially (but not necessarily) backwards-
incompatible fashion.

Paul

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


if..else stmt

2007-10-22 Thread bigden007
Hi,
I have a if..else statement in my script. The statements all execute
fine, but the problem is , even if the IF part of the statement is
true, the else part executes as well. The verion of pythin i use 2.5
Any help is appreciatiated.

Regards

Big Den.

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


RE: calling a function from string

2007-10-22 Thread Trent Nelson
 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.
 
 for example
 
 a_string = 'datetime.' + 'today()'
 
 how could I call a_string as function?

Use 'eval' in one of the following fashions:

a_string_1 = 'datetime.' + 'today'
a_string_2 = 'datetime.' + 'today()'

eval(a_string_1)()
eval(a_string_2)


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


Re: Dealing with funny characters

2007-10-22 Thread Diez B. Roggisch
 I doubt that indexing has anything to do with it whatsoever.
 
  Of course it does.  ORDER BY, LIKE, TRIM, and other SQL expressions
  that
 do more than an equal comparison need to know the actual data
 representation. If you were to convert to UTF-8 or UCS-2 in the Python
 program and send the resulting byte string to MySQL, with MySQL thinking
 it was storing
 ASCII or a BLOB, many SQL functions won't work right.  A database is
 not a file system; a database looks at the data.

Garbage in, garbage out. But putting correctly encoded data into it won't
make any troubles, so You don't want to convert data to UTF-8 before
putting it in a
database; the database indexing won't work. is utter nonsense. 

 You confuse unicode with utf-8 here.
 ... pontification deleted

Pontication in contrast to what - your highly informative posts like this? 
http://mail.python.org/pipermail/python-list/2007-October/461375.html

I'm sure there are other daily routines your audience here can't wait to be
informed of in regular intervals.

Just because you write nonsense like 

    First, tell MySQL, before you create your MySQL tables, that the tables
are
to be stored in Unicode:

ALTER database yourdatabasename DEFAULT CHARACTER SET utf8;
 

confusing unicode with an encoding of it doesn't make me pontificate. 

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

Re: using request variable in python web program

2007-10-22 Thread Paul Boddie
On 22 Okt, 10:34, sami [EMAIL PROTECTED] wrote:
  See the library reference for information on how to get the value of
  form/request parameters from the CGI environment:

 http://docs.python.org/lib/node561.html

  Paul

 Thanks again Paul - now I can see that the request object is a
 string of name/value pairs that occurs after a ? in a url e.g.
 url.com/index.cgi?name=samilang=python - is that correct? Googling
 for this information is useless since the word request is so common
 on the www

The string after ? in a URL is actually the query string and is
typically exposed as the QUERY_STRING environment variable in CGI. See
here for more specific details:

http://www.w3.org/CGI/
http://cgi-spec.golux.com/

What the cgi module provides is some conveniences for automatically
decoding the query string - perhaps not *so* difficult, you might
think, even taking the decoding of encoded values into account (such
as things like %20 that you find in URLs) - but the cgi module also
provides facilities to decode request parameters that are supplied in
the body of a request (such as those provided in POST requests), and
that can be a more difficult exercise.

Paul

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


Re: if..else stmt

2007-10-22 Thread Erik Max Francis
bigden007 wrote:

 I have a if..else statement in my script. The statements all execute
 fine, but the problem is , even if the IF part of the statement is
 true, the else part executes as well. The verion of pythin i use 2.5
 Any help is appreciatiated.

You're doing something wrong.  Without seeing actual code, it's 
impossible to say what.

-- 
Erik Max Francis  [EMAIL PROTECTED]  http://www.alcyone.com/max/
  San Jose, CA, USA  37 20 N 121 53 W  AIM, Y!M erikmaxfrancis
   So little time, so little to do.
-- Oscar Levant
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get the clsid of Internet Explorer_Server?

2007-10-22 Thread 尹祥龙
Thanks for any help
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread J. Cliff Dyer
iu2 wrote:
 Hi all,

 I've copied the example of RPC usage from the Python's doc.
 When the client and server were on the same PC (localhost) (I use
 Windows)
 it worked ok. But putting the server on a different PC raised the
 error:

 gaierror: (11001, 'getaddrinfo failed')
 The error was raised upion accessing some function of the server,
 i.e.,
 print s.add_nums(1, 2, 3)  # server registered function

 PCs in our organization are accessed by \\name so I used

 s = xmlrpclib.Server(r'http://\\pc_name:8000')
 I got the same error when I put some non-existing name.
 Trying to remove the double-backslash from the PC's name raised the
 error:
 error: (10061, 'Connection refused')

 I'll appreciate your help on this.

 Thanks
 iu2

   

Don't use the \\.  That's a windows networking convention, and it does
not apply if you are using http.  Your error messages tell you this. 
The first one (r'http://\\pc_name:8000') could not resolve the address. 
The second one reached the server just fine, but the server rejected the
client's request.  So now the issue is why is the request being
rejected?  Did you check your firewall to see if it is blocking access
to port 8000 on the ethernet adapter?

Cheers,
Cliff


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


Re: calling a function from string

2007-10-22 Thread Jarek Zgoda
Trent Nelson napisał(a):
 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.

 for example

 a_string = 'datetime.' + 'today()'

 how could I call a_string as function?
 
 Use 'eval' in one of the following fashions:
 
 a_string_1 = 'datetime.' + 'today'
 a_string_2 = 'datetime.' + 'today()'
 
 eval(a_string_1)()
 eval(a_string_2)

Do not use eval(). Not only it's deprecated, it's also unsafe.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

We read Knuth so you don't have to. (Tim Peters)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread Diez B. Roggisch
 Maybe using the IP-address helps?

 Diez- Hide quoted text -

 - Show quoted text -
 
 No, that doesn't help either.
 May be I don't use it right.
 I tried http://1.2.3.4:8000;
 and
 rhttp://\\1.2.3.4:8000;
 
 with no success.

The former should work. The latter is Windows-name-style and has nothing to
do here.

I'm not a windows-user, but there should be ways to determine which program
listens to which port on a machine.

And a common problem is that servers listen on 127.0.0.1 instead of the
ethernet interface. 

Try putting the server's IP as argument to the listening XMLRPC-server, and
check with the windows-netstat-equivalent if it works out.

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


Re: if..else stmt

2007-10-22 Thread J. Cliff Dyer
Your else statement is incorrectly indented.  The interpreter treats it
as part of the for-loop construct inside the if statement rather than as
part of the if statement itself.  See the recent thread about for-else
constructs for more details.

If your problem is not obvious yet, make sure you aren't mixing spaces
and tabs.

:)

bigden007 wrote:
 Hi,
 I have a if..else statement in my script. The statements all execute
 fine, but the problem is , even if the IF part of the statement is
 true, the else part executes as well. The verion of pythin i use 2.5
 Any help is appreciatiated.

 Regards

 Big Den.

   

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


Re: if..else stmt

2007-10-22 Thread Sander Smits

Works as expected here, the 'else' part is not executed if the 'if' part is
true.

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type help, copyright, credits or license for more information.
 def tr():   
... print tr func
... return Sander
... 
 def fa():
... print fa func
... return Harry
... 
 s = yes if tr() == Sander else fa()
tr func
 s
'yes'
 s = yes if tr() == San else fa()
tr func
fa func
 s
'Harry'
 

Can you show your code?


bigden007 wrote:
 
 Hi,
 I have a if..else statement in my script. The statements all execute
 fine, but the problem is , even if the IF part of the statement is
 true, the else part executes as well. The verion of pythin i use 2.5
 Any help is appreciatiated.
 
 Regards
 
 Big Den.
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 
 

-- 
View this message in context: 
http://www.nabble.com/if..else-stmt-tf4670106.html#a13340589
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: if..else stmt

2007-10-22 Thread J. Cliff Dyer
bigden007 wrote:
 Hi,
 I have a if..else statement in my script. The statements all execute
 fine, but the problem is , even if the IF part of the statement is
 true, the else part executes as well. The verion of pythin i use 2.5
 Any help is appreciatiated.

 Regards

 Big Den.

   
Your else statement is incorrectly indented.  The interpreter treats it
as part of the for-loop construct inside the if statement rather than as
part of the if statement itself.  See the recent thread about for-else
constructs for more details.

If your problem is not obvious yet, make sure you aren't mixing spaces
and tabs.

:)

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


Re: dynamic invoke

2007-10-22 Thread Dustan
On Oct 19, 6:34 am, Nils [EMAIL PROTECTED] wrote:
  Use apply(): http://docs.python.org/lib/non-essential-built-in-funcs.html

Did you actually read the title of the page you linked to (Non-
essential Built-in Functions)?

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


Re: calling a function from string

2007-10-22 Thread Dustan
On Oct 22, 4:41 am, Francesco Guerrieri [EMAIL PROTECTED]
wrote:
 On 10/22/07, james_027 [EMAIL PROTECTED] wrote:

  hi,

  i have a function that I could like to call, but to make it more
  dynamic I am constructing a string first that could equivalent to the
  name of the function I wish to call. how could I do that? the string
  could might include name of the module.

  for example

  a_string = 'datetime.' + 'today()'

  how could I call a_string as function?

 you could use getattr:

 function_name = 'time'  # this is a string
 module_name = 'time'   # this is a string, too

 my_function = getattr(module_name, function_name) # this is the
 function object,
 # equivalent to my_function = time.time


Not quite.


 function_name = 'time'  # this is a string
 module_name = 'time'   # this is a string, too
 my_function = getattr(module_name, function_name)
Traceback (most recent call last):
  File pyshell#3, line 1, in module
my_function = getattr(module_name, function_name)
AttributeError: 'str' object has no attribute 'time'


It's actually equivalent to:


 time.time
Traceback (most recent call last):
  File pyshell#0, line 1, in module
time.time
AttributeError: 'str' object has no attribute 'time'


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


Re: Error when python script run as cgi script

2007-10-22 Thread sophie_newbie
On Oct 21, 7:28 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 On Sun, 21 Oct 2007 09:50:54 -0700, sophie_newbie
 [EMAIL PROTECTED] declaimed the following in comp.lang.python:

  Hi, I'm running a python script which if I run from the command line
  as root runs fine. But if I run it through the web-browser as a cgi
  script gives the following error Error in X11: unable to start device
  PNG.

  Now I should say that this python script is calling fucntions in R (a
  scripting languange used in statistics) using the python module RPy,
  so this I dunno if this is entirely a Python question, because as far
  as I can see the error is being thrown by R. But then as I say, when
  the script is run by the root user from the command line everything
  goes off without a hitch.

 Ah, but does it run if you boot into a NON-graphical command shell
 mode...

 That error message looks suspiciously like something is trying to
 open a graphical display window... A web-server likely does not have any
 graphical environment.
 --
 WulfraedDennis Lee Bieber   KD6MOG
 [EMAIL PROTECTED]  [EMAIL PROTECTED]
 HTTP://wlfraed.home.netcom.com/
 (Bestiaria Support Staff:   [EMAIL PROTECTED])
 HTTP://www.bestiaria.com/

Ya thanks looks like you're actually right. The strange thing is that
the program, when run from a graphical command line, doesn't actually
open any display window. Although the code doesn't run when executed
as a webserver, most likely, as you pointed out, because there is no
graphical environment. I wonder if there any way I can somehow enable
a graphical environment for the webserver, or do I have to re-write
the underlying code?

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


Re: calling a function from string

2007-10-22 Thread Dustan
On Oct 22, 5:46 am, Jarek Zgoda [EMAIL PROTECTED] wrote:
 Do not use eval(). Not only it's deprecated, it's also unsafe.

I don't think it's deprecated; it doesn't say so:
http://docs.python.org/lib/built-in-funcs.html#l2h-25

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


Re: if..else stmt

2007-10-22 Thread Bruno Desthuilliers
bigden007 a écrit :
 Hi,
 I have a if..else statement in my script. The statements all execute
 fine, but the problem is , even if the IF part of the statement is
 true, the else part executes as well. The verion of pythin i use 2.5
 Any help is appreciatiated.

My crystal ball tells me the problem is on line 42 !-)


And if you expect any useful help, please post the minimal working code 
reproducing the problem (chances are you'll find the problem by yourself 
doing so...).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling a function from string

2007-10-22 Thread Bruno Desthuilliers
james_027 a écrit :
 hi,
 
 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.
 
 for example
 
 a_string = 'datetime.' + 'today()'
 
 how could I call a_string as function?

The obvious answer is to use eval or exec, but it's 99.99 times out of 
100 the wrong solution.

Better solutions usually rely on Python's introspection features - 
mostly globals(), locals(), sys.modules, and of course getattr().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python with braces pre-processor

2007-10-22 Thread Ant
On Oct 22, 10:58 am, Paul Brauner [EMAIL PROTECTED] wrote:
 I'll look at that. Thanks a lot !

I've just had a look, it's the pindent.py script in Tools/Scripts (at
least it is on Windows). It takes code of the following form:

def foobar(a, b):
   if a == b:
   a = a+1
   elif a  b:
   b = b-1
   if b  a: a = a-1
   # end if
   else:
   print 'oops!'
   # end if
# end def foobar

The help in the script looks pretty good.

--
Ant...

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


Re: calling a function from string

2007-10-22 Thread Bruno Desthuilliers
Jarek Zgoda a écrit :
 Trent Nelson napisał(a):
 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.

 for example

 a_string = 'datetime.' + 'today()'

 how could I call a_string as function?
 Use 'eval' in one of the following fashions:

 a_string_1 = 'datetime.' + 'today'
 a_string_2 = 'datetime.' + 'today()'

 eval(a_string_1)()
 eval(a_string_2)
 
 Do not use eval(). Not only it's deprecated,

Chapter and verse ???

 it's also unsafe.

it's *potentially* unsafe. As long as the eval'd code comes from a 
trusted source, there should be no security problem.

I agree that eval is usually not the solution, but mainly because Python 
has far better (wrt/ readability and maintainance) options for this kind 
of things.

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


Re: a question about decorator

2007-10-22 Thread Bruno Desthuilliers
Trent Nelson a écrit :
(snip (rather convoluted) decorator example)

 When Python first parses your code, every time it runs into '@A', it
 calls A() in order to get the required decorator function.

It's not happening at parsing time, but when the (decorated) def 
statement is executed - that is, *usually* (but not necessarily), when 
the module/script is loaded in the interpreter (either as a the main 
program or thru import).

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


Re: python with braces pre-processor

2007-10-22 Thread Jean-Paul Calderone
On Mon, 22 Oct 2007 09:44:27 + (UTC), Paul Brauner [EMAIL PROTECTED] 
wrote:
 [snip]
 I thought that it must exists because everyone generating python code will
encounter more or less the same problem, but I didn't find any 'official'
thing on the subject.

I expect many projects which emit Python code actually emit Python code.
Getting the indentation right isn't much of a chore at all.  If you need
some help to get it right, maybe this will get you going in the right
direction:

  http://twistedmatrix.com/trac/browser/sandbox/exarkun/ast/ast_pp.py

It's just some throw-away code, but it at least manages to indent code
properly.

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


Iteration for Factorials

2007-10-22 Thread Py-Fun
I'm stuck trying to write a function that generates a factorial of a
number using iteration and not recursion.  Any simple ideas would be
appreciated.

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


Re: Iteration for Factorials

2007-10-22 Thread Diez B. Roggisch
Py-Fun wrote:

 I'm stuck trying to write a function that generates a factorial of a
 number using iteration and not recursion.  Any simple ideas would be
 appreciated.

Show us your attempts, and we might suggest a fix. Because otherwise this
sounds suspiciously like homework.

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


Re: CGI Server that supports redirects

2007-10-22 Thread John J. Lee
Thomas Guettler [EMAIL PROTECTED] writes:

 Hi,

 CGIHTTPServer does not support redirects[1]

 Is there an other python-only way to get a web server
 running wich can execute python code?

 Since I already use flup[2]. I think there is not much
 missing to get it serving as http server.

 Has anyone hints?

twisted.web2 .  I found it easier to get it to do the simple stuff I
needed than cherrypy.

Simple example that shows how to do static files, redirects  CGI in a
standalone script:

http://codespeak.net/svn/wwwsearch/mechanize/trunk/test-tools/twisted-localserver.py


Of course you can do dynamic but non-CGI stuff too, examples here
(these examples illustrate running under twistd rather than
standalone):

http://twistedmatrix.com/projects/web2/documentation/howto/intro.xhtml


Other twisted web stuff:

http://twistedmatrix.com/projects/web2/documentation/howto/

http://twistedmatrix.com/trac/wiki/WebDevelopmentWithTwisted


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


Re: Failure to connect in SimpleXMLRPCServer/xmlrpclib

2007-10-22 Thread iu2
On Oct 22, 12:47 pm, J. Cliff Dyer [EMAIL PROTECTED] wrote:
 iu2 wrote:
  Hi all,

  I've copied the example of RPC usage from the Python's doc.
  When the client and server were on the same PC (localhost) (I use
  Windows)
  it worked ok. But putting the server on a different PC raised the
  error:

  gaierror: (11001, 'getaddrinfo failed')
  The error was raised upion accessing some function of the server,
  i.e.,
  print s.add_nums(1, 2, 3)  # server registered function

  PCs in our organization are accessed by \\name so I used

  s = xmlrpclib.Server(r'http://\\pc_name:8000')
  I got the same error when I put some non-existing name.
  Trying to remove the double-backslash from the PC's name raised the
  error:
  error: (10061, 'Connection refused')

  I'll appreciate your help on this.

  Thanks
  iu2

 Don't use the \\.  That's a windows networking convention, and it does
 not apply if you are using http.  Your error messages tell you this.
 The first one (r'http://\\pc_name:8000') could not resolve the address.
 The second one reached the server just fine, but the server rejected the
 client's request.  So now the issue is why is the request being
 rejected?  Did you check your firewall to see if it is blocking access
 to port 8000 on the ethernet adapter?

 Cheers,
 Cliff- Hide quoted text -

 - Show quoted text -

Cliff and Diez, thanks. That helped. The server indeed was listening
on 127.0.0.1. I changed the hostname from localhost to
socket.gethostname() and it worked!

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


Re: python with braces pre-processor

2007-10-22 Thread Paul Brauner
Le Mon, 22 Oct 2007 05:00:02 -0700, Ant a écrit :

 On Oct 22, 10:58 am, Paul Brauner [EMAIL PROTECTED] wrote:
 I'll look at that. Thanks a lot !
 
 I've just had a look, it's the pindent.py script in Tools/Scripts (at
 least it is on Windows). It takes code of the following form:
 
 def foobar(a, b):
if a == b:
a = a+1
elif a  b:
b = b-1
if b  a: a = a-1
# end if
else:
print 'oops!'
# end if
 # end def foobar
 
 The help in the script looks pretty good.

Thanks,

actually i'm using it right now as a backend and it's helpful.

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

Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
On 22 Oct, 13:28, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Py-Fun wrote:
  I'm stuck trying to write a function that generates a factorial of a
  number using iteration and not recursion.  Any simple ideas would be
  appreciated.

 Show us your attempts, and we might suggest a fix. Because otherwise this
 sounds suspiciously like homework.

 Diez

Here is my futile attempt.  Be careful with this though, I just ran
something similar and it was never ending...

def itforfact(n):
while n100:
print n
n+1
n = input(Please enter a number below 100)

itforfact(n)

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


Re: I can't get minimock and nosetests to play nice

2007-10-22 Thread John J. Lee
Matthew Wilson [EMAIL PROTECTED] writes:

 I'm curious if anyone has ever tried using nosetests along with
 minimock.

This has nothing to do with nose.


 I'm trying to get the two to play nice and not making progress.  I
 also wonder if I'm using minimock incorrectly.

 Here's the code I want to test, saved in a file dtfun.py.

 class Chicken(object):
I am a chicken.
def x(self): return 1
def z(self): return 1

 def g():


Verify that we call method x on an instance of the Chicken class.

# First set up the mockery.
 from minimock import Mock
 Chicken = Mock('Chicken')
 Chicken.mock_returns = Mock('instance_of_chicken')

This does not rebind the module global name Chicken.


Now this stuff is the real test.
 g()
Called Chicken()
Called instance_of_chicken.x()

g() returns None, and prints nothing.

[...]
 File /home/matt/svn-checkouts/scratch/python/dtfun/dtfun.py, line
 22, in dtfun.g
 Failed example:
g()
 Expected:
Called Chicken()
Called instance_of_chicken.x()
 Got nothing

... because g() returns None, and prints nothing.

[...]
 Any ideas?

Read the Python tutorial, write some Python code and some doctests
without using minimock.  Google about Python scoping rules.  Read the
doctest docs about the global namespace seen by doctest-ed code:

http://docs.python.org/lib/doctest-execution-context.html


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


Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
Py-Fun wrote:

 I'm stuck trying to write a function that generates a factorial of a
 number using iteration and not recursion.  Any simple ideas would be
 appreciated.

As opposed to what, a complicated one?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
Py-Fun wrote:

 def itforfact(n):
 while n100:
 print n
 n+1
 n = input(Please enter a number below 100)

You function should probably return something. After that, you can see 
what happens with the result you get.
-- 
http://mail.python.org/mailman/listinfo/python-list


TeX pestilence (was Distributed RVS, Darcs, tech love)

2007-10-22 Thread Xah Lee
TeX, in my opinion, has done massive damage to the computing world.

i have written on this variously in emails. No coherent argument, but
the basic thoughts are here:
http://xahlee.org/cmaci/notation/TeX_pestilence.html

it's slightly repeatitous there. But i think i might summarize in gist
the few fundanmental issues, all sterm from just the first one:

1. A typesetting system per se, not a mathematical expressions
representation system.

2. The free nature, like cigeratte given to children, contaminated the
entire field of math knowledge representation into 2 decades of
stagnation.

3. Being a typesetting system, brainwashed entire generation of
mathematicians into micro-spacing doodling.

4. Inargurated a massive collection of documents that are invalid
HTML. (due to the programing moron's ingorance and need to idolize a
leader, and TeX's inherent problem of being a typesetting system that
is unsuitable of representing any structure or semantics)

5. This is arguable and trivial, but i think TeX judged as a computer
language in particular its syntax, on esthetical grounds, sucks in
major ways.

Btw, a example of item 4 above, is Python's documentation. Fucking
asses and holes.

  Xah
  [EMAIL PROTECTED]
  http://xahlee.org/

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


Re: Iteration for Factorials

2007-10-22 Thread Duncan Booth
Py-Fun [EMAIL PROTECTED] wrote:

 I'm stuck trying to write a function that generates a factorial of a
 number using iteration and not recursion.  Any simple ideas would be
 appreciated.
 
This version avoids doing anything fancier than adding 1, so it should be 
simple enough for anyone:

def factorial(e):
a = 1
for b in range(e):
c = 0
for j in range(b, -1, -1):
for d in range(a):
c += 1
a = c
return a


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


Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
On 22 Oct, 13:43, Marco Mariani [EMAIL PROTECTED] wrote:
 Py-Fun wrote:
  def itforfact(n):
  while n100:
  print n
  n+1
  n = input(Please enter a number below 100)

 You function should probably return something. After that, you can see
 what happens with the result you get.

Marco, Thanks for the tip.  This now works:

def itforfact(n):
while n100:
print n
n = n+1
n = input(Please enter a number below 100)

itforfact(n)

Is it a factorial though?

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


Re: Iteration for Factorials

2007-10-22 Thread cokofreedom
On Oct 22, 2:43 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Py-Fun wrote:
  def itforfact(n):
  while n100:
  print n
  n+1
  n = input(Please enter a number below 100)

 You function should probably return something. After that, you can see
 what happens with the result you get.

lambda n: n=0 or reduce(lambda a,b: long(a)*long(b),xrange(1,n+1))


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


Re: Iteration for Factorials

2007-10-22 Thread Amit Khemka
On 10/22/07, Py-Fun [EMAIL PROTECTED] wrote:
 On 22 Oct, 13:28, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Py-Fun wrote:
   I'm stuck trying to write a function that generates a factorial of a
   number using iteration and not recursion.  Any simple ideas would be
   appreciated.
 
  Show us your attempts, and we might suggest a fix. Because otherwise this
  sounds suspiciously like homework.
 
  Diez

 Here is my futile attempt.  Be careful with this though, I just ran
 something similar and it was never ending...

 def itforfact(n):
 while n100:
 print n
 n+1
 n = input(Please enter a number below 100)

 itforfact(n)

Let me give you a pseudo code (which though can be found in most of
the textbooks and some 'simple' googling). Try to understand the code
and then write an equivalent python function.

function iFactorial(n: integer): integer;
var i, temp: integer;
begin
  temp = 1;
  for i = 1 to n do
temp = temp * i
end
return temp

About your code.
1. why doesn't it surprise you if the code that you posted goes in
infinite loop ?!
2. why do you use condition:  n  100
3. How do you think that your function will calculate the factorial ?
4. Instead of input use raw_input, and then cast the input as integer .

Cheers,
amit.
-- 
--
Amit Khemka
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration for Factorials

2007-10-22 Thread vimal
On Oct 22, 5:43 pm, Marco Mariani [EMAIL PROTECTED] wrote:
 Py-Fun wrote:
  def itforfact(n):
  while n100:
  print n
  n+1
  n = input(Please enter a number below 100)

 You function should probably return something. After that, you can see
 what happens with the result you get.


i am just suggesting u an idea
but i dont know it satisfies ur needs

x=10
def cal_range(10)
for i in range(10):
print 2**i


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


Re: CGI and external JavaScript nightmare

2007-10-22 Thread Istvan Albert
On Oct 18, 5:04 pm, IamIan [EMAIL PROTECTED] wrote:
   The OP's problem is that he suffers from the delusion that people want
   to steal the source code for hisCGIscript.

 Why is assuming someone may try to get my source CGI delusional?

 I'm on a shared server (Dreamhost). The CGI itself has 755 permissions
 to execute, but what about folder permissions, etc? If you could
 expand on access to the server, and so on that would be great.

- as far as accessing through the web goes this is a matter of
webserver configuration, set up your webserver in a such a way that it
will not return the source code for your scripts

- regarding shared webhosting services, you may not be able to deny
access to people who have shared accounts (and shell login) on the
same server as you do. It all depends on how the shared accounts are
set up.

i.



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


Re: TeX pestilence (was Distributed RVS, Darcs, tech love)

2007-10-22 Thread Lew
Xah Lee wrote:
 i have written ... No coherent argument, 

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


How can I test the web page opened by window.showModalDialog() method using PAMIE?

2007-10-22 Thread 尹祥龙
How can I test the web page  which is opened by window.showModalDialog()
method using PAMIE?

There are two html pages:a.html and b.html.
[a.html]:
input type=button onClick='a();' value=button_a
script type=text/javascript
!--
function a(){
yin = window.showModalDialog(b.htm,hehe);
}
//--
/script

[b.html]:
input type=button value=button_b

Firstly, I clicked button_a in a.html. The b.html is pop up. Now I expect to
click the button_b in b.html. How to do?Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problems in using wxPython in a multithreaded context

2007-10-22 Thread kyosohma
On Oct 22, 4:53 am, [EMAIL PROTECTED] wrote:
 For my C application, I use many interpreters (withh the fonction
 Py_NewInterpreter()). For my needs, I create many GUI with wxPython
 and I have problems. Here is My C Code:

 {
 PyEval_InitThreads();
 Py_Initialize();
 PyImport_ImportModule(myModule);//it creates a wxApp and a GUI
 ..

 Py_NewInterpreter();
 PyImport_ImportModule(anotherModule);//it should create a new
 wxApp and a new GUI

 Unfortunately this code does not work. In fact, My C application which
 use many interpreters is seen by wxPython as a single application, and
 as wxPython is thread safe, it is not possible to create a second
 App.
 I have to use many interpreters to separate variables and to avoid
 links between modules.

 What could I do to create many GUI in different interpreters (each GUI
 have to be in a separate environment)???

 Thanks.

You should probably check out this thread:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4ac31cd3a389a4d8/

And this might help as well:

http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html

And here's a wxPython specific article on threading:

http://wiki.wxpython.org/LongRunningTasks

You might consider posting to the wxPython mailing list too, as they
can probably help you more.

Mike

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


Re: Endless GIL and thread confusion

2007-10-22 Thread kyosohma
On Oct 21, 11:25 am, enska [EMAIL PROTECTED] wrote:
 Can someone clarify the steps needed to make access to the interpreter
 safe from multiple threads?

 I've been reading the docs for days and I still find them very confusing
 and misleading. For example does the PyGILState_Ensure() function lock the
 GIL or just create the thread state? Is thread supposed to call it once on
 creation and then the release function before exiting or is this the
 preferred mechanism to handle the locking? Most of the confusion stems
 from this segment in the documentation.

 ...when threads are created from C, they don't have the global
 interpreter lock, nor is there a thread state data structure for them.
 Such threads must bootstrap themselves into existence, by first creating a
 thread state data structure, then acquiring the lock, and finally storing
 their thread state pointer, before they can start using the Python/C API.
 When they are done, they should reset the thread state pointer, release
 the lock, and finally free their thread state data structure.

 Beginning with version 2.3, threads can now take advantage of the
 PyGILState_*() functions to do all of the above automatically.

 Anyway, currently my code looks like this:

 void foobar(...)
 {
 PyGILState state = PyGILState_Ensure();

 // make python calls

 PyGILState_Release(state);

 }

 void blablah(...)
 {
 PyGILState state = PyGILState_Ensure();

 // make python calls

 PyGILState_Release(state);

 }

 My python Initialization code looks like this

 void init_python(char* progname, char* bindir)
 {
 Py_SetProgramName(progname);
 PyEval_InitThreads();
 Py_InitializeEx(0);

 char* argv[] = {progname, bindir};
 PySys_SetArgv(2, argv);

 }

 calling foobar() or blablah() from the main thread works as expected, but
 if the second thread calls them it locks up in the call to
 PyGILState_Ensure().

 I have tried adding a call to PyEval_ReleaseLock() in the init_python
 function to make sure that the main thread is not holding the GIL, but
 this causes the application to segfault when it is calling Py_Finalize()
 so it is clear that this is not correct.

 Please advice.

 Thanks.

I use the Threading module whenever I need to use threads. It works
quite nicely and I have yet to have any problems with it, except for a
little goofiness with WMI that was explained to me long ago. You might
check that module out.

The wiki for wxPython actually has a good tutorial on threads:

http://wiki.wxpython.org/LongRunningTasks

And here's an article on usurping the GIL:

http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html

Hope that helps a little.

Mike

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


Re: calling a function from string

2007-10-22 Thread Shane Geiger
 exec(import datetime) ; exec(x = datetime. + date. + today())
 print x
2007-10-22




james_027 wrote:
 hi,

 i have a function that I could like to call, but to make it more
 dynamic I am constructing a string first that could equivalent to the
 name of the function I wish to call. how could I do that? the string
 could might include name of the module.

 for example

 a_string = 'datetime.' + 'today()'

 how could I call a_string as function?

 Thanks
 james

   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
url:http://www.ncee.net
version:2.1
end:vcard

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

Python-URL! - weekly Python news and links (Oct 22)

2007-10-22 Thread Gabriel Genellina
QOTW:  [T]here's always no best. - Lawrence Oluyede
http://groups.google.com/group/comp.lang.python/msg/32bce47d185 ce42e

I actually do a lot of unit testing. I find it both annoying and highly
necessary and useful. - Steven Bethard
http://groups.google.com/group/comp.lang.python/msg/4df60bdff72540cb


Some confusion when using `if x:` as an existence test:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e75348ea2159ceac

The difference between list+=a and list.extend(a) and
how to use the timeit module the right way:
http://groups.google.com/group/comp.lang.python/msg/2f932731e3b96c7f

Detecting the last element in an iteration:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/34c7398eec5a92cd

Unicode support in MySQL:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e1a9b5e57d37254a

mod_python and its limited reload support:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/30cc3ff191064589

unicodedata.normalize is not enough for automatic transliteration:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e977d6cd55d1014a

How to use expressions and reference other modules
when configuring the logging package:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/21be57fae7e9381a

How to tell if a script is being run by python.exe
or pythonw.exe (Windows):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/716df077effd7736



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiats:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://aspn.activestate.com/ASPN/Cookbook/Python

Many Python conferences 

Re: Get the instance name from a list by Reflection

2007-10-22 Thread Larry Bates
Jean-Paul Calderone wrote:
 On Sat, 20 Oct 2007 21:10:34 +0200 (CEST), sccs cscs [EMAIL PROTECTED] 
 wrote:
 Hello,
 I cannot find into documentation how to get the instance name. I found 
 the attributes __dict__,__class__ ,__bases__ __name__ ,
 but if i have the code:

 class A :pass
 a1 = A ()
 a2 = A ()
 aList = [a1,a2]
 for elem in aList :
print elem.__instance_name__ ???

 I expect to have a1 a2 ...
 But it does not work ...
 help please
 Zorgi
 
$ python
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type help, copyright, credits or license for more information.
 class A: pass
...
 a1 = A()
 a2 = A()
 aList = [a1, a2]
 import __main__
 from twisted.python.reflect import objgrep, isSame
 for elem in aList:
... objgrep(__main__, elem, isSame)
...
['.aList[0]', '.elem', '.a1']
['.aList[1]', '.elem', '.a2']

 
 Don't see how this could help,
 
 Jean-Paul
If you want to accomplish something like this use the following:

class A(object):
 def __init__(self, name=None):
 self.name=name

aList=[]
aList.append(A(name='a1')
aList.append(A(name='a2')
for elem in aList:
 print elem.name

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


Re: Check File Change Every 10 Seconds

2007-10-22 Thread Gabriel Genellina
En Mon, 22 Oct 2007 06:56:52 -0300, Robert Rawlins - Think Blue  
[EMAIL PROTECTED] escribi�:

 I've got a requirement to check a file for a change every 10 seconds or  
 so,
 and if the file has been modified since the last time I parsed its  
 content
 into the application then I need to parse it in again. However, I need  
 this
 process to not interrupt the rest of my application flow.

See this article by Tim Golden:
http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html

 What is the best way to handle this? Is there some form of file watcher
 module for python which can watch the file for me and then parse any  
 changes
 into the application memory? Or should I be spawning and unjoined thread
 which contains and infinite loop which checks a date/time the file was
 modified against an internal date/time variable for when the application
 last parsed the file into memory?

I would use a different thread waiting for notifications from  
ReadDirectoryChangesW (third option in the link above)
See http://msdn2.microsoft.com/en-us/library/aa365465.aspx for more info  
on ReadDirectoryChangesW

-- 
Gabriel Genellina

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

Re: Check File Change Every 10 Seconds

2007-10-22 Thread Tim Golden
Gabriel Genellina wrote:
 En Mon, 22 Oct 2007 06:56:52 -0300, Robert Rawlins - Think Blue  
 [EMAIL PROTECTED] escribi�:
 
 I've got a requirement to check a file for a change every 10 seconds or  
 so,
 and if the file has been modified since the last time I parsed its  
 content
 into the application then I need to parse it in again. However, I need  
 this
 process to not interrupt the rest of my application flow.
 
 See this article by Tim Golden:
 http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
 
 What is the best way to handle this? Is there some form of file watcher
 module for python which can watch the file for me and then parse any  
 changes
 into the application memory? Or should I be spawning and unjoined thread
 which contains and infinite loop which checks a date/time the file was
 modified against an internal date/time variable for when the application
 last parsed the file into memory?
 
 I would use a different thread waiting for notifications from  
 ReadDirectoryChangesW (third option in the link above)
 See http://msdn2.microsoft.com/en-us/library/aa365465.aspx for more info  
 on ReadDirectoryChangesW
 

Although Robert doesn't say so here, I seem to remember that his
past posts have indicated a *nix setting. Robert?

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

RE: Check File Change Every 10 Seconds

2007-10-22 Thread Robert Rawlins - Think Blue
Thanks for your time Gabriel,

That certainly looks to be the type of thing that I'm looking to achieve, 
however, I forgot to mention I'm running this on a Linux platform and not a 
Win32 one :-( Sorry.

I'm sure similar things are achievable, I've used os.stat before now to get the 
time stamp for when a file was last changed, if I perhaps combine this with the 
while 1: inside a thread I can achieve the same end result? Sound like a good 
idea?

I just wasn’t sure how safe it was to spawn a thread like this which contains 
an infinite loop.

Thanks again for your time,

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gabriel Genellina
Sent: 22 October 2007 15:29
To: python-list@python.org
Subject: Re: Check File Change Every 10 Seconds

En Mon, 22 Oct 2007 06:56:52 -0300, Robert Rawlins - Think Blue  
[EMAIL PROTECTED] escribi�:

 I've got a requirement to check a file for a change every 10 seconds or  
 so,
 and if the file has been modified since the last time I parsed its  
 content
 into the application then I need to parse it in again. However, I need  
 this
 process to not interrupt the rest of my application flow.

See this article by Tim Golden:
http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html

 What is the best way to handle this? Is there some form of file watcher
 module for python which can watch the file for me and then parse any  
 changes
 into the application memory? Or should I be spawning and unjoined thread
 which contains and infinite loop which checks a date/time the file was
 modified against an internal date/time variable for when the application
 last parsed the file into memory?

I would use a different thread waiting for notifications from  
ReadDirectoryChangesW (third option in the link above)
See http://msdn2.microsoft.com/en-us/library/aa365465.aspx for more info  
on ReadDirectoryChangesW

-- 
Gabriel Genellina

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

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

Re: C++ version of the C Python API?

2007-10-22 Thread Robert Dailey
On 10/22/07, Nicholas Bastin [EMAIL PROTECTED] wrote:

 Object-oriented programming is a design choice, not a language
 feature.  You can write straight procedural code in C++, and you can
 write object oriented code in C.  Sure, C++ has some language features
 which facilitate object-oriented programming, but it doesn't magically
 make your code object-oriented.  You can certainly write basic
 object-oriented code in C and hide most of the implementation in
 preprocessor macros if you so desire.

Well, perhaps what I meant was I personally would not turn to C for
OOP. As I said before, I've seen OOP attemps using C and it was VERY
unattractive (this coming from a C++ programmer of course). It just
doesn't make sense to me why you'd choose an OOP approach in a
language that makes it messy over a language that had OOP in mind when
it was designed. There are far better languages (which, as you said,
have features to facilitate OOP) that I would choose long before I
chose C, such as C++.

Yes, I agree you can do OOP in any language as it is just a concept,
however there are other entities that can greatly affect which
language you choose to intake such a responsibility. For example, I'd
choose Python OOP over C++ OOP because to me Python code is cleaner
and has less syntax redundancy. You get to read the important stuff
more quickly. A lot of people would disagree in that whitespace does
not make code more readable than operator delimiters, however this is
just my opinion. In addition, I'd choose Python OOP over C++ OOP for
quick applications that didn't require a great amount of performance
(such as a level editor for a game). For the game itself, I'd choose
C++ OOP because it is way more flexible and allows me to optimize the
game for speed as best as I can, whereas with python you can only
optimize only to a certain point (as with any language), which still
may not be fast enough. In any case, it's really not fair to compare
speed between an interpreted language vs a compiled language.

Given what I've learned and things I've come to like, I doubt I'd do
any sort of programming ever again that didn't involve some sort of
object oriented design. That's just my preference. This preference, in
turn, is what motivated my original question. The CPython API
interface itself seems modularized, NOT object oriented (only from
what I saw). Boost.Python, as so many have already noted, is a wrapper
over that interface introducing C++ which provides the OOP I am
looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration for Factorials

2007-10-22 Thread Ant
On Oct 22, 1:26 pm, Py-Fun [EMAIL PROTECTED] wrote:
 I'm stuck trying to write a function that generates a factorial of a
 number using iteration and not recursion.  Any simple ideas would be
 appreciated.

The following simple adder functions should give you an idea of how
recursion can be recast as iteration:

def acc(i):
'''i should be a positive integer'''
if i  0:
return i + acc(i - 1)
return 0

print acc, acc(9)

def itt(i):
'''i should be a positive integer'''
out = 0

while i  0:
out += i
i = i - 1

return out

print itt, itt(9)

 ...
 Is it a factorial though?

Er, no. And neither is mine. You may want to google for the definition
of factorial! Here's a hint:

reduce(operator.mul, range(1, i + 1))

--
Anthony Roy


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


Building sparc64 32/64-bit Python

2007-10-22 Thread Stefan Bellon
Hi,

I'm trying to build a Sun Solaris Version of Python from the source so
that both, 32-bit and 64-bit libraries are present.

I can successfully build a 32-bit version in one directory and a 64-bit
version in another directory. What I'd like to do is to build a version
that has the 64-bit library in a sparcv9 directory but shares the other
Python libraries that are ELF-code independent.

Is this possible or do I really have to install two complete but
separate Pythons although most of the files are the same?

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


Re: Building sparc64 32/64-bit Python

2007-10-22 Thread Diez B. Roggisch
Stefan Bellon wrote:

 Hi,
 
 I'm trying to build a Sun Solaris Version of Python from the source so
 that both, 32-bit and 64-bit libraries are present.
 
 I can successfully build a 32-bit version in one directory and a 64-bit
 version in another directory. What I'd like to do is to build a version
 that has the 64-bit library in a sparcv9 directory but shares the other
 Python libraries that are ELF-code independent.
 
 Is this possible or do I really have to install two complete but
 separate Pythons although most of the files are the same?

It should be possible to create a independent site-packages directory that
contains the python-library and then tinker with both installations setting
that directory as part of the python-path (look at *pth-files in the
site-packages directory to get an idea how that works)

Another question is if that's advisable. It certainly won't become part of
the standard installation scripts, and in the end you save how much - 8MB
or so?

Diez

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


Re: using request variable in python web program

2007-10-22 Thread Gabriel Genellina
En Mon, 22 Oct 2007 05:34:55 -0300, sami [EMAIL PROTECTED] escribi�:

 Thanks again Paul - now I can see that the request object is a
 string of name/value pairs that occurs after a ? in a url e.g.
 url.com/index.cgi?name=samilang=python - is that correct? Googling
 for this information is useless since the word request is so common
 on the www

Not exactly - this is the query string part of the URI.
Request and Response are the two messages defined by the HTTP protocol.  
When you type a URL or click on a link or press a button in a page, your  
browser builds the appropiate Request message and sends it to the server.  
After processing, the server emits the Response message, and the browser  
displays it or otherwise processes the response.
The request and response objects that most web frameworks expose are  
abstractions of these two HTTP messages.
The bloody details are specified in RFC 2616 HTTP/1.1  
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html, but you can find  
plenty of less technical descriptions. At least a basic understanding of  
how the HTTP protocol works is required to build a web application.

-- 
Gabriel Genellina

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

RE: Check File Change Every 10 Seconds

2007-10-22 Thread Robert Rawlins - Think Blue
Spot on Tim, I'm running Linux, I totally forgot to mention... more detail 
coming in a reply to Gabriel's post.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Golden
Sent: 22 October 2007 15:40
Cc: python-list@python.org
Subject: Re: Check File Change Every 10 Seconds

Gabriel Genellina wrote:
 En Mon, 22 Oct 2007 06:56:52 -0300, Robert Rawlins - Think Blue  
 [EMAIL PROTECTED] escribi�:
 
 I've got a requirement to check a file for a change every 10 seconds or  
 so,
 and if the file has been modified since the last time I parsed its  
 content
 into the application then I need to parse it in again. However, I need  
 this
 process to not interrupt the rest of my application flow.
 
 See this article by Tim Golden:
 http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
 
 What is the best way to handle this? Is there some form of file watcher
 module for python which can watch the file for me and then parse any  
 changes
 into the application memory? Or should I be spawning and unjoined thread
 which contains and infinite loop which checks a date/time the file was
 modified against an internal date/time variable for when the application
 last parsed the file into memory?
 
 I would use a different thread waiting for notifications from  
 ReadDirectoryChangesW (third option in the link above)
 See http://msdn2.microsoft.com/en-us/library/aa365465.aspx for more info  
 on ReadDirectoryChangesW
 

Although Robert doesn't say so here, I seem to remember that his
past posts have indicated a *nix setting. Robert?

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

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

Re: python 2.5 scripting in vim on windows: subprocess problem

2007-10-22 Thread MVP
Hi!

VIM can, also, to be OLE-COM-server.

Try with: 
  from win32com.client.dynamic import Dispatch
  vim = Dispatch('Vim.Application')

(+google)

@-salutations

Michel Claveau


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


Re: Building sparc64 32/64-bit Python

2007-10-22 Thread Stefan Bellon
On Mon, 22 Oct, Diez B. Roggisch wrote:
 Stefan Bellon wrote:

  I can successfully build a 32-bit version in one directory and a
  64-bit version in another directory. What I'd like to do is to
  build a version that has the 64-bit library in a sparcv9 directory
  but shares the other Python libraries that are ELF-code independent.
  
  Is this possible or do I really have to install two complete but
  separate Pythons although most of the files are the same?
 
 It should be possible to create a independent site-packages directory
 that contains the python-library and then tinker with both
 installations setting that directory as part of the python-path (look
 at *pth-files in the site-packages directory to get an idea how that
 works)

Well, I didn't want to to tinker with installation files. I hoped that
there was a way to configure it accordingly.

 Another question is if that's advisable. It certainly won't become
 part of the standard installation scripts, and in the end you save
 how much - 8MB or so?

I thought it would be a more correct way of installing it. GCC (and
others) install their libraries in prefix/lib and prefix/lib/sparcv9 as
well without needing two separate installations, therefore I was
wondering whether the same can be achieved with Python.

But if this is not possible, then I'll just go for python and python64
as separated installations.

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


Re: Get the instance name from a list by Reflection

2007-10-22 Thread jon vspython
May be, you could check against globals() dictionary looking for matching
id()'s:

def find_name(identifier):
 for k,v in globals().items():
 if id(v) == id(identifier):
 return k
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pydoc script.py vs. pydoc scriptpy

2007-10-22 Thread Stargaming
On Sat, 20 Oct 2007 15:02:26 +, BartlebyScrivener wrote:

 On Debian Etch, if ~/mypyscripts is in my bash PATH and also in
 PYTHONPATH, I get the following pydoc behaviors. Maybe this is
 intentional. I'm just checking to be sure I don't have something
 misconfigured in my environment.
 
 If I have two scripts or modules  in ~/mypyscripts: one script.py and
 one scriptpy (no extension), and do:
 
 $pydoc script
 
 I get the documentation strings for script.py.
 
 However, if I do:
 
 $pydoc scriptpy
 
 I get no doc strings, even if I am in the ~/mypyscripts directory, error
 message:
 no Python documentation found for 'scriptpy'
 
 Instead I must do:
 
 $pydoc ~/mypyscripts/scriptpy
 
 even though ~/mypyscripts is in both PATH and PYTHONPATH
 
 Took me awhile to sort this out. Is this the way pydoc is supposed to
 work?
 
 thanks,
 
 rpd

From the pydoc documentation:

The argument to pydoc can be the name of a function, 
module, or package, or a dotted reference to a class, 
method, or function within a module or module in a 
package. If the argument to pydoc looks like a path 
(that is, it contains the path separator for your 
operating system, such as a slash in Unix), and refers 
to an existing Python source file, then documentation 
is produced for that file.

Since `script` is a valid module name in your case, referencing 
script.py, pydoc uses this file. `scriptpy` is no valid module name and 
thus, does not work.

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


Re: TeX pestilence (was Distributed RVS, Darcs, tech love)

2007-10-22 Thread George Neuner
On Mon, 22 Oct 2007 05:50:30 -0700, Xah Lee [EMAIL PROTECTED] wrote:

TeX, in my opinion, has done massive damage to the computing world.

i have written on this variously in emails. No coherent argument, but
the basic thoughts are here:
http://xahlee.org/cmaci/notation/TeX_pestilence.html

Knuth did a whole lot more for computing than you have or, probably,
ever will.  Your arrogance is truly amazing.


1. A typesetting system per se, not a mathematical expressions
representation system.

So?

2. The free nature, like cigeratte given to children, contaminated the
entire field of math knowledge representation into 2 decades of
stagnation.

What the frac are you talking about?

3. Being a typesetting system, brainwashed entire generation of
mathematicians into micro-spacing doodling.

Like they wouldn't be doodling anyway.  At least the TeX doodling is
likely to be readable (as if anyone cared).

4. Inargurated a massive collection of documents that are invalid
HTML. (due to the programing moron's ingorance and need to idolize a
leader, and TeX's inherent problem of being a typesetting system that
is unsuitable of representing any structure or semantics)

HTML is unsuitable for representing most structure and semantics.  And
legions of fumbling idiots compose brand new invalid HTML every day.

5. This is arguable and trivial, but i think TeX judged as a computer
language in particular its syntax, on esthetical grounds, sucks in
major ways.

No one except you thinks TeX is a computer language.

Btw, a example of item 4 above, is Python's documentation. Fucking
asses and holes.

Watch your language, there are children present.

George
--
for email reply remove / from address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
 From the cookbook, this time.
It satisfies the requirements nicely  ;)


http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691



def tail_recursion(g):
 '''
 Version of tail_recursion decorator using no stack-frame 
inspection.
 '''
 loc_vars ={in_loop:False,cnt:0}

 def result(*args, **kwd):
 loc_vars[cnt]+=1
 if not loc_vars[in_loop]:
 loc_vars[in_loop] = True
 while 1:
 tc = g(*args,**kwd)
 try:
 qual, args, kwd = tc
 if qual == 'continue':
 continue
 except (TypeError, ValueError):
 loc_vars[in_loop] = False
 return tc
 else:
 if loc_vars[cnt]%2==0:
 return ('continue',args, kwd)
 else:
 return g(*args,**kwd)
 return result


@tail_recursion
def factorial(n, acc=1):
 calculate a factorial
 if n == 0:
return acc
 res = factorial(n-1, n*acc)
 return res

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


Re: Check File Change Every 10 Seconds

2007-10-22 Thread Marco Mariani
Robert Rawlins - Think Blue wrote:

 That certainly looks to be the type of thing that I'm looking to achieve, 
 however, I forgot to mention I'm running this on a Linux platform and not a 
 Win32 one :-( Sorry.

Did you try python-gamin?

Gamin is a file and directory monitoring system defined to be a subset 
of the FAM (File Alteration Monitor) system.

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


Re: Iteration for Factorials

2007-10-22 Thread Tim Golden
Marco Mariani wrote:
  From the cookbook, this time.
 It satisfies the requirements nicely  ;)
 
 
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
 

[... snip the ultimate general-purpose answer to the OP's question ...

I really hope that's a wink up there, Marco. The poor guy
was just trying to get his homework done!

:

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


Re: Check File Change Every 10 Seconds

2007-10-22 Thread Gabriel Genellina
En Mon, 22 Oct 2007 11:45:49 -0300, Robert Rawlins - Think Blue  
[EMAIL PROTECTED] escribi�:

 Thanks for your time Gabriel,

 That certainly looks to be the type of thing that I'm looking to  
 achieve, however, I forgot to mention I'm running this on a Linux  
 platform and not a Win32 one :-( Sorry.

Ouch! Should have asked...

 I'm sure similar things are achievable, I've used os.stat before now to  
 get the time stamp for when a file was last changed, if I perhaps  
 combine this with the while 1: inside a thread I can achieve the same  
 end result? Sound like a good idea?

Yes, that may work, but there are better ways I think. Check this recipe  
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/217829 and the  
pyinotify module at sourceforge.

-- 
Gabriel Genellina

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

Re: Check File Change Every 10 Seconds

2007-10-22 Thread Paul Rudin
Marco Mariani [EMAIL PROTECTED] writes:

 Robert Rawlins - Think Blue wrote:

 That certainly looks to be the type of thing that I'm looking to achieve, 
 however, I forgot to mention I'm running this on a Linux platform and not a 
 Win32 one :-( Sorry.

 Did you try python-gamin?

 Gamin is a file and directory monitoring system defined to be a
 subset of the FAM (File Alteration Monitor) system.

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


Re: TeX pestilence (was Distributed RVS, Darcs, tech love)

2007-10-22 Thread Lew
Xah Lee [EMAIL PROTECTED] wrote:
 4. Inargurated a massive collection of documents that are invalid
 HTML. (due to the programing moron's ingorance and need to idolize a
 leader, and TeX's inherent problem of being a typesetting system that
 is unsuitable of representing any structure or semantics)

There's something a little fey about someone calling out a programing [sic] 
moron's ingorance [sic] and then devolving right into blue speech.

I think Xah Lee should look into:
http://en.wikipedia.org/wiki/Psychological_projection

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


Re: Need help parsing with pyparsing...

2007-10-22 Thread Paul McGuire
On Oct 22, 4:18 am, Just Another Victim of the Ambient Morality
[EMAIL PROTECTED] wrote:
 I'm trying to parse with pyparsing but the grammar I'm using is somewhat
 unorthodox.  I need to be able to parse something like the following:

 UPPER CASE WORDS And Title Like Words

 ...into two sentences:

 UPPER CASE WORDS
 And Title Like Words

 I'm finding this surprisingly hard to do.  The problem is that pyparsing
 implicitly assumes whitespace are ignorable characters and is (perhaps
 necessarily) greedy with its term matching.  All attempts to do the
 described parsing either fails to parse or incorrectly parses so:

 UPPER CASE WORDS A
 nd Title Like Words

 Frankly, I'm stuck.  I don't know how to parse this grammar with
 pyparsing.
 Does anyone know how to accomplish what I'm trying to do?
 Thank you...

Yes, whitespace skipping does get in the way sometimes.  In your case,
you need to clarify that each word that is parsed must be followed by
whitespace.  See the options and comments in the code below:

from pyparsing import *

data = UPPER CASE WORDS And Title Like Words

# Option 1 - qualify Word instance with asKeyword=True
upperCaseWord = Word(alphas.upper(), asKeyword=True)
titleLikeWord = Word(alphas.upper(), alphas.lower(), asKeyword=True)

# Option 2 - explicitly state that each word must be followed by
whitespace
upperCaseWord = Word(alphas.upper()) + FollowedBy(White())
titleLikeWord = Word(alphas.upper(), alphas.lower()) +
FollowedBy(White())

# Option 3 - use regex's - note, still have to use lookahead to avoid
matching
# 'A' in 'And'
upperCaseWord = Regex(r[A-Z]+(?=\s))
titleLikeWord = Regex(r[A-Z][a-z]*)

# create grammar, with some friendly results names
grammar = (OneOrMore(upperCaseWord)(allCaps) +
   OneOrMore(titleLikeWord)(title))

# dump out the parsed results
print grammar.parseString(data).dump()


All three options print out:

['UPPER', 'CASE', 'WORDS', 'And', 'Title', 'Like', 'Words']
- allCaps: ['UPPER', 'CASE', 'WORDS']
- title: ['And', 'Title', 'Like', 'Words']

Once you have this, you can rejoin the words with  .join, or
whatever you like.

-- Paul

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


Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
Tim Golden wrote:

  From the cookbook, this time.
 It satisfies the requirements nicely  ;)

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
 
 [... snip the ultimate general-purpose answer to the OP's question ...
 
 I really hope that's a wink up there, Marco.

The wink is in the second line of my post... more for the do the least 
amount of work to meet the requirements people that for the OP

 The poor guy was just trying to get his homework done!

I don't see how my answer is in any way worse than those based on 
lambda. Maybe I'm just envious because when I was his age I couldn't 
google for answers. He should at least be able to do that, shouldn't he?
But wait. That would mean understanding what a factorial is. That would 
require a second search, or a textbook, or an understanding of 
arithmetics before programming with or without recursion. Should we 
blame the teachers?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help parsing with pyparsing...

2007-10-22 Thread Paul McGuire
On Oct 22, 4:18 am, Just Another Victim of the Ambient Morality
[EMAIL PROTECTED] wrote:
 I'm trying to parse with pyparsing but the grammar I'm using is somewhat
 unorthodox.  I need to be able to parse something like the following:

 UPPER CASE WORDS And Title Like Words

 ...into two sentences:

 UPPER CASE WORDS
 And Title Like Words

 I'm finding this surprisingly hard to do.  The problem is that pyparsing
 implicitly assumes whitespace are ignorable characters and is (perhaps
 necessarily) greedy with its term matching.  All attempts to do the
 described parsing either fails to parse or incorrectly parses so:

 UPPER CASE WORDS A
 nd Title Like Words

 Frankly, I'm stuck.  I don't know how to parse this grammar with
 pyparsing.
 Does anyone know how to accomplish what I'm trying to do?
 Thank you...

By the way, are these possible data lines?:

A Line With No Upper Case Words
A LINE WITH NO TITLE CASE WORDS
SOME UPPER CASE WORDS A Title That Begins With A One Letter Word

-- Paul

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


PDB scope problem

2007-10-22 Thread Dale Strickland-Clark
While debugging with PDB earlier, I discovered this idiosyncracy:

(Pdb) lstValues
[[Decimal(1), Decimal(47.0)]]
(Pdb) agg
[0, 1]
(Pdb) print list([sum(v[i] for i in range(len(agg))) for v in lstValues])
*** NameError: global name 'v' is not defined
(Pdb) 

However, the Python interpreter is happy with it if entered directly:

 lstValues
[[Decimal(1), Decimal(47.0)]]
 agg = [0,1]
 print list([sum(v[i] for i in range(len(agg))) for v in lstValues])
[Decimal(48.0)]
 

There seems to be some sort of scope problem in PDB.

-- 
Dale Strickland-Clark


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


parsing the output from matlab

2007-10-22 Thread wang frank

Hi, 
 
I have a big log file generated from matlabe, for each variable, it print the 
name of the variable and an empty line and then the value. such as:
 
x1 =
 
0.1
 
y =
 
   7
 
z = 
 
   6.7
 
x1 =
 
   0.5
 
I want to use python to parse the file and selectively print out the vairable 
and its value. For example, I want to print out all the value related with x1, 
so the output will be
 
x1 = 0.1
x1 = 0.5.
 
I really do not know how to do it.
 
 
Thanks
 
Frank
_
広告表示なし!アカウント有効期限なし!Hotmail Plus のお申し込みはこちら
http://get.live.com/mail/options-- 
http://mail.python.org/mailman/listinfo/python-list

  1   2   3   >