Re: scanning under windows WIA with custom settings (dpi / etc )

2009-11-25 Thread News123


News123 wrote:
 Hi,
 
 I'm trying to scan a document from a python 2.6 script without user
 interaction.
 
 I found  a code snippet, that allows me to scan under Vista, but that
 doesn't allow me to select the dpi / color mode / etc.

I'm still stuck.


I'll try to look at any solution (visual C++, C#, Basic) first.
Then it's perhaps easier to pythonize it via python .net.

However I don't know whether python .net exists for 2.6 and whether it
is stable enough.


N

 
 The snippet uses win32com.client
 
 # # script start
 import win32com.client,os
 
 WIA_IMG_FORMAT_PNG   = {B96B3CAF-0728-11D3-9D7B-F81EF32E}
 WIA_COMMAND_TAKE_PICTURE = {AF933CAC-ACAD-11D2-A093-00C04F72DC3C}
 
 os.chdir('c:/temp')
 wia = win32com.client.Dispatch(WIA.CommonDialog)
 dev = wia.ShowSelectDevice()
 for command in dev.Commands:
 if command.CommandID==WIA_COMMAND_TAKE_PICTURE:
 foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE)
 i=1
 for item in dev.Items:
 if i==dev.Items.Count:
 image=item.Transfer(WIA_IMG_FORMAT_PNG)
 break
 i=i+1
 
 image.SaveFile(test.png)
 # script end
 
 
 My problems are:
 
 - This script works fine for me under Windows 7, however I'm
   unable to   specify additional parameters, like dpi and
   color mode.
 
 - The script doesn't work under windows XP, though the scanner driver is
 installed. (Gimp finds the scanner (as WIA scanner)).
 Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL.
 The error message is:
 
 Traceback (most recent call last):
   File C:\work\python\minidemos\wia_get_simple.py, line 7, in module
 wia = win32com.client.Dispatch(WIA.CommonDialog)
   File C:\Python26\lib\site-packages\win32com\client\__init__.py, line
 95, in Dispatch
 dispatch, userName =
 dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
   File C:\Python26\lib\site-packages\win32com\client\dynamic.py, line
 104, in _GetGoodDispatchAndUserName
 return (_GetGoodDispatch(IDispatch, clsctx), userName)
   File C:\Python26\lib\site-packages\win32com\client\dynamic.py, line
 84, in _GetGoodDispatch
 IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
 pythoncom.IID_IDispatch)
 com_error: (-2147221005, 'Invalid class string', None, None)
 -
 
 
 As I have no knowledge of Win32com and WIA I would appreciate some help
 or good documentation about wincom32 / WIA with python
 
 
 
 thanks for your help and bye
 
 
 N
 
 
 
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CentOS 5.3 vs. Python 2.5

2009-11-25 Thread Steven D'Aprano
On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:

 My dedicated hosting provider wants to switch me to a new server with
 CentOS 5.3, so I have to look at how much work is required.
 
 CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
 requires Python 2.4 for its own internal purposes, and actually
 installing Python 2.5 breaks the package manager.  There's no supported
 RPM for upgrading.
 
 It's apparently necessary to build Python 2.5 from source,
 build all the packages, and debug.


You shouldn't need *quite* that much effort, particularly if you don't 
care about tkinter. Just use the alternate installation so it doesn't 
stomp all over the 2.4 installation:

.configure
make
make altinstall

You will need root or sudo for that last one.


I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly 
easily for me:

$ wget http://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
...
18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
$
$ tar xzf Python-2.5.4.tgz
$ cd Python-2.5.4
$ ./configure
...
$ make
...
$ sudo make altinstall
Password: 
...
$ python -V
Python 2.4.3
$ python2.5 -V
Python 2.5.4


And it all seems to just work for me.




 Nor does that just work. There's
 documentation, but some of it is in Japanese.
 
 http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/

I don't understand why you're using documentation for third-party RPMs as 
evidence that building from source will be troublesome.



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


Re: Beginning Question about Python functions, parameters...

2009-11-25 Thread Bruno Desthuilliers

astral orange a écrit :

On Nov 23, 10:37 pm, r rt8...@gmail.com wrote:

(snip)

This is a horrible example to show noobs. I think the OP could better
understand this as a class EVEN though the OP may or may not know what
a class *is* yet.


class Name():

def __init__(self, first, middle, last):
self.first = first
self.middle = middle
self.last = last


(snip)


As for the class Name(): example above? Even though I haven't seen
exactly what purpose 'self' serves


It's a reference to the current Name instance. But while technically 
correct, I'm sure such this kind of explanation really helps :-/


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


How to import a file by its full path using C api?

2009-11-25 Thread lallous

Hello

PyObject* PyImport_ImportModule( const char *name) 


How to specify a full file path instead and a module name?

Like PyImport_SomeFunction(const char *path_to_script, const char *name)

Thanks,
Elias 
--

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


Re: CentOS 5.3 vs. Python 2.5

2009-11-25 Thread Jon Clements
On Nov 25, 8:13 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
  My dedicated hosting provider wants to switch me to a new server with
  CentOS 5.3, so I have to look at how much work is required.

      CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
  requires Python 2.4 for its own internal purposes, and actually
  installing Python 2.5 breaks the package manager.  There's no supported
  RPM for upgrading.

      It's apparently necessary to build Python 2.5 from source,
  build all the packages, and debug.

 You shouldn't need *quite* that much effort, particularly if you don't
 care about tkinter. Just use the alternate installation so it doesn't
 stomp all over the 2.4 installation:

 .configure
 make
 make altinstall

 You will need root or sudo for that last one.

 I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
 easily for me:

 $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
 ...
 18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
 $
 $ tar xzf Python-2.5.4.tgz
 $ cd Python-2.5.4
 $ ./configure
 ...
 $ make
 ...
 $ sudo make altinstall
 Password:
 ...
 $ python -V
 Python 2.4.3
 $ python2.5 -V
 Python 2.5.4

 And it all seems to just work for me.

  Nor does that just work. There's
  documentation, but some of it is in Japanese.

 http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/

 I don't understand why you're using documentation for third-party RPMs as
 evidence that building from source will be troublesome.

 --
 Steven

And might I add on a box where there is no root access, but sufficient
tools (compilers etc...)

1) Compile from source
2) Set PYTHONPATH correctly for your shell
3) Set your normal path to include your Python rather than the
system's default Python
4) When installing modules (via setup.py install or easy_install)
include a home_dir= (I think that's right OTTOMH) to somewhere in
your home directory, and make sure step 2) complies with this.
5) Double check with which python to make sure it's the correct
version.

hth
Jon.



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


Re: Can self crush itself?

2009-11-25 Thread n00m
Then how can we destroy the 3rd instance,
right after its creation and from inside
class Moo code?

class Moo:
cnt = 0
def __init__(self, x):
self.x = x
self.__class__.cnt += 1
if self.__class__.cnt  2:
print id(self)
## 13406816
## in what dict is this ID?
## and can we delete it from there?

## ???


f = Moo(1)
g = Moo(2)
h = Moo(3)
print h

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


Re: Can self crush itself?

2009-11-25 Thread Chris Rebert
On Wed, Nov 25, 2009 at 1:46 AM, n00m n...@narod.ru wrote:
 Then how can we destroy the 3rd instance,
 right after its creation and from inside
 class Moo code?

Why would you want to do that in the first place? It's strange to say the least.
If you want to prevent an instance being created in the first place,
you can override __new__().

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: attributes, properties, and accessors -- philosophy

2009-11-25 Thread Bruno Desthuilliers

Ethan Furman a écrit :


Let's head towards murkier waters (at least murkier to me -- hopefully 
they can be easily clarified):  some of the attributes are read-only, 
such as record count; others are not directly exposed, but still 
settable, such as table version; and still others require a small amount 
of processing... at which point do I switch from simple attribute access 
to method access?


Short answer : you don't !-)

Long answer : well, in fact you do, but the client code doesn't have to 
be aware that it's in fact calling an accessor.


Before we go into more details, you have to know that Python has a 
pretty good support for computed attributes, with both a simple generic 
solution (the property type) and the full monty (custom types 
implementing the descriptor protocol). So from the interface POV, you 
should never have an explicit accessor method for what is semantically 
an attribute (wheter the attribute is a plain or a computed one being 
part of the implementation).


Let's start with your second point: not directly exposed but still 
settable. I assume you mean not part of the interface, only supposed 
to be accessed (rw) from the methods - if not, please pardon my 
stupidity and provide better explanations !-). If yes: Python doesn't 
have language inforced access restrictions (private / protected / 
etc), but a *very strong* naming convention which is that names starting 
with a leading underscore are implementation details, not part of the 
official interface, and shouldn't be accessed directly. Kind of a 
warranty voided if unsealed.


So if you have attributes you don't want to expose to the outside 
world, just add a single leading underscore to their names.


First and third points are solved by using computed attributes - usually 
a property. The property type takes a few accessor functions as 
arguments - typically, a getter and a setter, and eventually a 
deleter. Used as a class attribute, a property instance will hook up 
into the attribute lookup / setup mechanism (__getattribute__ and 
__setattr__), and will call resp. it's getter or setter function, 
passing it the instance and (for the setter) value.


This directly solves the third point. For the first one, the obvious 
solution is to use a property with a setter that raises an exception - 
canonically, an AttributeError with a message explaining that the 
attribute is read-only.


And for something more hands-on:

class Person(object):
   def __init__(self, firstname, lastname, birthdate):
   self.firstname = firstname
   self.lastname = lastnale
   self.birthdate = birthdate
   self._foo = 42 # implementation only

   def _getfullname(self):
   return %s %s % (self.firstname, self.lastname)
   def _setfullname(self, value):
   raise AttributeError(%s.fullname is read-only % type(self)
   fullname = property(fget=_getfullname, fset=_setfullname)

   def _getage(self):
   return some_computation_with(self.birthdate)
   def _setage(self, value):
   raise AttributeError(%s.age is read-only % type(self)
   age = property(fget=_getage, fset=_setage)


For more on computed attributes, you may want to read about the 
descriptor protocol (google is your friend as usual). This and the 
attribute resolution mechanism are fundamental parts of Python's inner 
working. Learn how it works if you really want to leverage Python's power.


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


Re: attributes, properties, and accessors -- philosophy

2009-11-25 Thread Bruno Desthuilliers

Ethan Furman a écrit :
(snip)

Okay, I'll go back and switch all my attributes *back* to attributes -- 
and properties will be much nicer than my original implementation (using 
__getattr__ and __setattr__).


It will also be faster FWIW.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can self crush itself?

2009-11-25 Thread Ben Finney
n00m n...@narod.ru writes:

 Then how can we destroy the 3rd instance, right after its creation and
 from inside class Moo code?

Normally, one binds whatever references one needs, and lets the garbage
collector clean them up once they fall out of scope. If the references
are living beyond their usefulness, that's probably a sign that your
code isn't modular enough; short, focussed functions might help. But
this is all diagnosis without seeing the symptoms.

Perhaps it's beyond time that you explained what you're trying to
achieve that you think “destroy an instance” will help.

-- 
 \  “I bought a self learning record to learn Spanish. I turned it |
  `\on and went to sleep; the record got stuck. The next day I |
_o__)   could only stutter in Spanish.” —Steven Wright |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to log messages _only once_ from all modules ?

2009-11-25 Thread Jean-Michel Pichavant

Barak, Ron wrote:

Hi,
 
I'm trying to add the logging module to my application, but I seem to 
be missing something.
My application (a wxPython one) has a main script that calls various 
helper classes.

I want the log messages from all modules to go to one central log file.
 
When I implement logging, I think that due to preparation, I get the 
same message more than once.
 
Here's an example:
 
[snip example]
 
Could you suggest what should I change in the above scripts so that 
the log messages would appear only once ?
 
Thanks,

Ron.

If you are starting with the logging facility, I would suggest to add 
handlers only to the root logger (in your __main__ section).


Basically, never configure or add handlers to any logger except for the 
root logger in your __main__ section. There are very few reasons why you 
would break this rule. And when you'll be familiar with the logging 
module you'll when to break it.



[server.py]

import logging
import logging.handlers

logger = logging.getLogger(__name__) # you'd better to create the logger 
at the module level, you may want to log within   the module function


def aFunction(a, b, ,c):
   logger.debug('You called aFunction')

class Server():
   def __init__(self):
   self.logger = logger

   def util(self):
   self.logger.warning('This message comes from Server module ')


[client.py]

import logging
import logging.handlers
from server import Server

logger = logging.getLogger(__name__)

class Client():
   def __init__(self):
   self.logger = logger

   def client_test(self):
   self.logger.warning(This message comes from Client module)

if __name__ == __main__:
   rootLogger = logging.getLogger()
   rootLogger.addHandler(logging.FileHandler(client.log))
   rootLogger.handlers[-1].setFormatter(logging.Formatter(%(asctime)s 
%(name)-12s %(levelname)-8s %(message)s))

   rootLogger.setLevel(logging.DEBUG)
   ser = Server()
   cli = Client()
   ser.util()
   cli.client_test()

Happy logging,

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


Re: pointless musings on performance

2009-11-25 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 22:08:19 +, Benjamin Peterson a écrit :
 
 Would it be worth in-lining the remaining part of PyObject_IsTrue in
 ceval?
 
 Inlining by hand is prone to error and maintainability problems.

Which is why we like to do it :-))


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


Re: pointless musings on performance

2009-11-25 Thread Antoine Pitrou
Le Tue, 24 Nov 2009 16:09:10 -0800, Paul Boddie a écrit :
 
 I'm referring to what you're talking about at the end. The enhancements
 in Python 3 presumably came about after discussion of threaded
 interpreters, confirming that the evaluation loop in Python 2 was not
 exactly optimal.

An optimal evaluation loop is a evaluation loop which doesn't get 
executed at all :-)
(which is what unladen-swallow, cython and pypy are trying to do)

 You need to draw the line between work done by system and external
 libraries and that done by Python, but a breakdown of the time spent
 executing each kind of bytecode instruction could be interesting.

When you say executing each kind of bytecode instruction, are you 
talking about the overhead of bytecode dispatch and operand gathering, or 
the total cost including doing the useful work?

Regardless, it probably isn't easy to do such measurements. I once tried 
using AMD's CodeAnalyst (I have an AMD CPU) but I didn't manage to get 
any useful data out of it; the software felt very clumsy and it wasn't 
obvious how to make it take into account the source code of the Python 
interpreter.

Regards

Antoine.


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


Help with pprint

2009-11-25 Thread Nadav Chernin
Hello, I want to print list of lists in matrix format. So I use pprint
with parameter 'width' for this target. 

For example :

 

 data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]

 pprint(data,width=20)

[[1, 1, 1],

 [1, 1, 1],

 [1, 1, 1]]

 

The problem that I don't know how to select width value, because if:

 

data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one',
'one']]  

 pprint(data,width=20)

[['one',

  'one',

  'one'],

 ['one',

  'one',

  'one'],

 ['one',

  'one',

  'one']]

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


(pywin related) pywintypes.com_error: -2147417846 Application busy

2009-11-25 Thread Alexander Eisenhuth

Hello list,

I'm having a problem with a python COM Excel client that rarely gets the 
exception pywintypes.com_error with the error code -2147417846. (means Excel is 
busy) Here the python code of the exception handling:


[...]
try:
# write a excel cell
[...]
except pywintypes.com_error, ex:
if ex[0] == -2147417846:
time.sleep(1.0)
# retry write?
[...]

My first approach was to retry the writing to the excel cell. But that ends in a 
hanging Excel application (probably a deadlock).


After a little research I found this post:

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5

[...] If you don't register a MessageFilter yourself (by calling 
CoRegisterMessageFilter), you will get default behavior which will be to fail 
the call if it gets rejected.  .Net converts the failure HRESULT to an 
exception.  To deal with the possibility of the server being busy when you try 
to call, you need to implement IMessageFilter::RetryRejectedCall in your client 
code and also register the message filter.  In most cases, you will just need to 
wait for a few seconds and then retry the call--generally that will be 
sufficient time to enable Word to finish whatever it is doing so it can handle 
your call.  However, if the instance of Word that you are controlling could 
possibly visible, you might want to add additional logic to display the 
OLEUIBUSY dialog after some amount of time has passed to notify the user that 
you are waiting on Word to do something and give them the opportunity to help 
the process.  For example, as Misha mentions, Word will reject all incoming 
calls if a modal dialog box is up.  Therefore, in that situation, you would be 
blocked indefinitely until the dialog is dismissed. [...]


As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't 
included in pywin32 I don't see a possibility to do that, or?


Did anybody else have to deal with that problem?

Any hints are very welcome.

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


Re: (pywin related) pywintypes.com_error: -2147417846 Application busy

2009-11-25 Thread Michel Claveau - MVP
Hi! 

Your computer is too slow, for launch Excel.
Configure the machine for more speed...

@+
-- 
MCI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Raw strings as input from File?

2009-11-25 Thread Jon Clements
On Nov 25, 3:31 am, Grant Edwards inva...@invalid.invalid wrote:
 On 2009-11-25, Rhodri James rho...@wildebst.demon.co.uk wrote:



  On Tue, 24 Nov 2009 21:20:25 -, utabintarbo utabinta...@gmail.com  
  wrote:

  On Nov 24, 3:27 pm, MRAB pyt...@mrabarnett.plus.com wrote:

  .readlines() doesn't change the \10 in a file to \x08 in the string
  it returns.

  Could you provide some code which shows your problem?

  Here is the code block I have so far:
  for l in open(CONTENTS, 'r').readlines():
      f = os.path.splitext(os.path.split(l.split('-')[0]))[0]
      if f in os.listdir(DIR1) and os.path.isdir(os.path.join(DIR1,f)):
          shutil.rmtree(os.path.join(DIR1,f))
          if f in os.listdir(DIR2) and os.path.isdir(os.path.join(DIR2,f)):
              shutil.rmtree(os.path.join(DIR2,f))

  Ahem.  This doesn't run.  os.path.split() returns a tuple, and calling  
  os.path.splitext() doesn't work.  Given that replacing the entire loop  
  contents with print l readily disproves your assertion, I suggest you  
  cut and paste actual code if you want an answer.  Otherwise we're just  
  going to keep saying No, it doesn't, because no, it doesn't.

 It's, um, rewarding to see my recent set of instructions being
 followed.

  A minimally obfuscated line from the log file:
  K:\sm\SMI\des\RS\Pat\10DJ\121.D5-30\1215B-B-D5-BSHOE-MM.smz-/arch_m1/
  smi/des/RS/Pat/10DJ/121.D5-30\1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
  11/24/2009 08:16:42 ; 1259068602

  What I get from the debugger/python shell:
  'K:\\sm\\SMI\\des\\RS\\Pat\x08DJQ.D5-30Q5B-B-D5-BSHOE-MM.smz-/arch_m1/
  smi/des/RS/Pat/10DJ/121.D5-30/1215B-B-D5-BSHOE-MM.smz ; t9480rc ;
  11/24/2009 08:16:42 ; 1259068602'

  When you do what, exactly?

 ;)

 --
 Grant

Can't remember if this thread counts as Edwards' Law 5[b|c] :)

I'm sure I pinned it up on my wall somewhere, right next to
http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png

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


Re: (pywin related) pywintypes.com_error: -2147417846 Application busy

2009-11-25 Thread Alexander Eisenhuth

I don't think so, because it happens very rarely

Michel Claveau - MVP schrieb:
Hi! 


Your computer is too slow, for launch Excel.
Configure the machine for more speed...

@+

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


'classmethod' object has only read-only attributes

2009-11-25 Thread Thomas Guettler
Hi,

why have classmethods only readonly attributes? It works for other methods.

exmpale code:
{{{
class Foo(object):
@classmethod
def bar(cls):
pass
bar.myattr='test'
}}}

u...@host:~ python ~/tmp/t.py
Traceback (most recent call last):
  File /home/user/tmp/t.py, line 1, in module
class Foo(object):
  File /home/user/tmp/t.py, line 5, in Foo
bar.myattr='test'
TypeError: 'classmethod' object has only read-only attributes (assign to 
.myattr)


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to import a file by its full path using C api?

2009-11-25 Thread lallous

Looks like one way to do that is to use something like:

   s.sprintf(
 import imp\n
 imp.load_source('%s', r'%s'), modname, script_path);
   PyRun_SimpleString(s.c_str());

Unless someone has a better suggestion.

Regards,
Elias
lallous lall...@lgwm.org wrote in message news:heir4g$oh...@aioe.org...

Hello

PyObject* PyImport_ImportModule( const char *name) 


How to specify a full file path instead and a module name?

Like PyImport_SomeFunction(const char *path_to_script, const char *name)

Thanks,
Elias 

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


Re: 'classmethod' object has only read-only attributes

2009-11-25 Thread Peter Otten
Thomas Guettler wrote:

 Hi,
 
 why have classmethods only readonly attributes? It works for other
 methods.
 
 exmpale code:
 {{{
 class Foo(object):
 @classmethod
 def bar(cls):
 pass
 bar.myattr='test'
 }}}
 
 u...@host:~ python ~/tmp/t.py
 Traceback (most recent call last):
   File /home/user/tmp/t.py, line 1, in module
 class Foo(object):
   File /home/user/tmp/t.py, line 5, in Foo
 bar.myattr='test'
 TypeError: 'classmethod' object has only read-only attributes (assign to
 .myattr)

No idea. But here's a workaround:

 class A(object):
... def method(cls): print cls
... method.foo = 42
... method = classmethod(method)
...
 A.method()
class '__main__.A'
 A.method.foo
42

Or, going fancy:

 def attrs(**kw):
... def set(obj):
... for k, v in kw.iteritems():
... setattr(obj, k, v)
... return obj
... return set
...
 class A(object):
... @classmethod
... @attrs(foo=42)
... def method(cls): print cls
...
 A.method()
class '__main__.A'
 A().method.foo
42

Peter

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


Re: Beginning Question about Python functions, parameters...

2009-11-25 Thread Lie Ryan

astral orange wrote:


As for the class Name(): example above? Even though I haven't seen
exactly what purpose 'self' serves


In many other programming language, self (or this, or Me) refers the the 
current class instance. In some languages, you can refer to an instance 
attribute without an explicit self, this, or Me; the name resolver will 
search in the local namespace (method-level), instance namespace 
(instance-level), class namespace (class-level), perhaps module level 
namespace (file-level), and finally global (application level).


Python interpreter is simple and stupid. It doesn't have many smarts; 
instead of having such a sophisticated name resolver, the compiler 
passes an argument to the function, making `self` a local variable that 
refers to the current instance.


Python programmers accesses instance and class namespace by explicitly 
referring to `self`; the name resolver only have two places to lookup 
names: local namespace (method level) and global namespace (module-level 
[!] not application level in python).


This choice of design simplifies the name resolver, simplifies 
method/function object design (since it does not need any code to handle 
an otherwise implicit self), and completely eliminates ambiguity (to the 
programmer) when having a local variable with the same name as an 
instance variable. Among many other advantages.


The side-effect of this design choice is self must be explicitly 
referenced to access class/instance attributes; unlike in some other 
language where self/this/Me may be omitted when it doesn't clash with 
other variable in local namespace.

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


Workaround To Add Value To TextArea

2009-11-25 Thread Victor Subervi
Hi;
I've noticed that html doesn't support a value attribute for textarea. I
have a form in which I enable users to edit data they've entered into my
database, and one of the data is a textarea. How do I fill the textarea with
the value, or what kind of workaround can I create?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Workaround To Add Value To TextArea

2009-11-25 Thread Rami Chowdhury

Rami Chowdhury
Never assume malice when stupidity will suffice. -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



On Wed, Nov 25, 2009 at 07:19, Victor Subervi victorsube...@gmail.com wrote:
 Hi;
 I've noticed that html doesn't support a value attribute for textarea. I
 have a form in which I enable users to edit data they've entered into my
 database, and one of the data is a textarea. How do I fill the textarea with
 the value, or what kind of workaround can I create?

Hi Victor,

You'll find the textarea and input tags differ significantly, even
though they're both typically used in HTML forms. The W3C page has a
fair overview of how various parts of HTML forms work in HTML 4.01,
and it's roughly accurate for XHTML up to 1.1 as well:
http://www.w3.org/TR/html401/interact/forms.html

HTH,
Rami

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


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


Re: Workaround To Add Value To TextArea

2009-11-25 Thread Victor Subervi
On Wed, Nov 25, 2009 at 10:27 AM, Rami Chowdhury
rami.chowdh...@gmail.comwrote:

 You'll find the textarea and input tags differ significantly, even
 though they're both typically used in HTML forms. The W3C page has a
 fair overview of how various parts of HTML forms work in HTML 4.01,
 and it's roughly accurate for XHTML up to 1.1 as well:
 http://www.w3.org/TR/html401/interact/forms.html


Oops. Silly mistake. Thought I had to put the value inside the tag like the
other tags. Thanks,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: attributes, properties, and accessors -- philosophy

2009-11-25 Thread Ethan Furman

Bruno Desthuilliers wrote:

Ethan Furman a écrit :



Let's head towards murkier waters (at least murkier to me -- hopefully 
they can be easily clarified):  some of the attributes are read-only, 
such as record count; others are not directly exposed, but still 
settable, such as table version; and still others require a small 
amount of processing... at which point do I switch from simple 
attribute access to method access?



Short answer : you don't !-)

Long answer : well, in fact you do, but the client code doesn't have to 
be aware that it's in fact calling an accessor.


Before we go into more details, you have to know that Python has a 
pretty good support for computed attributes, with both a simple generic 
solution (the property type) and the full monty (custom types 
implementing the descriptor protocol). So from the interface POV, you 
should never have an explicit accessor method for what is semantically 
an attribute (wheter the attribute is a plain or a computed one being 
part of the implementation).


Let's start with your second point: not directly exposed but still 
settable. I assume you mean not part of the interface, only supposed 
to be accessed (rw) from the methods - if not, please pardon my 
stupidity and provide better explanations !-).


Better explanation: attribute is publicly available, but buried a couple 
layers deep in a private structure (yes, private structure name starts 
with a leading underscore).


If yes: Python doesn't 
have language inforced access restrictions (private / protected / 
etc), but a *very strong* naming convention which is that names starting 
with a leading underscore are implementation details, not part of the 
official interface, and shouldn't be accessed directly. Kind of a 
warranty voided if unsealed.


So if you have attributes you don't want to expose to the outside 
world, just add a single leading underscore to their names.


First and third points are solved by using computed attributes - usually 
a property. The property type takes a few accessor functions as 
arguments - typically, a getter and a setter, and eventually a 
deleter. Used as a class attribute, a property instance will hook up 
into the attribute lookup / setup mechanism (__getattribute__ and 
__setattr__), and will call resp. it's getter or setter function, 
passing it the instance and (for the setter) value.


This directly solves the third point. For the first one, the obvious 
solution is to use a property with a setter that raises an exception - 
canonically, an AttributeError with a message explaining that the 
attribute is read-only.


And for something more hands-on:

class Person(object):
   def __init__(self, firstname, lastname, birthdate):
   self.firstname = firstname
   self.lastname = lastnale
   self.birthdate = birthdate
   self._foo = 42 # implementation only

   def _getfullname(self):
   return %s %s % (self.firstname, self.lastname)
   def _setfullname(self, value):
   raise AttributeError(%s.fullname is read-only % type(self)
   fullname = property(fget=_getfullname, fset=_setfullname)

   def _getage(self):
   return some_computation_with(self.birthdate)
   def _setage(self, value):
   raise AttributeError(%s.age is read-only % type(self)
   age = property(fget=_getage, fset=_setage)


For more on computed attributes, you may want to read about the 
descriptor protocol (google is your friend as usual). This and the 
attribute resolution mechanism are fundamental parts of Python's inner 
working. Learn how it works if you really want to leverage Python's power.


HTH


Very helpful, thank you.  Hopefully my brain will be up to the 
descriptor protocol this time... the last couple times were, um, less 
than successful.  :)


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


Re: Workaround To Add Value To TextArea

2009-11-25 Thread Jitish
On Nov 25, 8:27 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote:
 
 Rami Chowdhury
 Never assume malice when stupidity will suffice. -- Hanlon's Razor
 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

 On Wed, Nov 25, 2009 at 07:19, Victor Subervi victorsube...@gmail.com wrote:
  Hi;
  I've noticed that html doesn't support a value attribute for textarea. I
  have a form in which I enable users to edit data they've entered into my
  database, and one of the data is a textarea. How do I fill the textarea with
  the value, or what kind of workaround can I create?

 Hi Victor,

 You'll find the textarea and input tags differ significantly, even
 though they're both typically used in HTML forms. The W3C page has a
 fair overview of how various parts of HTML forms work in HTML 4.01,
 and it's roughly accurate for XHTML up to 1.1 as 
 well:http://www.w3.org/TR/html401/interact/forms.html

 HTH,
 Rami

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



HI,
  Ok the simplest solution for this is textarea id=someid
name=somenameAnything you type between this will be treated as the
value for textarea. /textarea

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


Re: IDE+hg

2009-11-25 Thread NiklasRTZ
On Nov 23, 11:37 pm, Rhodri James rho...@wildebst.demon.co.uk
wrote:
 On Mon, 23 Nov 2009 19:20:27 -, NiklasRTZ nikla...@gmail.com wrote:
  Dear experts,
  Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
  Mercurial support not found i.e. buttons to clone, commit and push to
  repositories to define dev env dvcs, editor and deployment all in 1.

 I don't really understand this urge to cram everything into a single  
 program, since that inevitably leads to compromises that will compromise  
 just how much of Mercurial's useful and interesting functionality you can  
 get at.  Still, if you really must, Emacs (and presumably vim) seems to be  
 capable of working with most source control systems.

 --
 Rhodri James *-* Wildebeest Herder to the Masses

Obvious explainations are commandline is slower and IDEs claim support
(Eric) which may mean it's up2 programmer to add and enable the ui. Or
any binding to enable 1 ui. Emacs sure can.
Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE+hg

2009-11-25 Thread NiklasRTZ
On Nov 24, 2:35 pm, Gerhard Häring g...@ghaering.de wrote:
 Rhodri James wrote:
  On Mon, 23 Nov 2009 19:20:27 -, NiklasRTZ nikla...@gmail.com wrote:

  Dear experts,
  Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
  Mercurial support not found i.e. buttons to clone, commit and push to
  repositories to define dev env dvcs, editor and deployment all in 1.

  I don't really understand this urge to cram everything into a single
  program, since that inevitably leads to compromises that will compromise
  just how much of Mercurial's useful and interesting functionality you
  can get at.  Still, if you really must, Emacs (and presumably vim) seems
  to be capable of working with most source control systems.

 I prefer the commandline tools, too.

 FWIW, Eclipse supports Mercurial 
 throughhttp://www.vectrace.com/mercurialeclipse/

 -- Gerhard

Good just Eclipse is too much and tested 4,5... python IDE where non
can hg. Just 2 or 3 buttons to drPython with script enables it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE+hg

2009-11-25 Thread NiklasRTZ
On Nov 24, 3:13 pm, Richard Riley rileyrg...@gmail.com wrote:
 Gerhard Häring g...@ghaering.de writes:
  Rhodri James wrote:
  On Mon, 23 Nov 2009 19:20:27 -, NiklasRTZ nikla...@gmail.com wrote:

  Dear experts,
  Since no py IDE I found has easy hg access. IDEs PIDA and Eric claim
  Mercurial support not found i.e. buttons to clone, commit and push to
  repositories to define dev env dvcs, editor and deployment all in 1.

  I don't really understand this urge to cram everything into a single
  program, since that inevitably leads to compromises that will
  compromise

 Huh? Cram what? Nothing is crammed into anything. The IDE/Editor is
 merely programmed to hook into the external tools

  just how much of Mercurial's useful and interesting functionality you
  can get at.  Still, if you really must, Emacs (and presumably vim) seems
  to be capable of working with most source control systems.

  I prefer the commandline tools, too.

  FWIW, Eclipse supports Mercurial through
 http://www.vectrace.com/mercurialeclipse/

  -- Gerhard

 Why would you prefer the command line tools in a shell when the same
 tools can be used in a way which makes navigating the output so much
 easier? It strikes me as a kind of intransigence. it's a common
 misconception that IDEs use their own tools all the time. They
 don't. They integrate the very same tools. e.g Why the hell would I drop
 to a command line to diff a file with a back version in GIT when I can
 do the same in the buffer in emacs with a single hot key? Why would I
 pipe the output of compile into a file then open that file when a single
 hot key can fire off the SAME compiler and then list the errors in an
 emacs buffer and another hot key can take me directly to the source
 lines in question? Living in the past has its mements, but really.

 e.g I have pylint working live in python buffers. Big time
 saver. Similar with C.

true. While not many programmers lint the code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating pipelines in python

2009-11-25 Thread per
Thanks to all for your replies.  i want to clarify what i mean by a
pipeline.  a major feature i am looking for is the ability to chain
functions or scripts together, where the output of one script -- which
is usually a file -- is required for another script to run.  so one
script has to wait for the other.  i would like to do this over a
cluster, where some of the scripts are distributed as separate jobs on
a cluster but the results are then collected together.  so the ideal
library would have easily facilities for expressing this things:
script X and Y run independently, but script Z depends on the output
of X and Y (which is such and such file or file flag).

is there a way to do this? i prefer not to use a framework that
requires control of the clusters etc. like Disco, but something that's
light weight and simple. right now ruffus seems most relevant but i am
not sure -- are there other candidates?

thank you.

On Nov 23, 4:02 am, Paul Rudin paul.nos...@rudin.co.uk wrote:
 per perfr...@gmail.com writes:
  hi all,

  i am looking for a python package to make it easier to create a
  pipeline of scripts (all in python). what i do right now is have a
  set of scripts that produce certain files as output, and i simply have
  a master script that checks at each stage whether the output of the
  previous script exists, using functions from the os module. this has
  several flaws and i am sure someone has thought of nice abstractions
  for making these kind of wrappers easier to write.

  does anyone have any recommendations for python packages that can do
  this?

 Not entirely what you're looking for, but the subprocess module is
 easier to work with for this sort of thing than os. See e.g. 
 http://docs.python.org/library/subprocess.html#replacing-shell-pipeline

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


Re: attributes, properties, and accessors -- philosophy

2009-11-25 Thread Bruno Desthuilliers

Ethan Furman a écrit :


Very helpful, thank you.  Hopefully my brain will be up to the 
descriptor protocol this time... the last couple times were, um, less 
than successful.  :)


Well, it's quite simple in fact. Most of the magic happens in 
object.__getattribute__ and object.__setattr__. You'll find a rough 
description of what happens here:


http://groups.google.com/group/comp.lang.python/browse_frm/thread/a136f7626b2a8b7d/70a672cf7448c68e




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


Re: csv and mixed lists of unicode and numbers

2009-11-25 Thread M.-A. Lemburg
Sibylle Koczian wrote:
 Hello,
 
 I want to put data from a database into a tab separated text file. This
 looks like a typical application for the csv module, but there is a
 snag: the rows I get from the database module (kinterbasdb in this case)
 contain unicode objects and numbers. And of course the unicode objects
 contain lots of non-ascii characters.
 
 If I try to use csv.writer as is, I get UnicodeEncodeErrors. If I use
 the UnicodeWriter from the module documentation, I get TypeErrors with
 the numbers. (I'm using Python 2.6 - upgrading to 3.1 on this machine
 would cause other complications.)
 
 So do I have to process the rows myself and treat numbers and text
 fields differently? Or what's the best way?

It's best to convert all data to plain strings before passing it
to the csv module.

There are many situations where you may want to use a different
string format than the standard str(obj) format, so this is best
done with a set of format methods - one for each type and format
you need, e.g. one for integers, floats, monetary values, Unicode
text, plain text, etc.

The required formatting also depends on the consumers of the
generated csv or tsv file and their locale.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 25 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with pprint

2009-11-25 Thread Emile van Sebille

On 11/25/2009 4:47 AM Nadav Chernin said...
Hello, I want to print list of lists in matrix format. So I use pprint 
with parameter ‘width’ for this target.

snip

The problem that I don’t know how to select width value, because if:

 

 data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
'one']]  


  pprint(data,width=20)


Almost...

 pprint.pprint(data,width=24)
[['one', 'one', 'one'],
 ['one', 'one', 'one'],
 ['one', 'one', 'one']]

Emile

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


Re: How to run python script in emacs

2009-11-25 Thread doug

When I type C-c C-c my emacs window just hangs.  If I use Task Manager
to kill cmdproxy I can get emacs back but of course interactivity with
Python is not accomplished.  By the way, if I do C-c ! then I get a
functional python shell.  Does anybody know a solution to this?

On Oct 13, 7:12 am, rustom rustompm...@gmail.com wrote:
 On Sep 26, 8:54 pm, devilkin devilsp...@gmail.com wrote:

  I'm just starting learning python, and coding in emacs. I usually
  split emacs window into two, coding in one, and run script in the
  other, which is not very convenient. anyone can help me with it? is
  there any tricks like emacs short cut?

  also please recommand some emacs plug-ins for python programming, i'm
  also beginner in emacs.currently i'm only using python.el.

 python.el comes with emacs
 python-mode.el comes from python  https://launchpad.net/python-mode/
 Because of some emacs politics the first ships with emacs although
 most uses prefer the second.
 Note 1. The key bindings are different
 Note 2. Does not work with python3. See my 
 posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...

  Are any plugins supply code folding and autocomplete?

 See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
 but its an installation headache (requires pymacs bleeding edge
 version etc)
 I suggest you just get used to python-mode first (C-c ! and C-c C-c)
 and then explore these questions a bit later.



  BTW, I'm not a english native speaker, any grammer mistakes, please
  correct them. :)

 grammer is spelt grammar :-)

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


Re: CentOS 5.3 vs. Python 2.5

2009-11-25 Thread Jeff McNeil
On Nov 25, 4:45 am, Jon Clements jon...@googlemail.com wrote:
 On Nov 25, 8:13 am, Steven D'Aprano





 ste...@remove.this.cybersource.com.au wrote:
  On Tue, 24 Nov 2009 22:42:28 -0800, John Nagle wrote:
   My dedicated hosting provider wants to switch me to a new server with
   CentOS 5.3, so I have to look at how much work is required.

       CentOS 5.3 apparently still ships with Python 2.4.  Worse, it
   requires Python 2.4 for its own internal purposes, and actually
   installing Python 2.5 breaks the package manager.  There's no supported
   RPM for upgrading.

       It's apparently necessary to build Python 2.5 from source,
   build all the packages, and debug.

  You shouldn't need *quite* that much effort, particularly if you don't
  care about tkinter. Just use the alternate installation so it doesn't
  stomp all over the 2.4 installation:

  .configure
  make
  make altinstall

  You will need root or sudo for that last one.

  I don't have Centos 5.3, but I have Centos 5, and it seems to work fairly
  easily for me:

  $ wgethttp://www.python.org/ftp/python/2.5.4/Python-2.5.4.tgz
  ...
  18:39:11 (69.6 KB/s) - `Python-2.5.4.tgz' saved [11604497/11604497]
  $
  $ tar xzf Python-2.5.4.tgz
  $ cd Python-2.5.4
  $ ./configure
  ...
  $ make
  ...
  $ sudo make altinstall
  Password:
  ...
  $ python -V
  Python 2.4.3
  $ python2.5 -V
  Python 2.5.4

  And it all seems to just work for me.

   Nor does that just work. There's
   documentation, but some of it is in Japanese.

  http://blog.bashton.com/2008/python-25-rpms-for-rhel-5-centos-5/

  I don't understand why you're using documentation for third-party RPMs as
  evidence that building from source will be troublesome.

  --
  Steven

 And might I add on a box where there is no root access, but sufficient
 tools (compilers etc...)

 1) Compile from source
 2) Set PYTHONPATH correctly for your shell
 3) Set your normal path to include your Python rather than the
 system's default Python
 4) When installing modules (via setup.py install or easy_install)
 include a home_dir= (I think that's right OTTOMH) to somewhere in
 your home directory, and make sure step 2) complies with this.
 5) Double check with which python to make sure it's the correct
 version.

 hth
 Jon.

I'm in a RHEL3 - RHEL5.4 environment and the situation is exactly the
same.  The code I've written requires 2.5 or higher.  I keep a /usr/
local/pythons directory and manually install the versions I need
there.  I then use virtualenv so I don't have to worry about setting
PYTHONPATH manually or anything. I just need to remember to use the
right Python executable. I got to doing this when I discovered that
there are issues with the Cluster Manager (Lucci) and some external
Python packages (some of the Zope stuff, if I remember correctly).

So, in addition to the above steps, you'll probably also want to
include a '--prefix=.' on the command line to the configure script
in order to install in a non-standard location.

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


Python Statements/Keyword Localization

2009-11-25 Thread Emanuele D'Arrigo
Greetings everybody,

some time ago I saw a paper that used an XSL transformation sheet to
transform (if I remember correctly) a Chinese xml file (inclusive of
Chinese-script XML tags) into an XHTML file.

More recently you might have all heard how the ICANN has opened up the
way for non-latin characters in domain names, so that we'll soon start
seeing URLs using Russian, Asian and Arabic characters.

In this context I was wondering if there has ever been much thought
about a mechanism to allow the localization not only of the strings
handled by python but also of its built-in keywords, such as if,
for, while, class and so on. For example, the following English-
based piece of code:

class MyClass(object):
def myMethod(self, aVariable):
 if aVariable == True:
print It's True!
 else:
print It's False!

would become (in Italian):

classe LaMiaClasse(oggetto):
def ilMioMetodo(io, unaVariabile)
 se unaVariabile == Vero:
 stampa E' Vero!
 altrimenti:
 stampa E' Falso!

I can imagine how a translation script going through the source code
could do a 1:1 keyword translation to English fairly quickly but this
would mean that the runtime code still is in English and any error
message would be in English. I can also imagine that it should be
possible to simply recompile python to use different keywords, but
then all libraries using the English keywords would become
incompatible, wouldn't they?

In this context it seems to be the case that the executable would have
to be able to optionally accept -a list- of dictionaries to internally
translate to English the keywords found in the input code and at most -
one- dictionary to internally translate from English output messages
such as a stack trace.

What do you guys think?

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


A language for S40 mobiles

2009-11-25 Thread Saket Bharambe
Hey,
I have recently created an application for S60 mobiles. But I want to
create a similar application for S40 mobiles too. I did the
application of S60 in pyS60 as java had problems with accessing inbox
and contacts. I tried searching for pyS40 , but i couldnt find it.

Ques : Is there python for S40 mobiles ? If yes , where can i find the
installation files and documentation . If no , which the best language
for writing application for S40 mobiles. (keeping in mind that I need
to access the Inbox(sms) and contacts ) ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python gui builders

2009-11-25 Thread Stef Mientki

Shawn Wheatley wrote:

It's not quite all encompassing, but I found this link last year when
looking for a similar comparison of Python GUIs:
http://ginstrom.com/scribbles/2008/02/26/python-gui-programming-platforms-for-windows/

Tkinter, Qt, GTK, IronPython... I think the only thing missing is
Jython w/ Swing or SWT. Check it out.
  
Instead of *hello* world examples, I was thinking of  *real* world 
applications,

something like this,
 http://mientki.ruhosting.nl/data_www/pylab_works/random_gui.html
which in a good GUI package should be doable in about 100 lines of code.

cheers,
Stef

Shawn

On Nov 18, 5:11 pm, Stef Mientki stef.mien...@gmail.com wrote:
  

Wouldn't it be nice
if each fan of some form of GUI-package,
would post it's code (and resulting images) for generating one or two
standard GUI-forms ?



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


Re: How to log messages _only once_ from all modules ?

2009-11-25 Thread Terry Reedy

Jean-Michel Pichavant wrote:



Basically, never configure or add handlers to any logger except for the 
root logger in your __main__ section. There are very few reasons why you 
would break this rule. And when you'll be familiar with the logging 
module you'll when to break it.


I have never used logging, but if and when I have a need for it, the 
advice above and your clear example will be a good guide to getting 
started. Thank you from me too.


tjr


[server.py]

import logging
import logging.handlers

logger = logging.getLogger(__name__) # you'd better to create the logger 
at the module level, you may want to log within   the module function


def aFunction(a, b, ,c):
   logger.debug('You called aFunction')

class Server():
   def __init__(self):
   self.logger = logger

   def util(self):
   self.logger.warning('This message comes from Server module ')


[client.py]

import logging
import logging.handlers
from server import Server

logger = logging.getLogger(__name__)

class Client():
   def __init__(self):
   self.logger = logger

   def client_test(self):
   self.logger.warning(This message comes from Client module)

if __name__ == __main__:
   rootLogger = logging.getLogger()
   rootLogger.addHandler(logging.FileHandler(client.log))
   rootLogger.handlers[-1].setFormatter(logging.Formatter(%(asctime)s 
%(name)-12s %(levelname)-8s %(message)s))

   rootLogger.setLevel(logging.DEBUG)
   ser = Server()
   cli = Client()
   ser.util()
   cli.client_test()

Happy logging,

Jean-Michel


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


Re: Help with pprint

2009-11-25 Thread Terry Reedy

Nadav Chernin wrote:
Hello, I want to print list of lists in matrix format. So I use pprint 
with parameter ‘width’ for this target.


For example :
  data=[[1, 1, 1], [1, 1, 1], [1, 1, 1]]
  pprint(data,width=20)
[[1, 1, 1], 
 [1, 1, 1],

 [1, 1, 1]]




The problem that I don’t know how to select width value, because if:
  data=[['one', 'one', 'one'], ['one', 'one', 'one'], ['one', 'one', 
'one']]  
  pprint(data,width=20)

[['one',
  'one',

 [snip]

1. Cpp.pprint(data, width=100)alculate a width that is big enough but 
not too big. In your example, the interval is [24,69]

2. Write a loop, which gives you finer control.

 for line in data: print(line)
['one', 'one', 'one']
['one', 'one', 'one']
['one', 'one', 'one']

To me, this is more like a matrix and possibly better, depending on your 
particular application. If the items have different default printed 
widths and you want column lined up, you will need to custom format each 
 field in a column to a uniform width anyway. Print and pprint are for 
quick, take-what-you-get output, not for customj-designed production output.


Terry Jan Reedy

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


Re: Python Statements/Keyword Localization

2009-11-25 Thread MRAB

Emanuele D'Arrigo wrote:

Greetings everybody,

some time ago I saw a paper that used an XSL transformation sheet to
transform (if I remember correctly) a Chinese xml file (inclusive of
Chinese-script XML tags) into an XHTML file.

More recently you might have all heard how the ICANN has opened up the
way for non-latin characters in domain names, so that we'll soon start
seeing URLs using Russian, Asian and Arabic characters.

In this context I was wondering if there has ever been much thought
about a mechanism to allow the localization not only of the strings
handled by python but also of its built-in keywords, such as if,
for, while, class and so on. For example, the following English-
based piece of code:

class MyClass(object):
def myMethod(self, aVariable):
 if aVariable == True:
print It's True!
 else:
print It's False!

would become (in Italian):

classe LaMiaClasse(oggetto):
def ilMioMetodo(io, unaVariabile)
 se unaVariabile == Vero:
 stampa E' Vero!
 altrimenti:
 stampa E' Falso!

I can imagine how a translation script going through the source code
could do a 1:1 keyword translation to English fairly quickly but this
would mean that the runtime code still is in English and any error
message would be in English. I can also imagine that it should be
possible to simply recompile python to use different keywords, but
then all libraries using the English keywords would become
incompatible, wouldn't they?

In this context it seems to be the case that the executable would have
to be able to optionally accept -a list- of dictionaries to internally
translate to English the keywords found in the input code and at most -
one- dictionary to internally translate from English output messages
such as a stack trace.

What do you guys think?


It might be necessary to work in tokens, where a token is a word or a
string (or maybe also a comment). Your example would be encoded to:

«1» «2»(«3»):
«4» «5»(«6», «7»):
«8» «7» == «9»:
«10» «11»
«12»:
«10» «13»

with either English:

«1» class
«2» MyClass
«3» object
«4» def
«5» myMethod
«6» self
«7» aVariable
«8» if
«9» True
«10» print
«11» It's True!
«12» else
«13» It's False!

or Italian:

«1» classe
«2» LaMiaClasse
«3» oggetto
«4» def
«5» ilMioMetodo
«6» io
«7» unaVariabile
«8» se
«9» Vero
«10» stampa
«11» É Vero!
«12» altrimenti
«13» É Falso!

Any messages produced by, or format strings used by, the runtime would
also be tokens.

Python currently does lexical analysis on the source code to identify
names, strings, etc; a new tokenised file format would partially bypass
that because the names and strings (and comments?) have already been
identified.
--
http://mail.python.org/mailman/listinfo/python-list


reading windows event logs

2009-11-25 Thread EW
Hi All,
 I'm looking for some guidance on a better way to read eventlogs
from windows servers.  I've written a handy little app that relies on
WMI to pull the logs an in all my testing it worked great.  When I
deployed it, however, WMI choked on servers with a lot of logs.  I've
tried pulling the logs using much smaller VB scripts as well and they
still failed, so I'm pretty sure I'm facing a WMI problem and not a
python or system resources problem.  So I couldn't effectively get
logs off of domain controllers for example or file servers that had
auditing turned on.  Sadly those are exactly the types of servers
whose logs are most interesting.

 So I'm looking for suggestions on a way to grab that data without
using WMI for remote machines.  I know MS has C libraries for this but
I haven't touched C for 10 years so I'm hoping there's a python
equivalent out there somewhere.  Any advice would be appreciated.

Thanks in advance for any help,
Eric
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Statements/Keyword Localization

2009-11-25 Thread garabik-news-2005-05
Emanuele D'Arrigo man...@gmail.com wrote:
 Greetings everybody,
 
 some time ago I saw a paper that used an XSL transformation sheet to
 transform (if I remember correctly) a Chinese xml file (inclusive of
 Chinese-script XML tags) into an XHTML file.
 
 More recently you might have all heard how the ICANN has opened up the
 way for non-latin characters in domain names, so that we'll soon start
 seeing URLs using Russian, Asian and Arabic characters.

Non-latin characters in domain names are already possible (and usable and
actually used) for some years by now. Google for punycode.

ICANN was talking about TLD.

 
 I can imagine how a translation script going through the source code
 could do a 1:1 keyword translation to English fairly quickly

...and get conflickts because I named my variable (in English python),
say, stampa.

Anyway, see http://www.chinesepython.org

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: csv and mixed lists of unicode and numbers

2009-11-25 Thread Sibylle Koczian

Terry Reedy schrieb:

In Python 3, a file opened in 'b' mode is for reading and writing bytes 
with no encoding/decoding. I believe cvs works with files in text mode 
as it returns and expects strings/text for reading and writing. Perhaps 
the cvs doc should say must not be opened in 'b' mode. Not sure.




I think that might really be better, because for version 2.6 they 
explicitly stated 'b' mode was necessary. The results I couldn't 
understand, even after reading the documentation for open():


 import csv
 acsv = open(rd:\home\sibylle\temp\tmp.csv, wb)
 row = [babc, bdef, bghi]
 wtr = csv.writer(acsv)
 wtr.writerow(row)
Traceback (most recent call last):
  File pyshell#22, line 1, in module
wtr.writerow(row)
TypeError: must be bytes or buffer, not str

Same error message with row = [5].

But I think I understand it now: the cvs.writer takes mixed lists of 
text and numbers - that's exactly why I like to use it - so it has to 
convert them before writing. And it converts into text - even bytes for 
a file opened in 'b' mode. Right?


Thank you, everybody, for explaining.

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


Re: reading windows event logs

2009-11-25 Thread MRAB

EW wrote:

Hi All,
 I'm looking for some guidance on a better way to read eventlogs
from windows servers.  I've written a handy little app that relies on
WMI to pull the logs an in all my testing it worked great.  When I
deployed it, however, WMI choked on servers with a lot of logs.  I've
tried pulling the logs using much smaller VB scripts as well and they
still failed, so I'm pretty sure I'm facing a WMI problem and not a
python or system resources problem.  So I couldn't effectively get
logs off of domain controllers for example or file servers that had
auditing turned on.  Sadly those are exactly the types of servers
whose logs are most interesting.

 So I'm looking for suggestions on a way to grab that data without
using WMI for remote machines.  I know MS has C libraries for this but
I haven't touched C for 10 years so I'm hoping there's a python
equivalent out there somewhere.  Any advice would be appreciated.


The events logs are in %SystemRoot%\system32\config and have the
extension .evt. There's info here on the file format:

http://www.whitehats.ca/main/members/Malik/malik_eventlogs/malik_eventlogs.html

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


Re: Python Statements/Keyword Localization

2009-11-25 Thread Terry Reedy

Emanuele D'Arrigo wrote:

Greetings everybody,

some time ago I saw a paper that used an XSL transformation sheet to
transform (if I remember correctly) a Chinese xml file (inclusive of
Chinese-script XML tags) into an XHTML file.

More recently you might have all heard how the ICANN has opened up the
way for non-latin characters in domain names, so that we'll soon start
seeing URLs using Russian, Asian and Arabic characters.

In this context I was wondering if there has ever been much thought
about a mechanism to allow the localization not only of the strings
handled by python but also of its built-in keywords, such as if,
for, while, class and so on.


There have been various debates and discussions on the topic. There has 
been slow movement away from ascii-only in user code. (But not in the 
stdlib, nor will there be there.)

1. Unicode data type.
2. Unicode allowed in comment and string literals.
This required input decoding and coding cookie. This lead, I believe 
somewhat accidentally, to
3. Extended ascii (high bit set, for other European chars in various 
encodings) for identifiers.

4 (In 3.0) unicode allowed for identifiers

 Here is a version of the anti-customized-keyword position. Python is 
designed to be read by people. Currently, any programmer in the world 
can potentially read any Python program. The developers, especially 
Guido, like this. Fixed keywords are not an undue burden because any 
educated person should learn to read Latin characters a-z,0-9. and 
Python has an intentionally  short list that the developers are loath to 
lengthen.


Change 4 above inhibits universal readability. But once 3 happened and 
str became unicode, in 3.0, it was hard to say no to this.


A 'pro' argument: Python was designed for learning and is good for that 
and *is* used in schools down to the elementary level. But kids cannot 
be expected to know foreign alphabets and words whill still learning 
their own.


 For example, the following English-

based piece of code:

class MyClass(object):
def myMethod(self, aVariable):
 if aVariable == True:
print It's True!
 else:
print It's False!

would become (in Italian):

classe LaMiaClasse(oggetto):
def ilMioMetodo(io, unaVariabile)
 se unaVariabile == Vero:
 stampa E' Vero!
 altrimenti:
 stampa E' Falso!

I can imagine how a translation script going through the source code
could do a 1:1 keyword translation to English fairly quickly but this
would mean that the runtime code still is in English and any error
message would be in English.


This is currently seen as a reason to not have other keywords: it will 
do no good anyway. A Python programmer must know minimal English and the 
keywords are the least of the problem.


I can imagine that there could be a mechanism for extracting and 
replacing error messages with translations, like there is for Python 
code, but I do not know if it will even happen with haphazard volunteer 
work or will require grant sponsorship.



I can also imagine that it should be
possible to simply recompile python to use different keywords, but
then all libraries using the English keywords would become
incompatible, wouldn't they?

In this context it seems to be the case that the executable would have
to be able to optionally accept -a list- of dictionaries to internally
translate to English the keywords found in the input code and at most -
one- dictionary to internally translate from English output messages
such as a stack trace.

What do you guys think?


I would like anyone in the world to be able to use Python, and I would 
like Python programmers to potentially be able to potentially read any 
Python code and not have the community severely balkanized. To me, this 
would eventually mean both native keywords and tranliteration from other 
alphabets and scripts to latin chars. Not an easy project.


Terry Jan Reedy

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


Re: Can self crush itself?

2009-11-25 Thread Aahz
In article mailman.965.1259143133.2873.python-l...@python.org,
Chris Rebert  c...@rebertia.com wrote:

If you want to prevent an instance being created in the first place,
you can override __new__().

Or just raise an exception in __init__(), which I think is more common
practice.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.  
-- 
http://mail.python.org/mailman/listinfo/python-list


reposition a column

2009-11-25 Thread Francesco Pietra
Hi:

In a pdb file made of lines ATOM .. (see attachment as I was unable
to obtain plain text with gmail) I would like to reposition the second
W from column 19 to 17 ( (Python numbering; in pdb numbering it
would be 20 18). I started with bold slices, then I was unable to
complete the script. Much obliged for help.

francesco pietra
# Sample line
# Slice indexes cut to the left of the corrresponding item index
#   1 2 3 4 5 6
# 012345678901234567890123456789012345678901234567890123456789012345 ...
# ATOM  1  W W 1   0.690  35.960  33.300  1.00  0.00

data = open('out.2.5.2.5.2.0.pdb', 'r')
outp = open('rect.out.2.5.2.5.2.0.pdb', 'w')

for L in data:
   if L[19] == 'W':
 L = 
   outp.write(L)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating pipelines in python

2009-11-25 Thread Stefan Behnel
per, 25.11.2009 17:42:
 Thanks to all for your replies.  i want to clarify what i mean by a
 pipeline.  a major feature i am looking for is the ability to chain
 functions or scripts together, where the output of one script -- which
 is usually a file -- is required for another script to run.  so one
 script has to wait for the other.  i would like to do this over a
 cluster, where some of the scripts are distributed as separate jobs on
 a cluster but the results are then collected together.  so the ideal
 library would have easily facilities for expressing this things:
 script X and Y run independently, but script Z depends on the output
 of X and Y (which is such and such file or file flag).
 
 is there a way to do this? i prefer not to use a framework that
 requires control of the clusters etc. like Disco, but something that's
 light weight and simple. right now ruffus seems most relevant but i am
 not sure -- are there other candidates?

As others have pointed out, a Unix pipe approach might be helpful if you
want the processes to run in parallel. You can send the output of one
process to stdout, a network socket, an HTTP channel or whatever, and have
the next process read it and work on it while it's being generated by the
first process.

Looking into generators is still a good idea, even if you go for a pipe
approach. See the link posted by Wolodja Wentland.

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


confused with os.fork()

2009-11-25 Thread Sandy
Hi all,
I am a little bit confused about os.fork().
Say I have the following code.

import os
a = ['a','b','c','d','e']

for i in xrange(len(a)):
pid = os.fork()
if not pid:
print a[i]
os._exit(0)

From most of the tuts and examples I saw online, I expect it to print
a,b,c,d,e.
Sometimes (very rare) it prints something like this:
ab
c
d
e
I thought there is no way a parent process can enter the 'if'.
Can anyone explain this behaviour? Is it the case where parent is
forking a child even before the previous child is printing? In that
case is there a way to prevent that? I can use os.wait(), but I don't
want to wait till the child is finished, just don't want to mix the
child processes, that's it.

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


Re: confused with os.fork()

2009-11-25 Thread Diez B. Roggisch

Sandy schrieb:

Hi all,
I am a little bit confused about os.fork().
Say I have the following code.

import os
a = ['a','b','c','d','e']

for i in xrange(len(a)):
pid = os.fork()
if not pid:
print a[i]
os._exit(0)

From most of the tuts and examples I saw online, I expect it to print
a,b,c,d,e.
Sometimes (very rare) it prints something like this:
ab
c
d
e
I thought there is no way a parent process can enter the 'if'.
Can anyone explain this behaviour? Is it the case where parent is
forking a child even before the previous child is printing? In that
case is there a way to prevent that? I can use os.wait(), but I don't
want to wait till the child is finished, just don't want to mix the
child processes, that's it.


Yes, that's the case - you have a race-condition here. Two childs at the 
same time write, interleaving their data.


To prevent this, you can use file-locking.

http://docs.python.org/library/fcntl.html#fcntl.lockf

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


Re: Python OpenOffice Spreadsheets

2009-11-25 Thread bobicanprogram
On Nov 23, 5:49 am, Gerhard Häring g...@ghaering.de wrote:
 Is there a *simple* way to read OpenOffice spreadsheets?

 Bonus: write them, too?

 I mean something like:

 doc.cells[0][0] = foo
 doc.save(xyz.ods)

 From a quick look, pyodf offers little more than just using a XML parser

 directly.

 -- Gerhard


OO Calc has an HTML file feature for auto updating fields in a
spreadsheet.

I hacked together something for a talk a few years ago:

http://www.icanprogram.com/hosug

(See Open Office Calc demo section)
While it isn't Python code it should be easy enough to convert to
Python.

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


Re: reposition a column

2009-11-25 Thread MRAB

Francesco Pietra wrote:

Hi:

In a pdb file made of lines ATOM .. (see attachment as I was unable
to obtain plain text with gmail) I would like to reposition the second
W from column 19 to 17 ( (Python numbering; in pdb numbering it
would be 20 18). I started with bold slices, then I was unable to
complete the script. Much obliged for help.


I'm assuming that you want to put a space where the 'W' was.

L = L[ : 17] + L[19] + L[18] + ' ' + L[20 : ]

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


Re: reposition a column

2009-11-25 Thread Vlastimil Brom
2009/11/25 Francesco Pietra francesco.pie...@accademialucchese.it:
 Hi:

 In a pdb file made of lines ATOM .. (see attachment as I was unable
 to obtain plain text with gmail) I would like to reposition the second
 W from column 19 to 17 ( (Python numbering; in pdb numbering it
 would be 20 18). I started with bold slices, then I was unable to
 complete the script. Much obliged for help.

 francesco pietra

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


Hi,
using only string slices, you can probably do something like the
following (if I underestand the specification correctly, i.e. to swap
the two columns under the given condition).
An alternative is to swap the indices directly using list.
Also a regular expression replace with re.sub might be viable
(probably the shortest one)...

hth,
  vbr

##

scale =   1 2 3 4 5 6
012345678901234567890123456789012345678901234567890123456789012345
data_line = ATOM  1  W W 1   0.690  35.960  33.300  1.00  0.00

if data_line [19] == 'W':
output_line = data_line [0:17]+data_line [19]+data_line
[18]+data_line [17]+data_line [20:]
# alternatively
ch_19, ch_17 = data_line [19], data_line [17]
data_lst = list(data_line)
data_lst[17] = ch_19
data_lst[19] = ch_17
output_line_2 = .join(data_lst)
print output_line_2 == output_line

else:
output_line = data_line

print scale
print data_line
print scale
print output_line
print = * 66
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: confused with os.fork()

2009-11-25 Thread MRAB

Sandy wrote:

Hi all,
I am a little bit confused about os.fork().
Say I have the following code.

import os
a = ['a','b','c','d','e']

for i in xrange(len(a)):
pid = os.fork()
if not pid:
print a[i]
os._exit(0)


From most of the tuts and examples I saw online, I expect it to print

a,b,c,d,e.
Sometimes (very rare) it prints something like this:
ab
c
d
e
I thought there is no way a parent process can enter the 'if'.
Can anyone explain this behaviour? Is it the case where parent is
forking a child even before the previous child is printing? In that
case is there a way to prevent that? I can use os.wait(), but I don't
want to wait till the child is finished, just don't want to mix the
child processes, that's it.


The parent isn't entering the 'if' statement. os.fork() simply forks the
process and then both the parent and the child processes continue.

All of the child processes run independently and there's no guarantee as
to the order in which they'll print, and there's nothing to stop the
printouts from being mixed together (you would need to protect the
'print' with a mutex to do that).
--
http://mail.python.org/mailman/listinfo/python-list


Re: reading windows event logs

2009-11-25 Thread Mark Hammond

On 26/11/2009 7:22 AM, EW wrote:

Hi All,
  I'm looking for some guidance on a better way to read eventlogs
from windows servers.  I've written a handy little app that relies on
WMI to pull the logs an in all my testing it worked great.  When I
deployed it, however, WMI choked on servers with a lot of logs.  I've
tried pulling the logs using much smaller VB scripts as well and they
still failed, so I'm pretty sure I'm facing a WMI problem and not a
python or system resources problem.  So I couldn't effectively get
logs off of domain controllers for example or file servers that had
auditing turned on.  Sadly those are exactly the types of servers
whose logs are most interesting.

  So I'm looking for suggestions on a way to grab that data without
using WMI for remote machines.  I know MS has C libraries for this but
I haven't touched C for 10 years so I'm hoping there's a python
equivalent out there somewhere.  Any advice would be appreciated.


Look for the win32evtlog and win32evtlogutil modules which come with 
pywin32 (http://sf.net/projects/pywin32)


Cheers,

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


embed python dynamically

2009-11-25 Thread naveen
How do you embed the python dll file distributed with the automatic
installable python distribution on windows?
Is it possible to dynamically load the python dll from running c
program and start up a python interpreter ?
Do you have to compile python from source to be able to embed python?

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


High-performance Python websites

2009-11-25 Thread Nick Mellor
Hi all,

I'm contemplating setting up a Python-powered website for the tourist
industry, which will involve a web service, a good deal of XML
processing, and a Django-powered front-end. If the project works, it
could get a lot of traffic. I'm sure it can be done, but I'm looking
to find out more about how existing high-volume Python sites have
managed their workload. Can anyone give me examples of high-volume
Python-powered websites, if possible with some idea of their
architecture?

Many thanks,

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


Re: Python 3.1 cx_Oracle 5.0.2 ImportError: DLL load failed: The specified module could not be found.

2009-11-25 Thread André
On Nov 19, 6:57 pm, Neil Hodgson nyamatongwe+thun...@gmail.com
wrote:
 André:

  Apparently the error is caused by cx_Oracle not being able to find the
  Oracle client DLLs (oci.dll and others). The client home path and the
  client home path bin directory are in the PATH System Variable and
  oci.dll is there.

    Open the cx_Oracle extension with Dependency Walker
 (http://www.dependencywalker.com/) to get a better idea about what the
 problem is in more detail.

    Neil

Thanks Neil. I used Dependency Walker and discovered cx_Oracle was
looking for python30.dll. I seems to be a known issue with Python 3.1
http://bugs.python.org/issue4091. I'm now used Python 2.6.4 and the
corresponding cx_Oracle version with no problems.

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


Re: High-performance Python websites

2009-11-25 Thread ShoqulKutlu
Hi,

Managing load of high volume of visitors is a common issue for all
kind of web technologies. I mean this is not the python issue. This
issue is mostly about server level designs. You need to supply load
balancing for both web servers and databases to make your web site
able to respond to several concurrent visitors. Of course a good
programmed website is a key performance issue but for your mention I
would also suggest considering how many hardwares, how many
webservers, how many database cluster and which database server should
be used or will be used in the future..

Regards,
Kutlu

On Nov 26, 2:24 am, Nick Mellor nick.mellor.gro...@pobox.com wrote:
 Hi all,

 I'm contemplating setting up a Python-powered website for the tourist
 industry, which will involve a web service, a good deal of XML
 processing, and a Django-powered front-end. If the project works, it
 could get a lot of traffic. I'm sure it can be done, but I'm looking
 to find out more about how existing high-volume Python sites have
 managed their workload. Can anyone give me examples of high-volume
 Python-powered websites, if possible with some idea of their
 architecture?

 Many thanks,

 Nick

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


Re: Can self crush itself?

2009-11-25 Thread n00m
 Or just raise an exception in __init__(),..

Then we are forced to handle this exception outside of class code.
It's Ok. Never mind.


Next thing.
I can't understand why we can get __name__, but not __dict__,
on the module level?


print __name__
print __dict__


 = RESTART 

__main__

Traceback (most recent call last):
  File D:\Python25\zewrt.py, line 19, in module
print __dict__
NameError: name '__dict__' is not defined

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


Re: embed installed python dynamically

2009-11-25 Thread naveen
ok, it was almost intuitive.
just made a simple visual c express dll project
included python26\include and python26\libs in the project settings
the debug version has issues, but the release compiles without a
problem.
here is the source:
http://github.com/tinku99/embedpython
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can self crush itself?

2009-11-25 Thread Terry Reedy

n00m wrote:

Or just raise an exception in __init__(),..


Then we are forced to handle this exception outside of class code.
It's Ok. Never mind.


Next thing.
I can't understand why we can get __name__, but not __dict__,
on the module level?


print __name__
print __dict__


If the global namespace contained itself, as a dict, there would be an 
infinite loop.


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


jython and java application

2009-11-25 Thread KB
Hi there,

Apologies if this is on the wrong group, this is a jython question.
Please redirect me to the correct group if this is in error.

I have a java application that takes no arguements. When I run it, it
spits out output, and finishes.

I am trying to run this java application from jython 2.5.1, JRE6.

I have made simple Hello World java classes be callable from a
simple jython script, yet I am stumbling on the java main construct in
the application.

print krbtest.SimpleHistoricTutorial().main() obviously gives me an
args error (expected 1, got 0) as the definition in the java
application is:

public static void main(String[] args)

The jython code is as follows:
import krbtest

# was messing with this to pass a java formatted string but to no
avail

from java.lang import String

print krbtest.SimpleHistoricTutorial().main()

#

Any advice greatly appreciated! Especially with how to call main()
with arguments from jython.

Apologies in advance again if this is the wrong group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: jython and java application

2009-11-25 Thread MRAB

KB wrote:

Hi there,

Apologies if this is on the wrong group, this is a jython question.
Please redirect me to the correct group if this is in error.

I have a java application that takes no arguements. When I run it, it
spits out output, and finishes.

I am trying to run this java application from jython 2.5.1, JRE6.

I have made simple Hello World java classes be callable from a
simple jython script, yet I am stumbling on the java main construct in
the application.

print krbtest.SimpleHistoricTutorial().main() obviously gives me an
args error (expected 1, got 0) as the definition in the java
application is:

public static void main(String[] args)

The jython code is as follows:
import krbtest

# was messing with this to pass a java formatted string but to no
avail

from java.lang import String

print krbtest.SimpleHistoricTutorial().main()

#

Any advice greatly appreciated! Especially with how to call main()
with arguments from jython.

Apologies in advance again if this is the wrong group.


I don't know jython, but from the look of it I'd say that you need to
give main() some kind of argument, such as a string or an empty list.
(If you pass an empty jython list to a Java method that's expecting an
array of String, will the Java method receive a zero-length array of
String?).
--
http://mail.python.org/mailman/listinfo/python-list


Re: jython and java application

2009-11-25 Thread ShoqulKutlu
I don't know if it's right place but normally main method requires an
args even it is not needed to supply from commandline. Maybe this is a
jython runtime error and requires at least an empty argument. You
could try to pass and empty string array like ['']. I'm not using
jython please use your own notation.

Regards,
Kutlu

On Nov 26, 3:30 am, KB ke...@nekotaku.com wrote:
 Hi there,

 Apologies if this is on the wrong group, this is a jython question.
 Please redirect me to the correct group if this is in error.

 I have a java application that takes no arguements. When I run it, it
 spits out output, and finishes.

 I am trying to run this java application from jython 2.5.1, JRE6.

 I have made simple Hello World java classes be callable from a
 simple jython script, yet I am stumbling on the java main construct in
 the application.

 print krbtest.SimpleHistoricTutorial().main() obviously gives me an
 args error (expected 1, got 0) as the definition in the java
 application is:

 public static void main(String[] args)

 The jython code is as follows:
 import krbtest

 # was messing with this to pass a java formatted string but to no
 avail

 from java.lang import String

 print krbtest.SimpleHistoricTutorial().main()

 #

 Any advice greatly appreciated! Especially with how to call main()
 with arguments from jython.

 Apologies in advance again if this is the wrong group.

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


Re: embed installed python dynamically

2009-11-25 Thread naveen
ok, its even easier than that.
With autohotkey:

pythondll := DllCall(LoadLibrary, str, c:\windows
\system32\python26.dll)
init := DllCall(c:\windows\system32\python26.dll\Py_Initialize
, Cdecl)
msgbox python initalized
call := DllCall(c:\windows\system32\python26.dll\PyRun_SimpleString
, str, import sys, Cdecl)
msgbox will exit using python code
call := DllCall(c:\windows\system32\python26.dll\PyRun_SimpleString
, str, sys.exit(0), Cdecl)
init := DllCall(c:\windows\system32\python26.dll\Py_Finalize
, Cdecl)
msgbox % never called
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can self crush itself?

2009-11-25 Thread Steven D'Aprano
On Wed, 25 Nov 2009 20:09:25 -0500, Terry Reedy wrote:

 n00m wrote:
 Or just raise an exception in __init__(),..
 
 Then we are forced to handle this exception outside of class code. It's
 Ok. Never mind.
 
 
 Next thing.
 I can't understand why we can get __name__, but not __dict__, on the
 module level?
 
 
 print __name__
 print __dict__
 
 If the global namespace contained itself, as a dict, there would be an
 infinite loop.


Why would that be a problem?  Any time you do this:

 g = globals()


you create such a recursive reference:

 globals()['g']['g']['g']['g'] is globals() is g
True


Yes, there's a tiny bit extra work needed when bootstrapping the 
processes, and when exiting, but I don't see why it's a big deal. Whether 
it's necessary or useful is another story.



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


Feature request: String-inferred names

2009-11-25 Thread The Music Guy
Hello all,

I just posted to my blog about a feature that I'd like to see added to
Python. Before I go through the trouble of learning how to write a PEP or
how to extend the Python interpreter, I want to know what people in the
community have to say about it.

http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html

As far as I know, a feature like this does not appear in any existing PEPs.
(If it does I would appreciate it if someone could tell me what PEP it is.)

Please give and comments you may have, but I request that you be
constructive if you must criticize...thank you!

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


Help with error on self.show

2009-11-25 Thread Christian Grise
Hi,

I am getting an error when I try to run some code my friend gave me. Here is
the error:

Warning (from warnings module):
  File C:\Documents and Settings\GriseC\Desktop\Widget Base\applet.py,
line 145
self.show()
GtkWarning: ../../../../gtk+/gdk/win32/gdkwindow-win32.c:1089: SetWindowLong
failed: Not enough storage is available to process this command.

If anyone knows what this means, any info would be greatly appreciated.

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


Re: Can self crush itself?

2009-11-25 Thread n00m

aaah... globals()...
Then why self not in globals()?

class Moo:
cnt = 0
def __init__(self, x):
self.__class__.cnt += 1
if self.__class__.cnt  3:
self.x = x
else:
print id(self)
for item in globals().items():
print item

f = Moo(1)
g = Moo(2)
h = Moo(3)


 = RESTART 

13407336
('g', __main__.Moo instance at 0x00CC9260)
('f', __main__.Moo instance at 0x00CC9440)
('__builtins__', module '__builtin__' (built-in))
('Moo', class __main__.Moo at 0x00CCC060)
('__name__', '__main__')
('__doc__', None)

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


Re: Feature request: String-inferred names

2009-11-25 Thread The Music Guy
I just posted to my blog about a feature that I'd like to see added to
Python. Before I go through the trouble of learning how to write a PEP or
how to extend the Python interpreter, I want to know what people in the
community have to say about it.

http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html

As far as I know, a feature like this does not appear in any existing PEPs.
(If it does I would appreciate it if someone could tell me what PEP it
is.)Please give and comments you may have, but I request that you be
constructive if you must criticize...thank you!

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


Re: jython and java application

2009-11-25 Thread KB

Hmmm, for some reason my follow up post didn't make it.

Modified jython script to:

# Eclipse package name for java application
import krbtest

import java.lang as lang
from java.lang import String
from jarray import array

myargs=array([],String)

krbtest.SimpleHistoricTutorial().main(myargs)


Now I get:

Traceback (most recent call last):
  File test.py, line 15, in module
krbtest.SimpleHistoricTutorial().main(myargs)
at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)

at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
22)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)


java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
bloomberglp/blpapi/Session


I would post the java app but its quite large, but the main defn:

public static void main(String[] args) throws Exception
{
SimpleHistoricTutorial example = new SimpleHistoricTutorial();
example.run();
}


Is pretty vanilla. I have tried making the run() a public method and
call it, all to no avail.

Note, the Java app works fine standalone, I just need to call it from
jython.

Again, any help appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: jython and java application

2009-11-25 Thread ShoqulKutlu
Hi,

I don't know how do you call the java library from within your jython
application it gives java.lang.NoClassDefFoundError
This looks like you referenced jar or whatever else from your jython
application which also needs a class com/bloomberglp/blpapi/Session
in another library file. It might run while running standalone because
the dependent libraries exists where it looks for. For your jython
application you need to make krbtest referenced to the dependent
libraries. It seems you application took a copy of krbtest and other
libraries not available to krbtest there. I hope it helps.

Regards,
Kutlu



On Nov 26, 4:49 am, KB ke...@nekotaku.com wrote:
 Hmmm, for some reason my follow up post didn't make it.

 Modified jython script to:

 # Eclipse package name for java application
 import krbtest

 import java.lang as lang
 from java.lang import String
 from jarray import array

 myargs=array([],String)

 krbtest.SimpleHistoricTutorial().main(myargs)
 

 Now I get:

 Traceback (most recent call last):
   File test.py, line 15, in module
     krbtest.SimpleHistoricTutorial().main(myargs)
         at krbtest.SimpleHistoricTutorial.run(SimpleHistoricTutorial.java:27)

         at krbtest.SimpleHistoricTutorial.main(SimpleHistoricTutorial.java:
 22)

         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

         at java.lang.reflect.Method.invoke(Unknown Source)

 java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: com/
 bloomberglp/blpapi/Session

 I would post the java app but its quite large, but the main defn:

         public static void main(String[] args) throws Exception
         {
                 SimpleHistoricTutorial example = new SimpleHistoricTutorial();
                 example.run();
         }

 Is pretty vanilla. I have tried making the run() a public method and
 call it, all to no avail.

 Note, the Java app works fine standalone, I just need to call it from
 jython.

 Again, any help appreciated.

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


Re: Can self crush itself?

2009-11-25 Thread Steven D'Aprano
On Wed, 25 Nov 2009 18:39:09 -0800, n00m wrote:

 aaah... globals()...
 Then why self not in globals()?
 
 class Moo:
 cnt = 0
 def __init__(self, x):
 self.__class__.cnt += 1


Because it isn't a global, it's a local -- it is defined inside a class. 
Inside functions and classes, names you create are local, not global, 
unless you declare them global.




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


Re: Can self crush itself?

2009-11-25 Thread Mel
n00m wrote:

 
 aaah... globals()...
 Then why self not in globals()?
 
 class Moo:
 cnt = 0
 def __init__(self, x):
 self.__class__.cnt += 1
 if self.__class__.cnt  3:
 self.x = x
 else:
 print id(self)
 for item in globals().items():
 print item
 
 f = Moo(1)
 g = Moo(2)
 h = Moo(3)

Because self is not in globals().

It's defined as a local symbol in Moo.__init__ , supplied to that function 
as the first parameter.

Mel.


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


How do I correctly download Wikipedia pages?

2009-11-25 Thread Steven D'Aprano
I'm trying to scrape a Wikipedia page from Python. Following instructions 
here:

http://en.wikipedia.org/wiki/Wikipedia:Database_download
http://en.wikipedia.org/wiki/Special:Export

I use the URL http://en.wikipedia.org/wiki/Special:Export/Train; instead 
of just http://en.wikipedia.org/wiki/Train;. But instead of getting the 
page I expect, and can see in my browser, I get an error page:


 import urllib
 url = http://en.wikipedia.org/wiki/Special:Export/Train;
 print urllib.urlopen(url).read()
...
Our servers are currently experiencing a technical problem. This is 
probably temporary and should be fixed soon
...


(Output is obviously truncated for your sanity and mine.)


Is there a trick to downloading from Wikipedia with urllib?



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


Re: How do I correctly download Wikipedia pages?

2009-11-25 Thread ShoqulKutlu
Hi,

Try not to be caught if you send multiple requests :)

Have a look at here: http://wolfprojects.altervista.org/changeua.php

Regards
Kutlu

On Nov 26, 5:45 am, Steven D'Aprano
ste...@remove.this.cybersource.com.au wrote:
 I'm trying to scrape a Wikipedia page from Python. Following instructions
 here:

 http://en.wikipedia.org/wiki/Wikipedia:Database_downloadhttp://en.wikipedia.org/wiki/Special:Export

 I use the URL http://en.wikipedia.org/wiki/Special:Export/Train; instead
 of just http://en.wikipedia.org/wiki/Train;. But instead of getting the
 page I expect, and can see in my browser, I get an error page:

  import urllib
  url = http://en.wikipedia.org/wiki/Special:Export/Train;
  print urllib.urlopen(url).read()

 ...
 Our servers are currently experiencing a technical problem. This is
 probably temporary and should be fixed soon
 ...

 (Output is obviously truncated for your sanity and mine.)

 Is there a trick to downloading from Wikipedia with urllib?

 --
 Steven

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


Re: How do I correctly download Wikipedia pages?

2009-11-25 Thread Stephen Hansen
2009/11/25 Steven D'Aprano ste...@remove.this.cybersource.com.au

 I'm trying to scrape a Wikipedia page from Python. Following instructions
 here:


Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?

Its not just via urllib, but I've scraped several MediaWiki-based sites with
the software successfully.

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


Re: How do I correctly download Wikipedia pages?

2009-11-25 Thread Taskinoor Hasan
I fetched a different problem. Whenever I tried to fetch any page from
wikipedia, I received 403. Then I found that wikipedia don't accept the
default user-agent (might be python-urllib2.x or something like this). After
setting my own user-agent, it worked fine. You can try this if you receive
403.

On Thu, Nov 26, 2009 at 10:04 AM, Stephen Hansen apt.shan...@gmail.comwrote:



 2009/11/25 Steven D'Aprano ste...@remove.this.cybersource.com.au

 I'm trying to scrape a Wikipedia page from Python. Following instructions
 here:


 Have you checked out http://meta.wikimedia.org/wiki/Pywikipediabot?

 Its not just via urllib, but I've scraped several MediaWiki-based sites
 with the software successfully.

 --S

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


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


Re: Feature request: String-inferred names

2009-11-25 Thread Chris Rebert
On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
fearsomedragon...@gmail.com wrote:
 Hello all,

 I just posted to my blog about a feature that I'd like to see added to
 Python. Before I go through the trouble of learning how to write a PEP or
 how to extend the Python interpreter, I want to know what people in the
 community have to say about it.

 http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html

 As far as I know, a feature like this does not appear in any existing PEPs.
 (If it does I would appreciate it if someone could tell me what PEP it is.)

 Please give and comments you may have, but I request that you be
 constructive if you must criticize...thank you!

Ugly, Perlish, and as you even admit, entirely unnecessary.
And you'd need to wait at least a year anyway:
http://www.python.org/dev/peps/pep-3003/

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: High-performance Python websites

2009-11-25 Thread Nick Mellor
Thanks Kutlu,

I wasn't aware that Google used Python for running their Google groups
servers. Can you confirm that? The only place
I've seen Google explicitly use Python on their web front end is in
the Google Ads tests.

I am impressed by the responsiveness of lawrence.com, ljworld.com and
others on the Django home page (http://www.djangoproject.com/)

They seem to do a great job of loading large, complex pages using
Django (stacked on Python, stacked on bytecode, stacked on C.)
Shows it can be done.

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


Re: Feature request: String-inferred names

2009-11-25 Thread Brad
On Nov 25, 10:49 pm, Chris Rebert c...@rebertia.com wrote:
 On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy

 fearsomedragon...@gmail.com wrote:
  Hello all,

  I just posted to my blog about a feature that I'd like to see added to
  Python. Before I go through the trouble of learning how to write a PEP or
  how to extend the Python interpreter, I want to know what people in the
  community have to say about it.

 http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...

  As far as I know, a feature like this does not appear in any existing PEPs.
  (If it does I would appreciate it if someone could tell me what PEP it is.)

  Please give and comments you may have, but I request that you be
  constructive if you must criticize...thank you!

 Ugly, Perlish, and as you even admit, entirely unnecessary.
 And you'd need to wait at least a year 
 anyway:http://www.python.org/dev/peps/pep-3003/

 Cheers,
 Chris
 --http://blog.rebertia.com

Like I said, lots of things in Python are unnecessary, but that
doesn't make them useless, and it certainly doesn't mean they
shouldn't exist. My proposed feature is not useless; I think it would
make a lot of code easier.

As for it being ugly...well, that's really a matter of opinion and
experience. How ugly it looks to you will be a product of how well you
think it can be used, and how well you use it yourself. When I first
looked at decorators, I thought they were not only ugly but confusing.
Now that I understand them, however, I hardly consider them ugly,
and see them as a shining example of Python's abilities. (By the way,
decorators are another example of a feature that is entirely
unnecessary, but still very useful.)

As for the wait, that's to be expected. I'm willing to wait.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature request: String-inferred names

2009-11-25 Thread The Music Guy
P.S., my apologies for sending replies with different email addresses. This
is an unintentional technical issue and I am currently trying to get it
fixed.

On Wed, Nov 25, 2009 at 11:45 PM, Brad themusicguy...@gmail.com wrote:

 On Nov 25, 10:49 pm, Chris Rebert c...@rebertia.com wrote:
  On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy
 
  fearsomedragon...@gmail.com wrote:
   Hello all,
 
   I just posted to my blog about a feature that I'd like to see added to
   Python. Before I go through the trouble of learning how to write a PEP
 or
   how to extend the Python interpreter, I want to know what people in the
   community have to say about it.
 
  http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor.
 ..
 
   As far as I know, a feature like this does not appear in any existing
 PEPs.
   (If it does I would appreciate it if someone could tell me what PEP it
 is.)
 
   Please give and comments you may have, but I request that you be
   constructive if you must criticize...thank you!
 
  Ugly, Perlish, and as you even admit, entirely unnecessary.
  And you'd need to wait at least a year anyway:
 http://www.python.org/dev/peps/pep-3003/
 
  Cheers,
  Chris
  --http://blog.rebertia.com

 Like I said, lots of things in Python are unnecessary, but that
 doesn't make them useless, and it certainly doesn't mean they
 shouldn't exist. My proposed feature is not useless; I think it would
 make a lot of code easier.

 As for it being ugly...well, that's really a matter of opinion and
 experience. How ugly it looks to you will be a product of how well you
 think it can be used, and how well you use it yourself. When I first
 looked at decorators, I thought they were not only ugly but confusing.
 Now that I understand them, however, I hardly consider them ugly,
 and see them as a shining example of Python's abilities. (By the way,
 decorators are another example of a feature that is entirely
 unnecessary, but still very useful.)

 As for the wait, that's to be expected. I'm willing to wait.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: High-performance Python websites

2009-11-25 Thread ShoqulKutlu
Hi Nick,

Sorry about my concern on Google. It caused a confusion about Google
groups. I didn't mean explicitly where Google uses python, I mentioned
just Google uses Python. A Google officer told that they run Python on
thousands of their servers at an interview. Due to this claim I wanted
to say it for you.
Actualy of course it can be done and even it will not be worse than
any other frameworks, and I bet can be better than Java and ASP.NET if
configured and programmed well. I really encourage you to use
mod_python for any project. Mod_python and mod_wsgi made it very
powerful at web side. As I said in my previous message a web
application's responsiveness is dependent to several issues. A good
web framework, server speed, database design etc.. In this case you
want to use django, which as I know build for mod_python and can be
configured to run on a mod_wsgi web server. Consider that you will
have one million members on your site. That traffic simply needs
several clustered web servers and clustered databases. This means you
supply a load balancing. So concurrent user sessions will be shared on
different web servers. You can do your best with such a clustered
system with such a powerful language. Really don't worry about that.

Regards,
Kutlu

On Nov 26, 7:21 am, Nick Mellor nick.mellor.gro...@pobox.com wrote:
 Thanks Kutlu,

 I wasn't aware that Google used Python for running their Google groups
 servers. Can you confirm that? The only place
 I've seen Google explicitly use Python on their web front end is in
 the Google Ads tests.

 I am impressed by the responsiveness of lawrence.com, ljworld.com and
 others on the Django home page (http://www.djangoproject.com/)

 They seem to do a great job of loading large, complex pages using
 Django (stacked on Python, stacked on bytecode, stacked on C.)
 Shows it can be done.

 Nick

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


Re: High-performance Python websites

2009-11-25 Thread ShoqulKutlu
Hi again,

I also want to say something about creating a better web application.
If I were you I wouldn't use any web framework like django or other.
If you want to create a commercial project and want to manage all
modules of the application yourself I suggest you to create your own
framework. I don't mean create a Django like framework. Determine your
needs, modules, services and build your own modules. Use other
independent open source modules for any specific issues. To make a
successful project requires your own business logic. And you can do
this with your own algorithm. Don't avoid collecting other modules for
templating, xml parsing, DB connectivity issues. But build your own
framework with these and your own modules..

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


Re: Feature request: String-inferred names

2009-11-25 Thread Gabriel Genellina
En Wed, 25 Nov 2009 23:35:06 -0300, The Music Guy  
fearsomedragon...@gmail.com escribió:



I just posted to my blog about a feature that I'd like to see added to
Python. Before I go through the trouble of learning how to write a PEP or
how to extend the Python interpreter, I want to know what people in the
community have to say about it.

http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html

As far as I know, a feature like this does not appear in any existing  
PEPs.
(If it does I would appreciate it if someone could tell me what PEP it  
is.)


Already suggested, and rejected; see PEP 363:  
http://www.python.org/dev/peps/pep-0363/ and the python-dev discussion.


--
Gabriel Genellina

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


Re: Feature request: String-inferred names

2009-11-25 Thread Lie Ryan

Brad wrote:

On Nov 25, 10:49 pm, Chris Rebert c...@rebertia.com wrote:

On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy

fearsomedragon...@gmail.com wrote:

Hello all,
I just posted to my blog about a feature that I'd like to see added to
Python. Before I go through the trouble of learning how to write a PEP or
how to extend the Python interpreter, I want to know what people in the
community have to say about it.
http://alphaios.blogspot.com/2009/11/python-string-inferred-names-wor...
As far as I know, a feature like this does not appear in any existing PEPs.
(If it does I would appreciate it if someone could tell me what PEP it is.)
Please give and comments you may have, but I request that you be
constructive if you must criticize...thank you!

Ugly, Perlish, and as you even admit, entirely unnecessary.
And you'd need to wait at least a year 
anyway:http://www.python.org/dev/peps/pep-3003/

Cheers,
Chris
--http://blog.rebertia.com


Like I said, lots of things in Python are unnecessary, but that
doesn't make them useless, and it certainly doesn't mean they
shouldn't exist. My proposed feature is not useless; I think it would
make a lot of code easier.


How is it easier than using dictionary with string as keys? setattr, 
getattr, and delattr are already sugar for accessing instance.__dict__.


You make a comparison with decorators; even if it's unnecessary it does 
eliminate a DRY case (don't repeat yourself):

def foo(self): pass
foo = property(foo)

there you repeat foo three times unnecessarily, instead of:
@property
def foo(self): pass

people already bashed decorator syntax because it is ungoogleable; a 
non-python programmer reading a python code can't google python @ to 
find out that it's a decorator. $ has very similar problem; and we don't 
want to add more of this wart.


You also make with iterators and generators. Iterator and generator is 
an implication of the core design of python; because python chose not to 
have a for-loop (python's for-loop is actually a for-each-loop). 
Without the iterator protocol, it is not possible to make an iterable 
class and people would have to use for x in range(len(foo)): every so 
often. Iterator protocol also makes it possible to have infinite 
iterable (e.g. for x in primegenerator(): produces prime numbers 
indefinitely).


A list comprehension is space saver; it saves a lot of lines for the 
very common operation:


a = []
for x in orig:
if test(x):
a.append(transform(x))

into one concise line:
a = [transform(x) for x in orig if test(x)]

Also a generator comprehension can be passed around without being evaluated.

As you see, these unnecessary features does have significant benefits 
to it. Decorators reduced DRY, iterators/generators eliminates the need 
of range-len for-loop, list comprehension is huge space saver.


The proposed syntax only saves a few character, does not eliminate any 
DRY, is ungoogleable, and looks confusing to me. Is there any 
significant benefit from it?

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


Re: Can self crush itself?

2009-11-25 Thread Gregory Ewing

n00m wrote:


I can't understand why we can get __name__, but not __dict__,
on the module level?


For much the same reason that you can see your own
feet but (unless you look in a mirror) you can't
see your own eyes.

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


Re: Feature request: String-inferred names

2009-11-25 Thread Gregory Ewing

On Wed, 25 Nov 2009 20:44:36 -0600, The Music Guy
music...@alphaios.net declaimed the following in
gmane.comp.python.general:


I just posted to my blog about a feature that I'd like to see added to
Python.

http://alphaios.blogspot.com/2009/11/python-string-inferred-names-working.html


I don't think getattr and setattr are used anywhere near
frequently enough to justify special syntax.

To warrant having its own synax, a feature needs to be
used *all the time*. If you find yourself using getattr
and setattr that much, it's probably a symptom that
you're abusing namespaces for things that would be
better done using dictionaries.

(A frequent question asked by newcomers from certain
other kinds of languages is something like How do I
assign to a variable whose name is in another variable?
The answer is almost always Don't do that, use a
dictionary.)

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


[issue7117] Backport py3k float repr to trunk

2009-11-25 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Thanks, Eric.

The only remaining documentation issues I'm aware of are in 
Doc/tutorial/floatingpoint.rst.  I think Raymond is going to update this 
to match the py3k version.

I'll call this done, then!  Thanks for all your help.

--
resolution:  - accepted
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7117
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1606092] csv module broken for unicode

2009-11-25 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

This is indeed fixed in Python 3.  If someone wishes to step forward
with patches for 2.7, they can reopen this bug, but I don't think it is
worth the effort.

--
nosy: +r.david.murray
resolution:  - out of date
stage:  - committed/rejected
status: open - closed
type:  - feature request

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1606092
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6615] multiprocessing logging support test

2009-11-25 Thread Vinay Sajip

Vinay Sajip vinay_sa...@yahoo.co.uk added the comment:

 Since you reversed() the _handlerList, the following part need to be

 changed:
 
 -_handlerList.insert(0, weakref.ref(handler, _removeHandlerRef))
 +_handlerList.append(weakref.ref(handler, _removeHandlerRef))

Corrected in r76509. Florent, thanks for catching this (and for the patch).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6615
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7394] sqlite3: some OperationalError exceptions should be ProgrammingError (PEP 249)

2009-11-25 Thread dontbugme

New submission from dontbugme pythonbugsbugme...@spamavert.com:

The following code raises OperationalError exceptions:
python -c 'import sqlite3; sqlite3.connect(:memory:).execute(bad
syntax)'
python -c 'import sqlite3; sqlite3.connect(:memory:).execute(SELECT *
FROM no_such_table)'
python -c 'import sqlite3; sqlite3.connect(:memory:).execute(SELECT
no_such_column)'

But ProgrammingError should be raised, as per PEP 249:

ProgrammingError
  
Exception raised for programming errors, e.g. table not
found or already exists, syntax error in the SQL
statement, wrong number of parameters specified, etc.  It
must be a subclass of DatabaseError.

--
components: Library (Lib)
messages: 95719
nosy: dontbugme
severity: normal
status: open
title: sqlite3: some OperationalError exceptions should be ProgrammingError 
(PEP 249)
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7391] Re-title the Using Backslash to Continue Statements anti-idiom

2009-11-25 Thread Neil Cerutti

Neil Cerutti ceru...@trans-video.net added the comment:

Yes, I know. That's why I feel it should not be labeled an anti-idiom,
as it currently seems to be.

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7391
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7391] Re-title the Using Backslash to Continue Statements anti-idiom

2009-11-25 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Agreed.

--
priority:  - low
resolution: wont fix - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7391
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4097] Traceback doesn't run back all the way

2009-11-25 Thread flox

flox la...@yahoo.fr added the comment:

It looks similar to issue7378, but the latter has more details.

Close as duplicate?

--
nosy: +flox

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4097
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4158] compilation of sqlite3 fails

2009-11-25 Thread flox

flox la...@yahoo.fr added the comment:

Please close as invalid.

--
nosy: +flox

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4158
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4158] compilation of sqlite3 fails

2009-11-25 Thread flox

Changes by flox la...@yahoo.fr:


--
nosy:  -flox

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4158
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >