Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Paul Kölle

Am 06.04.2014 09:25, schrieb Gary Herron:

On 04/05/2014 11:53 PM, John Ladasky wrote:

I find this programming pattern to be useful... but can it cause
problems?

No.

What kind of problems are you considering?  It won't break Python. It's
perfectly legal code.

The tuple c is still immutable, consisting of two specific objects, and
(as always) without regard to the specifics or contents of those two
objects.
It seems a tuple's immutability is debatable, or is this another 
instance of the small-integer-reuse-implementation-detail-artifact?


Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type help, copyright, credits or license for more information.
 a = ([1,2],[3,4])
 b = a
 a is b
True
 a == b
True
 c = (1,2,3)
 d = (1,2,3)
 c is d
False
 c == d
True

cheers
 Paul
--
https://mail.python.org/mailman/listinfo/python-list


Re: Mutable objects inside tuples - good or bad?

2014-04-07 Thread Paul Kölle

Am 07.04.2014 17:44, schrieb Chris Angelico:

On Tue, Apr 8, 2014 at 1:26 AM, Paul Kölle pkoe...@gmail.com wrote:

It seems a tuple's immutability is debatable, or is this another instance of
the small-integer-reuse-implementation-detail-artifact?

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2

Type help, copyright, credits or license for more information.

a = ([1,2],[3,4])
b = a
a is b

True

a == b

True

c = (1,2,3)
d = (1,2,3)
c is d

False

c == d

True


That's nothing to do with mutability or reuse. With a and b, you
assigned one to be the same as the other, so they are by definition
identical (and equal; tuples assume that identity implies equality,
even though that may not be true of their elements). With c and d, you
assigned separate tuples, so they're allowed to be separate objects.
I'm not sure if they're allowed to be constant-folded, but CPython
apparently isn't doing so. They are still equal, though; they contain
equal elements, ergo they are equal. (Note that (1, 2, 3) and (1.0,
2.0, 3.0) are equal, but they obviously can't be identical any more
than 1 is 1.0 can ever be True.)

ChrisA


Thanks Chris, stupid error indeed ;)

cheers
 Paul


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


Re: Kivy for Python 3.3

2013-07-12 Thread Paul Kölle

Am 11.07.2013 16:26, schrieb fronag...@gmail.com:
[scnipp]

C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python33\include
-IC:\Python33\include -c kivy\graphics\vertex_instructions.c -o
build\temp.win32-3.3\Release\kivy\grap hics\vertex_instructions.o In
file included from kivy\graphics\vertex_instructions.c:314:0:
kivy\graphics\/gl_redirect.h:8:22: fatal error: GL/glew.h: No such
file or direc tory compilation terminated. error: command 'gcc'
failed with exit status 1

Working on the reasoning that sticking the missing file into the
python3.3\libs file worked, I tried adding the glew files
(glew32.dll, glew32.lib, GL\glew and GL\wglew.h) there, however, it
doesn't seem to have made a difference. And this I googled this
before asking. Doesn't seem to be much.


Hi,

I can feel your pain beeing dragged into 
compile-unknown-source-on-windows from an innocent looking python script 
;) This time it's not the linker complaining but GCC (the compiler) 
itself not being able to find the header file GL/glew.h. Headers are 
searched in the so called include path which is specified in setup.py. 
This link http://glew.sourceforge.net/install.html suggests glew.h is 
part of VisualStudio, and has some other interesting information.


hth
 Paul




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


Re: Kivy for Python 3.3

2013-07-11 Thread Paul Kölle

Am 11.07.2013 11:09, schrieb fronag...@gmail.com:

Hello, first time poster here, and general newbie to Python.

I'm looking to write a program in Python, (and have in fact written
most of it by now,) and am trying to put together a GUI for it. Kivy
looks very nice, particularly with the fact that it's supposed to be
compatible with most platforms (including Android, which I would like
to be able to use my program on in addition to running it on my
desktop) with minimal hassle. However, its current iteration is
Python 2.7 only, and I've only learned Python 3.3.

[ snipp ]

C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe:
cannot fin d -lmsvcr100 collect2: ld returned 1 exit status error:
command 'gcc' failed with exit status 1


It might help copying msvcr100.dll (from MS VC++ Redistributable 
Package) to c:\python33\libs (or wherever your python install is). See 
http://bugs.python.org/issue15315 msg191106


hth
 Paul


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


Re: Apache and suexec issue that wont let me run my python script

2013-06-02 Thread Paul Kölle

Am 01.06.2013 07:30, schrieb Νικόλαος Κούρας:
[snipp]



[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] suexec failure: could 
not open log file
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] Premature end of script 
headers: koukos.py
[Thu May 30 15:29:33 2013] [error] [client 46.12.46.11] File does not exist: 
/home/nikos/public_html/500.shtml

when i tail -F /usr/local/apache/logs/error_log 

What this error means?

It appears that the effective user of the script does not have permission to 
open the log file
that the suexec call requires.
Yes, so which logfile and what user is suexec using to run your script? 
You should be able to answer all this from your apache configuration.


cheers
 Paul



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


Re: accessing an OLE Automation (IDispatch) server from python which requires the use of out params

2012-12-11 Thread Paul Kölle

Hi,

Am 10.12.2012 20:13, schrieb bitbucket:

I have an existing Windows application which provides an OLE
Automation (IDispatch) interface.  I'm not able to change that
interface.  I'd like to call it from a scripting language.  I figure
this would provide a nice quick way to invoke on the app.

I initially tried this with Windows Powershell but ran into the
following problem.  I was able to create the object and invoke simple
methods on it.  However the interface for this app has methods which
take out params.  i.e. you pass in a reference to a variable and the
server fills in the value.  I couldn't get that to work.  I finally
gave up and decided it was just a limitation of Powershell, not being
able to work with those out params.


[snipp]
Before switching technologies I'd check if this solves your problem 
http://geekswithblogs.net/Lance/archive/2009/01/14/pass-by-reference-parameters-in-powershell.aspx 



TL;DR IMHO out parameters are basically pointers (pass by reference) 
and need to be passed like GetSettingValue(name, [ref]$value)...


cheers
 Paul

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


Re: Help accessing COM .dll from Python

2012-12-01 Thread Paul Kölle

Hi,

Am 01.12.2012 10:51, schrieb Steve Simmons:

First time post - be gentle with me :-)

I am trying to write a Python script to access a scanning device. I have an SDK
for the scanner but the documentation is a bit limited and the supplier doesn't
support Python (but Python is the best option for me in the current 
circumstances).
From a quick view it seems the documentation is excellent. There are 
tons of examples (even Java so you could use jython), API documents and 
the SDK. The VC SDK.pdf from the API documents zip explains what 
functions are there and how to call them. I have no idea why you used 
PEExplorer, are you using a device not covered by Slib.dll?
Anyway, I suggest you forget about COM and try to load Slib.dll via 
ctypes http://docs.python.org/2/library/ctypes.html and call some 
functions documented in VC SDK.pdf and see what happens. The defines 
for return codes used in the documentation are here 
http://www.id-reader.com/Support/Sample_Codes/Visual_C_Plus_Plus/header_lib.rar 
in SlibErrDef.h and probably others...


cheers
 Paul



The SDK revolves around a .dll file that is described as a 'COM Object' but the
text also implies that it can be accessed directly - If you don’t use the COM
interface in your application and use the SDK files directly like in VC++ then
you don’t need to install these files on the destination computer.  If I look
inside the .dll (thanks PEExplorer!), I see DllCanUnload, DllGetClassObject,
DllRegisterServer and DllUnregisterServer in the 'Export' view.  If I look at
the 'Import' view, I can see the names of a bunch of .dll files and the names of
the functions/methods I want to call.  So I concluded that DllGetClassObject
would be my friend.

However, I've read various tutorials on using .dll and COM (ctypes, comtypes,
and the Python documentation) and I've ended up more confused than when I
started. I expected to be using COM but all the examples seem to revolve around
automating excel or outlook.

I'd be really grateful for some hints on what direction Ishould be headed and a
pointer to a relevant tutorial.

Simmo






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


Re: Constructing JSON data structures from non-string key python dictionaries

2012-11-22 Thread Paul Kölle

Am 21.11.2012 17:04, schrieb hfo...@gmail.com:

Thanks for your reply, but the javascript function expects option
names to be unquoted, otherwise it won't work.
Others have shown you how to solve this, but I would like to note that 
the function does NOT expect JSON but a simple javascript object literal.


cheers
 Paul



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


Re: Forking simplejson

2011-10-27 Thread Paul Kölle

Am 26.10.2011 19:34, schrieb Nathan Rice:

Since this happily went off to the wrong recipient the first time...

The python json module/simpljson are badly in need of an architecture
update.  The fact that you can't override the encode method of
JSONEncoder and have it work reliably without monkey patching the pure
python encoder is a sign that something is horribly wrong.

+1

I wonder why the builtin json didn't implemented the __json__ hook. Now 
you need to write encoders for possibly arbitrary (imported/third party) 
objects Looks like it's not so hard to extend json.JSONEncoder to 
look for __json__ though:


 import json
 from functools import partial
 from types import MethodType
 class Encoder(json.JSONEncoder):
... def default(self, obj):
fn = getattr(obj, '__json__', None)
... if fn and type(fn) == MethodType:
... return obj.__json__()
... return json.JSONEncoder.default(self, obj)
...
 class T(object):
... def __json__(self):
... return 'foo'
...
 t = T()
 dumps = partial(json.dumps, cls=Encoder)
 dumps(dict([(1,1), (2,2), ('test',t)]))
'{test: foo, 1: 1, 2: 2}'


cheers
 Paul

[snip]

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


Re: Need advice on Web / Database framework...

2011-09-03 Thread Paul Kölle

Hi,

Am 03.09.2011 16:11, schrieb Benjamin Schollnick:

Folks,

I need some advice on a python web  database framework to use...?

Hardest question ever ;)



I have handcrafted a sqllite3 python script, that is a basic web
application, interfacing with a sqlite3 database...

But I am concerned at the thought of handcrafting a administration
interface, and so forth.
If you are not familiar with the various pitfalls of web security I'd 
recomment a framework which has all the layers already integrated. Take 
a look at http://www.web2py.com, I think it's quite powerful and has 
good documentation.
If you want to get your hands dirty you can compose your own framework 
cherrypy+sqlalchemy+cheetah might be a good combination.


hth
 Paul

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


Re: Installing WebDAV server

2011-08-31 Thread Paul Kölle

Hi,

Am 30.08.2011 22:00, schrieb Fokke Nauta:

Hi all,

I am completely new to Python, but I'm confronted with a problem I can't
solve.

Welcome to python.


This is my question:

[snip]


I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML. Now
I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and
PyXML-0.8.4. In the PyWebDAV README it says:

Installation and setup of server can be as easy as follows:

$ easy_install PyWebDAV
$ davserver -D /tmp -n -J

But of course it doesn't work like that. When I start up Python GUI I see
the  prompt instead of the $ prompt. But where do I place the two
directories? And there is no easy_install script in the PyXML-0.8.4
directory, only a setup.py and ez_setup.py script. I guess the latter is the
one to use. But how?
You dont install from Python GUI, use normal cmd, navigate to the 
folder you downloaded PyXML and PyWebDAV and run python setup.py 
install (python.exe has to be in your PATH). Then you have to find the 
startup-script davserver. Find your python installation directory and 
look into Install dir/Tools/Scripts, in my computer this is 
E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the 
site-packages folder i.e. E:\python27\Lib/site-packages. You might have 
to look for davserver there...


hth
 Paul

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


Re: Installing WebDAV server

2011-08-31 Thread Paul Kölle

Hi, answers below...

Am 31.08.2011 14:18, schrieb Fokke Nauta:

Paul Köllep...@subsignal.org  wrote in message
news:mailman.595.1314780791.27778.python-l...@python.org...

Hi,

Am 30.08.2011 22:00, schrieb Fokke Nauta:

Hi all,

I am completely new to Python, but I'm confronted with a problem I can't
solve.

Welcome to python.


This is my question:

[snip]


I installed Python 3.2.1 and extracted the packages PyWebDAV and PyXML.
Now
I have a working Python app and 2 directories called PyWebDAV-0.9.4.1 and
PyXML-0.8.4. In the PyWebDAV README it says:

Installation and setup of server can be as easy as follows:

$ easy_install PyWebDAV
$ davserver -D /tmp -n -J

But of course it doesn't work like that. When I start up Python GUI I see
the  prompt instead of the $ prompt. But where do I place the two
directories? And there is no easy_install script in the PyXML-0.8.4
directory, only a setup.py and ez_setup.py script. I guess the latter is
the
one to use. But how?

You dont install from Python GUI, use normal cmd, navigate to the folder
you downloaded PyXML and PyWebDAV and run python setup.py install
(python.exe has to be in your PATH). Then you have to find the
startup-script davserver. Find your python installation directory and
look intoInstall dir/Tools/Scripts, in my computer this is
E:\python27\Tools\Scripts. PyXML and PyWebDAV get installed in the
site-packages folder i.e. E:\python27\Lib/site-packages. You might have to
look for davserver there...



Thanks, Paul.

I ran python setup.py install in both the PyXML and PyWebDAV directories.
A lot of things happened and are added into those directories and I guess it
will be OK.
Next step, the startup-script davserver. There is no script as such, also
not in \python27\tools\scripts.
I found 2 similar scripts:
1. server.py in D:\Python27\WebDAV\PyWebDAV\DAVServer
2. WebDAVServer.py in D:\Python27\WebDAV\PyWebDAV\DAV

Which one is the one to use?
Your install locations look odd, but it might work nevertheless. The 
server is in DAVServer\server.py, you can look at the file and you will see:


if __name__ == '__main__':
run()

at the bottom. This is the entry point of a python script if called 
from the command line.


My install looks a bit different but I can start the server as follows:
python.exe 
E:\Python27\Lib\site-packages\pywebdav-0.9.4.1-py2.7.egg\DAVServer\server.py 
-D c:\home -n

WARNING:pywebdav:Authentication disabled!
Listening on localhost (8008)



I also configured config.ini in D:\Python27\WebDAV\PyWebDAV\DAVServer
I would use a config file outside the program directory and use the -c 
or --config switch, run server.py without arguments to see possible 
startup options.




In this file it says:
# Auth Database Table, Must exists in database prior to firstrun
dbtable=webDav

# Create User Database Table and Insert system user

I created in MySQL a database called webDav.
I can create a table called User, but how many fields?
Don't know if that's documented somewhere but you can just look at the 
code in mysqlauth.py in the same directory as server.py. Seems it needs 
three columns, (Userstring,Passstring,can_write0|1) but I haven't 
tried.


cheers
 Paul

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


Re: Methods on file-like objects can only used once on one object?

2011-08-23 Thread Paul Kölle

Am 23.08.2011 16:21, schrieb Yingjie Lin:

Hi Python users,

[snip]


There are quite a few methods for file-like objects that can only be used once 
on one object. If I prefer to use some of these methods on one object, one 
after another, like:

f.readlines()
f.read()
...

What should I do? Thank you.
use f.seek(0) between calls. The python documentation will educate you 
about the details.


hth
 Paul

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


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Paul Kölle

Am 22.08.2011 13:37, schrieb Roy Smith:

In article
c4163eeb-c306-49d1-9337-0eb9f47df...@s12g2000yqm.googlegroups.com,
  Tomas Lidéntomas.liden.pri...@gmail.com  wrote:

A cross-platform deterministic order would be excellent for us.


A cross-platform deterministic X would be excellent is a true
statement for almost any value of X.  Many people have wasted much of
their lives trying to achieve that goal, for various Xs.

So true..., QOTW +1


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


Re: Please code review.

2011-08-02 Thread Paul Kölle

Am 02.08.2011 13:45, schrieb Karim:


Hello,

I need a generator to create the cellname in a excell (using pyuno)
document to assign value to
the correct cell. The following code does this but do you have some
optimizations
on it, for instance to get the alphabetic chars instead of hard-coding it.

you can use:
import string
cellnames = string.ascii_uppercase

not sure why you need the .replace().split() stuff...


def _xrange_cellnames(rows, cols):
  cellnames = string.ascii_uppercase
  for row in xrange(1, rows+1):
for char in cellnames[:rows]:
  yield char + str(row)

cheers
 Paul




Cheers
karim

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type help, copyright, credits or license for more information.
  def _xrange_cellnames(rows, cols):
... Internal iterator function to compute excell table cellnames.
... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
... for row in xrange(1, rows+1):
... for char in cellnames.replace('', ' ').split()[:cols]:
... yield char + str(row)
...
  list( _xrange_cellnames(rows=3,cols=4))
['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3']





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


Re: How to build an application in Django which will handle Multiple servers accross network

2011-04-29 Thread Paul Kölle

Hi,

Am 29.04.2011 12:01, schrieb Adam Tauno Williams:

On Thu, 2011-04-28 at 23:47 -0700, Anurag (anu) Agarwal wrote:

Hi All,
I want to build an application for one of my client which has
following features
1. Client has some driver software which can be installed on Windows
and Linux based systems. This driver software is fetching some
operating system details using kernel level programming.
This is commonly called an agent. You might not want do write your own 
because it is hard to do correctly and takes a lot of time. I'd suggest 
you search for something like sigar (library) or collectd and check out 
what they can offer in terms of output formats.



2. Now a new web based application is required to moniter these
servers remotly. This application will talk to these servers and get
the data (not sure how data will be fetched from driver software) then
show it on UI.


Perhaps via WMI?
Yes, best option. Modern windows versions have WinRM which is basically 
WMI over http (wmi being an implementation of CIM over DCOM, but I 
digress...)





3. The web based application will be used internally in the network to
moniter servers in that network only.


You mean like OpenNMS or ZenOSS?


4. Web based application will be a real time application with a
Database.


Like OpenNMS or ZenOSS?

How can they be realtime if they generate static images?




5. Technology I am thingking for web based application is Django and
Python as this web application can also be installed on Windows or
Linux based OS.


If you want real-time monitoring you *must* build a service; a 'web app'
can *not* do that.

Do you mean an agent?




6. Also please suggest which third party tool for chatrs and graphs I
should use with Django (open source + paid)


ZenOSS and OpenNMS do graphs using RRD.
I know this is the standard but IMO it's totally backward these days. 
Correlating or selecting/deselecting certain values is painful (you have 
to write a graph def). With canvas and modern JS libs like raphael 
there are better ways to do this. Just look at google analytics. On the 
other hand, RRD (the database) is great, I just never got the python 
bindings for rrd_fetch to reliably fetch the values I needed (you can't 
tell it to stop normalizing )


It looks like PCP (http://oss.sgi.com/projects/pcp/features.html) will 
gain a JSON interface shortly. That would be awesome because PCP is 
developed by real engineers and has a proper architecture and is NOT a 
CPU sucking monstrosity of PERL-line-noise + a few hacked-together PHP 
frontends.


just my 2cents
 Paul


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


Re: [Beginer Question] I heard about python needing somesort of_VariableName_ boiler plate?

2010-11-02 Thread Paul Kölle

Its the entry point if the script is executed directly.
This message was sent from my 7 years old Dell D800 (without cables)

Am 01.11.2010 19:18, schrieb brad...@hotmail.com:

Sorry that is what I mean. What is it for?
Sent wirelessly from my BlackBerry.

-Original Message-
From: MRABpyt...@mrabarnett.plus.com
Sender: python-list-bounces+bradenf=hotmail@python.org
Date: Mon, 01 Nov 2010 17:33:22
To:python-list@python.org
Reply-To: python-list@python.org
Subject: Re: [Beginer Question] I heard about python needing some
sortof_VariableName_ boiler plate?

On 01/11/2010 04:51, Ben Finney wrote:

brad...@hotmail.com writes:


Sorry, to clarify I heard that when you declare a variable in python
you have to use some sort of standard boiler plate _variable_ however
this has not been my experience using IDLE so is this even true?


I don't know what “some sort of boiler plate _variable_” might mean.

Can you point to someone's actual message saying this, so we can see
what they might be talking about?


Perhaps the OP means:

  if __name__ == __main__:
  ...

although the declare a variable bit has me puzzled.



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


Re: please help explain this result

2010-10-17 Thread Paul Kölle

Am 17.10.2010 13:48, schrieb Steven D'Aprano:

On Sun, 17 Oct 2010 03:58:21 -0700, Yingjie Lan wrote:


Hi,

I played with an example related to namespaces/scoping. The result is a
little confusing:


[snip example of UnboundLocalError]

Python's scoping rules are such that if you assign to a variable inside a
function, it is treated as a local. In your function, you do this:

def f():
 a = a + 1

Since a is treated as a local, when you enter the function the local a is
unbound -- it does not have a value. So the right hand side fails, since
local a does not exist, and you get an UnboundLocalError. You are trying
to get the value of local a when it doesn't have a value.

Oh really? Can you explain the following?

 a = {}
 def foo():
... a['a'] = 'lowercase a'
... print a.keys()
...
 foo()
['a']
 a
{'a': 'lowercase a'}
 def bar():
... a['b'] = a['a'].replace('a', 'b')
...
 bar()
 a
{'a': 'lowercase a', 'b': 'lowercbse b'}


cheers
 Paul


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


Re: please help explain this result

2010-10-17 Thread Paul Kölle

Am 17.10.2010 19:51, schrieb TomF:

On 2010-10-17 10:21:36 -0700, Paul Kölle said:

Am 17.10.2010 13:48, schrieb Steven D'Aprano:

On Sun, 17 Oct 2010 03:58:21 -0700, Yingjie Lan wrote:


Hi,

I played with an example related to namespaces/scoping. The result is a
little confusing:


[snip example of UnboundLocalError]

Python's scoping rules are such that if you assign to a variable
inside a
function, it is treated as a local. In your function, you do this:

def f():
a = a + 1

Since a is treated as a local, when you enter the function the local
a is
unbound -- it does not have a value. So the right hand side fails, since
local a does not exist, and you get an UnboundLocalError. You are trying
to get the value of local a when it doesn't have a value.


Steven's explanation is correct. In your example below you're altering
portions of a global data structure, not reassigning a global variable.
Put another way, there is a significant difference between:
a = 7
and:
a['x'] = 7

Only the first reassigns a global variable.


Thanks Tom and Dennis.

This will teach me (hopefully) to pay attention to details next time and 
I think I learned something too. I always thought the rules about 
changing global objects where inconsistent because it works for 
mutables... Turns out it's all fine since assignment doesn't work for 
mutables too and assignment just happens to be the only way to change 
immutables ;)


cheers
 Paul



-Tom


Oh really? Can you explain the following?

 a = {}
 def foo():
... a['a'] = 'lowercase a'
... print a.keys()
...
 foo()
['a']
 a
{'a': 'lowercase a'}
 def bar():
... a['b'] = a['a'].replace('a', 'b')
...
 bar()
 a
{'a': 'lowercase a', 'b': 'lowercbse b'}


cheers
Paul






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


Re: Windows - select.select, timeout and KeyboardInterrupt

2010-05-09 Thread Paul Kölle

Am 09.05.2010 11:59, schrieb Lawrence D'Oliveiro:

In messagemailman.2769.1273327083.23598.python-l...@python.org,
exar...@twistedmatrix.com wrote:


On 07:48 am, l...@geek-central.gen.new_zealand wrote:


In messagemailman.2760.1273288730.23598.python-l...@python.org,
exar...@twistedmatrix.com wrote:


This is a good example of why it's a bad idea to use select on
Windows.
Instead, use WaitForMultipleObjects.


How are you supposed to write portable code, then?


With WaitForMultipleObjects on Windows, epoll on Linux, kqueue on BSD,
event completion on Solaris, etc...

Sound like more work than using select() everywhere?  Yea, a bit.  But
not once you abstract it away from your actual application code.  After
all, it's not like these *do* different things.  They all do the same
thing (basically) - differently.


Do you understand what “portable” means?
Yes. For me it means run as best as possible on all platforms I care 
about. It does *not* mean force one method from *one* platform upon all 
platforms for purely ideological reasons (like GTK being too stupid to 
tell the difference between %HOMEPATH% and %APPDATA%).


cheers
 Paul


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


Re: Django as exemplary design

2010-05-09 Thread Paul Kölle

Am 07.05.2010 04:48, schrieb TomF:

On 2010-05-06 18:20:02 -0700, Trent Nelson said:

I'm interested in improving my python design by studying a large,
well-designed codebase.


I'll tell you one of the best ways to improve your Python code: attend
one of Raymond Hettinger's Code Clinic workshops at a Python conference
and put some up of your work up on the projector for 20+ developers to
rip apart, line by line ;-) You'll pick up more in 30 minutes than you
ever thought possible.


I don't doubt it. But I'm not really interested in line (micro) level
code issues at the moment. Not that my code couldn't stand being
improved, but I'm more interested in seeing how medium/large OO python
systems are designed. If I could get this from a book I would, but I
suspect I need to study real code.

Then trac might be a good candidate, start here

http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture

then read

http://trac.edgewall.org/browser/trunk/trac/core.py#latest

there is one rather dubious hack in the implementation of implements() 
but I like the conceptual simplicity.


cheers
 Paul

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


Re: Accessing an instance of a class from within instance of another class

2010-04-30 Thread Paul Kölle

Am 30.04.2010 13:05, schrieb Stefan Krastanov:

Hello all,


[snipp]


Here is the problem:
I have a class (call it Data) that has a number of NumPy arrays and some
methods that get useful information from the arrays (math stuff).
I have two other classes (called Viewer1 and Viewer2) (they are subclasses
of QAbstractTableModel but that's not important).
I am working in my code with one instance of each class. Viewer1 and Viewer2
must be able to call methods from the Data instance, but as the instance of
Data is constantly updated, I cannot just copy it.
Why do you think the data is copied? Both viewers will hold a reference 
to the same data object:


Type help, copyright, credits or license for more information.
 class d(object):
...   a = 1
...   b = 2
...   c = 3
...
 d1 = d()
 d1.a
1
 class view1(object):
...   def __init__(self, data):
... self.data = data
...   def data(self):
... return self.data
...
 class view2(object):
...   def __init__(self, data):
... self.data = data
...   def data(self):
... return self.data
...
 v1 = view1(d1)
 v2 = view2(d1)
 v2.data.b
2
 v2.data.b = 4
 v2.data.b
4
 v1.data.b
4


hth
 Paul




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


Re: plugin / intra process communication system

2010-02-16 Thread Paul Kölle

Am 15.02.2010 23:12, schrieb Florian Ludwig:

On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote:

[...]

And then of course, this is not really needed. In Python, behavior
counts, not type-information. So you can get away without any explicit
declared interface. You might chose to not do that, for aestetic
reasons, or better documentation. But you aren't forced.


Actually some plugin-systems in python do force you and they check if
your implementation comply with the interface.

Which is a good thing IMO ;)


Here is one solution I came up with.

[...]
Can you post working code? It's not clear what pbus is and how it works.

cheers
 Paul



What do you think? Any obvious pitfalls (besides reinventing something)?

Please keep in mind that syntax/api is not done or anything its just
an concept presentation.

Thanks,
Florian






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


Re: plugin / intra process communication system

2010-02-14 Thread Paul Kölle

Am 13.02.2010 10:50, schrieb Florian Ludwig:

Hi,

I'm looking for a module/plugin/intra-process-communication/hook system
for python. Maybe someone here could point me to some project I missed
or might have some good ideas if I end up implementing it myself.

Most systems I have found are one to many communications but I would
like many to many, to clarify what I mean an *example* use-case:

 Lets say you program a wiki and like to allow different kind of
 authentications. So you create two plugins (for example one for
 OpenID and one for Shibboleth).

 Some time later you feel like reinventing the wheel again and
 you program a blog. Again you like to allow different ways of
 authentication and you already wrote plugins for exactly the
 same for your wiki, right?

With most systems now some trouble begins - the blog software would need
to have the interface/extention-points/however-you-name-it that the wiki
software defined.

The plugins you wrote probably import them from the wiki module directly
which means your blog would depend on the wiki. (?!) So where to put the
interface/[...] definition that is imported by those plugins? Create a
package/module just containing the interface? This really get
troublesome if different people wrote the wiki, the blog and another
third one a plugin.
If you are talking about code sharing you can move the common code out 
of your applications in a seperate namespace. If you follow the model 
trac is using you would install a module/package/egg with the basic 
functionality of the pluginsystem (i.e. what's in core.py and env.py + 
logging and whatever you think is necessary).
All shared code like your auth-plugins would go in a common plugin 
directory to which you can refer via PYTHONPATH.


Another common technique is chaining of WSGI middleware..., check out 
pythonpaste.org.


Then there is SOA where functionality is shared via RPC/webservices and 
wsdl/uddi. But my feeling is this is mostly used in Enterprise 
applications and is best used in Java/.NET where you already have 
libraries doing all the XML stuff.


hth
 Paul




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


Re: Trying to run a sudo command from script

2010-01-02 Thread Paul Kölle

Am 01.01.2010 23:55, schrieb Kent Tenney:

Howdy,

Hi Kent,


A script running as a regular user sometimes wants
to run sudo commands.

It gets the password with getpass.
pw = getpass.getpass()

I've fiddled a bunch with stuff like
proc = subprocess.Popen('sudo touch /etc/foo'.split(), stdin=subprocess.PIPE)
proc.communicate(input=pw)
If you don't use shell=True you have to provide the full path to 
commands (and split command and parameters as you do). So eather of this 
works for me:
p = Popen('/usr/bin/sudo /usr/bin/touch /tmp/foo.txt'.split(), 
stdin=PIPE, stdout=PIPE)


p = Popen('/usr/bin/sudo /usr/bin/touch /tmp/foo2.txt', stdin=PIPE, 
stdout=PIPE, shell=True)


The bad news is: It this gives me a password promt inside the 
interactive interpreter. Seems you can't catch stdout this way.


hth
 Paul



getting assorted errors with all variations I try.

Googling says use pexpect, but I'd prefer a stdlib solution.

Any help appreciated.

Thanks,
Kent



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


Re: Egg problem (~/.python-eggs)

2006-09-01 Thread paul kölle
Mike Orr wrote:
[... snipp ...]

 Can I make it use a different eggs directory?  Any other idea how to
 install a program using eggs on a server?

I had a similar issue with tracd on gentoo. My solution was setting
PYTHON_EGG_CACHE=/tmp/.egg_cache in /etc/conf.d/tracd and exporting that
var in /etc/init.d/tracd before calling start-stop-daemon, e.g.

export PYTHON_EGG_CACHE=${PYTHON_EGG_CACHE}
start-stop-daemon --start 


cheers
 Paul

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


Re: Using Python for my web site

2006-08-03 Thread paul kölle
Cliff Wells wrote:

 For myself, I handle user-installation of TurboGears pretty much like I
 do all user-installed Python packages: using setuptools.  Any user who
 uses easy_install or 'python setup.py install' gets their packages
 automatically installed into a subdirectory of their home directory and
 that takes precedence over the system installed packages.  Works like a
 charm.
May I ask how you handle clashes with packages already installed in
site-packages? Once I tried something like ~/lib/python and set up
distutils accordingly, easy_install wouldn't work if the package was
installed system-wide...

thanks
 Paul


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


Re: Type signature

2006-07-24 Thread paul kölle
Marc 'BlackJack' Rintsch wrote:
 In [EMAIL PROTECTED], Yacao Wang
 wrote:
 
 However, type signatures are not only a kind of information provided for
 the compiler, but also for the programmer, or more important, for the
 programmer. Without it, we have to infer the return type or required
 agument types of a function, and this can't be done without seeing the
 implementation of it,
 
 That's what documentation is meant for.  If you are forced to look at the
 implementation, the documentation is bad.
I think the OP refers to reading the *code*, the documentation might not
exist (yet). Sometimes I feel python is easier to write than to read and
 missing argument type declarations (just for documentation purposes)
are  IMHO one reason. Another are missing (optional) argument type
checks at runtime. Something like WrongArgumentType exceptions instead
of rather unspecific AttributeError from deep inside the code would be
very convenient.

Yes docstrings are nice but sometimes a simple:

foo(int:param1, string:param2) is way better than:

foo(param1, param2):
  
  @type param1: integer
  @type parame2: string
  

cheers
 Paul

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


Re: SQLObject connection/transaction blowing up

2006-01-14 Thread paul kölle
[EMAIL PROTECTED] wrote:
 I'm trying to connect to a mysql database, with autoCommit and caching
 off, and I'm trying to create a transaction.  Why does this blow up?
As the traceback is telling you, your connectionString is missing the
actual values. Not sure about the cache parameter but:
connectionString =
'mysql://[EMAIL PROTECTED]/mc_image_library_dev?autoCommit=1' should work.

cheers
 Paul
 
 from sqlobject import *
 connectionString = 'mysql://[EMAIL 
 PROTECTED]/mc_image_library_dev?cache=autoCommit='
[snipp]
 conn.autocommit(self.autoCommit)
 TypeError: an integer is required
 

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


Re: unittest setup

2005-09-25 Thread paul kölle
Diez B. Roggisch wrote:
 paul kölle wrote:
 
hi all,

I noticed that setUp() and tearDown() is run before and after *earch*
test* method in my TestCase subclasses. I'd like to run them *once* for
each TestCase subclass. How do I do that.
 
 
 Create a global/test instance flag.

I'm not sure if I understood what you mean, I tried:

setup = 'down'

class BaseTest(unittest.TestCase):
  def setUp(self):
global setup
if setup == 'up':
  print 'Not running setUp() again...'
  return
...
all setup work goes here.
...
setup = 'up'


This didn't work, (tried to reset the flag in the last test* method to
'down', no dice)
and:

class BaseTest(unittest.TestCase):
  def __init__(self, ...):
unittest.TestCase.__init__(self, ...)
self.setup = 'down'

  def setUp(self):
if self.setup == 'up':
  return
dowork
self.setup = 'up'

Failed also, I'm not sure why, __init__ was called way too often and
self.setup was always reset to 'down'. I finally gave up and created my
own method which I call in *every* test* method which is ugly, leads to
longer runtime and code duplication.


But at least it encouraged me to read the unittest docs more carefully.
Now I seem to understand that:

TestSuite.addTest(TestCaseSubclass('testSomething'))
TestSuite.addTest(TestCaseSubclass('testSomethingOther'))

will create two instances of TestCaseSubclass, so there is no way that
'testSomethingOther' will ever see what 'testSomething' might have
created if all work is done with instance data right? Initially I
thought it goes like: run setUp(), run all test* methods, run
tearDown() and that is what the unittest docs call a fixture

cite python 2.3 docs for unittest
A test fixture represents the preparation needed to perform one or more
tests, and any associate cleanup actions.
/cite

but further down:
cite python 2.3 docs for unittest
Each instance of the TestCase will only be used to run a single test
method, so a new fixture is created for each test.
/cite

It seems to me my case is not that exotic, I thought it would be quite
natural to write the boilerplate stuff in setUp() and build on that to
step through the applications state with test* methods each building on
top of each other. Is that the wrong approach? Are there other
frameworks supporting such a style?

thanks
 Paul

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


Re: Python Digest authentication against MS MapPoint

2005-09-05 Thread paul kölle
[EMAIL PROTECTED] wrote:
[problem with digest auth]

sorry for giving such a generic advice, but I'd capture the headers of
the C# app and compare with the urllib version line by line. Try to
reproduce the exact header with python (except the response and cnonce
of course). Maybe IIS has its own version of rfc2617.

hth
 Paul

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