ADO with Python

2006-10-16 Thread Ralf
Is their anybody with xperience in using the both and can provide me with 
some xamples.

Thx a lot
Ralf 


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


CGI Script using Python

2007-04-19 Thread Ralf
Hello,
is there anybody who can help me.
I would like to use a Python Script to download Files from a Server to the 
Client, to update the Client.

Thanx
Ralf 


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


Windows Shell Extensions - Out of Proc

2009-04-23 Thread Ralf
I'm trying to develop Windows Shell Extensions with the Python Win32
Extensions. Most of the samples are working. However, I have a
slightly different need: I want the Python COM server to run as a
separate process ("LocalServer" or "OutOfProc").

As I understand, both the InProc and LocalServer versions are created
automatically. So to disable the InProc version, I removed the
InProc32 key from the registry, for the context menu example
distributed with the Python Win32 Extensions. However, this removes
the context menu from Explorer, even though the LocalServer32 key
remains. I could access the COM objects in the example with a Python
client, so I have no idea why Explorer can't use the LocalServer
version.

Can anyone help with this? I've Google'd for hours, without much
success. I couldn't even find a good example for any other language,
only references saying it's possible for C#.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows Shell Extensions - Out of Proc

2009-04-23 Thread Ralf

> I think that for whatever reasons, explorer always tries to create
> shell extensions as InProc.  CoCreateInstance, which is the usual
> API to create COM instances, allows to specify which one you want.
>
> Thomas

So there is no way to do this, other than to create a "proxy" COM
object as InProc, which then forwards the requests to my COM object in
the separate process?
--
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] greenlet 0.4.1

2013-06-07 Thread Ralf Schmitt
Hi,

I have uploaded greenlet 0.4.1 to PyPI:
https://pypi.python.org/pypi/greenlet

What is it?
---
The greenlet module provides coroutines for python. coroutines allow
suspending and resuming execution at certain locations.

concurrence[1], eventlet[2] and gevent[3] use the greenlet module in
order to implement concurrent network applications.

Documentation can be found here: http://greenlet.readthedocs.org

The code is hosted on github:
https://github.com/python-greenlet/greenlet


Changes in version 0.4.1

The NEWS file lists these changes for release 0.4.1:

* fix segfaults when using gcc 4.8 on amd64/x86 unix
* try to disable certain gcc 4.8 optimizations that make greenlet
  crash
* Fix greenlet on aarch64 with gcc 4.8
* workaround segfault on SunOS/sun4v
* Add support for Aarch64
* Add support for x32 psABI on x86_64
* Changed memory constraints for assembly macro for PPC Linux
  platforms.


Many thanks to all contributors!


[1] http://opensource.hyves.org/concurrence/
[2] http://eventlet.net/
[3] http://www.gevent.org/

-- 
Cheers
Ralf Schmitt
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] pypiserver 1.1.1 - minimal private pypi server

2013-06-12 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.1.1 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

https://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in this version
---
- add 'overwrite' option to allow overwriting existing package
  files (default: false)
- show names with hyphens instead of underscores on the "/simple"
  listing
- make the standalone version work with jython 2.5.3
- upgrade waitress to 0.8.5 in the standalone version
- workaround broken xmlrpc api on pypi.python.org by using HTTPS

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


[ANN] pypiserver 1.1.2 - minimal private pypi server

2013-06-25 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.1.2 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

https://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in this version
---
- fix "pypi-server -U" stable/unstable detection, i.e. do not
  accidentally update to unstable packages

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


[ANN] bbfreeze 1.1.2

2013-07-17 Thread Ralf Schmitt
Hi,

I've just released bbfreeze 1.1.2. The code is available from pypi

  https://pypi.python.org/pypi/bbfreeze/

or from github 

 https://github.com/schmir/bbfreeze


bbfreeze creates stand-alone executables from python scripts. It's
similar in purpose to the well known py2exe for windows, py2app for OS
X, PyInstaller and cx_Freeze (in fact ancient versions were based on
cx_Freeze. And it uses the modulegraph package, which is also used by
py2app).

It has the following features:

easy installation 
  bbfreeze can be installed with setuptools' easy_install command.

zip/egg file import tracking
  bbfreeze tracks imports from zip files and includes whole egg files
  if some module is used from an eggfile. Packages using setuputils'
  pkg_resources module will now work (new in 0.95.0)

binary dependency tracking
  bbfreeze will track binary dependencies and will include DLLs and
  shared libraries needed by a frozen program.

multiple script freezing
  bbfreeze can freeze multiple scripts at once.

python interpreter included
  bbfreeze will create an extra executable named 'py', which might be
  used like the python executable itself.

automatic pathname rewriting
  pathnames in tracebacks are replaced with relative pathnames
  (i.e. if you import package foo.bar from /home/jdoe/pylib/
  tracebacks generated from functions in foo.bar will not show your
  local path /home/jdoe/pylib/foo/bar.py. They will instead show
  foo/bar.py)

distutils command 'bdist_bbfreeze'
  A new distutils/setuptools command bdist_bbfreeze integrates
  bbfreeze into your setup.py.

bbfreeze works on windows and UNIX-like operating systems. bbfreeze
has been tested with python 2.4, 2.5, 2.6 and 2.7 bbfreeze will not
work with python 3 or higher.


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


Re: [ANN] bbfreeze 1.1.2

2013-07-25 Thread Ralf Schmitt
Fábio Santos  writes:

> Seems like it has awesome features, but py3k is really important to me. Is
> this on your roadmap?

Sorry, I don't have a need for python 3 and also don't have a roadmap.

-- 
Cheers
Ralf

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


[ANNOUNCE] greenlet 0.4.0

2012-06-21 Thread Ralf Schmitt
Hi,

I have uploaded greenlet 0.4.0 to PyPI:
http://pypi.python.org/pypi/greenlet

What is it?
---
The greenlet module provides coroutines for python. coroutines allow
suspending and resuming execution at certain locations.

concurrence[1], eventlet[2] and gevent[3] use the greenlet module in
order to implement concurrent network applications.

Documentation can be found here: http://greenlet.readthedocs.org

The code is hosted on github:
https://github.com/python-greenlet/greenlet


Changes in version 0.4.0

The NEWS file lists these changes for release 0.4.0:

* Greenlet has an instance dictionary now, which means it can be
  used for implementing greenlet local storage, etc. However, this
  might introduce incompatibility if subclasses have __dict__ in their
  __slots__. Classes like that will fail, because greenlet already
  has __dict__ out of the box.
* Greenlet no longer leaks memory after thread termination, as long as
  terminated thread has no running greenlets left at the time.
* Add support for debian sparc and openbsd5-sparc64
* Add support for ppc64 linux
* Don't allow greenlets to be copied with copy.copy/deepcopy
* Fix arm32/thumb support
* Restore greenlet's parent after kill
* Add experimental greenlet tracing


Many thanks to Alexey Borzenkov, who spent a lot of time on this release
and everyone else that helped make this release happen.


[1] http://opensource.hyves.org/concurrence/
[2] http://eventlet.net/
[3] http://www.gevent.org/

-- 
Cheers
Ralf Schmitt
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] pypiserver 0.6.1 - minimal private pypi server

2012-08-07 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.6.1 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in version 0.6.1

- make 'python setup.py register' work
- added init scripts to start pypiserver on ubuntu/opensuse


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


[ANN] pypiserver 1.0.0 - minimal private pypi server

2012-10-26 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.0.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in version 1.0.0

- add passlib and waitress to pypi-server-standalone
- upgrade bottle to 0.11.3
- Update scripts/opensuse/pypiserver.init
- Refuse to re upload existing file
- Add 'console_scripts' section to 'entry_points', so
  'pypi-server.exe' will be created on Windows.
- paste_app_factory now use the the password_file option to create the
  app. Without this the package upload was not working.
- Add --fallback-url argument to pypi-server script to make it
  configurable.

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


[ANN] pypiserver 1.0.1 - minimal private pypi server

2013-01-03 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.0.1 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in version 1.0.1

- make 'pypi-server -Ux' work on windows
  ('module' object has no attribute 'spawnlp',
  https://github.com/schmir/pypiserver/issues/26)
- use absolute paths in hrefs for root view
  (https://github.com/schmir/pypiserver/issues/25)
- add description of uploads to the documentation
- make the test suite work on python 3
- make pypi-server-standalone work with python 2.5


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


[ANNOUNCE] greenlet 0.3.4

2012-02-11 Thread Ralf Schmitt
Hi,

I have uploaded greenlet 0.3.4 to PyPI:
http://pypi.python.org/pypi/greenlet

What is it?
---
The greenlet module provides coroutines for python. coroutines allow
suspending and resuming execution at certain locations.

concurrence[1], eventlet[2] and gevent[3] use the greenlet module in
order to implement concurrent network applications.

Documentation can be found here: http://greenlet.readthedocs.org

The code is hosted on github:
https://github.com/python-greenlet/greenlet


Changes in version 0.3.4

The NEWS file lists these changes for release 0.3.4:

* Use plain distutils for install command, this fixes installation of
  the greenlet.h header.
* Enhanced arm32 support
* Fix support for Linux/S390 zSeries
* Workaround compiler bug on RHEL 3 / CentOS 3


[1] http://opensource.hyves.org/concurrence/
[2] http://eventlet.net/
[3] http://www.gevent.org/

-- 
Cheers
Ralf Schmitt
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] pypiserver 0.5.1 - minimal pypi server

2012-02-23 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.5.1 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.5.1
-
- make 'pypi-server -U' compatible with pip 1.1

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


[ANNOUNCE] pypiserver 0.5.2 - minimal pypi server

2012-03-26 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.5.2 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.5.2
-
- provide a way to get the WSGI app
- improved package name and version guessing
- use case insensitive matching when removing archive suffixes
- fix pytz issue #6


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


[ANNOUNCE] pypiserver 0.6.0 - minimal private pypi server

2012-06-14 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.6.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.6.0
-
- make pypiserver work with pip on windows
- add support for password protected uploads
- make pypiserver work with non-root paths
- make pypiserver 'paste compatible'
- allow to serve multiple package directories using paste


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


Re: .0 in name

2022-05-28 Thread Ralf M.

Am 13.05.2022 um 23:23 schrieb Paul Bryan:

On Sat, 2022-05-14 at 00:47 +0800, bryangan41 wrote:


May I know (1) why can the name start with a number?


The name of an attribute must be an identifier. An identifier cannot
begin with a decimal number.


I'm not sure about the first statement. Feeding

[print("locals:", locals()) or c for c in "ab"]

to the REPL, the result is

locals: {'.0': , 'c': 'a'}
locals: {'.0': , 'c': 'b'}
['a', 'b']

i.e. there is a variable of name .0 in the local namespace within the 
list comprehension, and .0 is definitely not an identifier.


I came across this while investigating another problem with list 
comprehensions, and I think the original post was about list comprehensions.


There also can be non-identifier names in the global namespace and as 
attributes, e.g. using the REPL again:


globals()["42"] = "The Answer"
globals()

outputs (see last entry)

{'__name__': '__main__', '__doc__': None, '__package__': None, 
'__loader__': , '__spec__': 
None, '__annotations__': {}, '__builtins__': (built-in)>, '42': 'The Answer'}


and

class Cls:
def __init__(self, lst):
for i, e in enumerate(lst):
self.__dict__[str(i)] = e

obj = Cls([31, 42, 53])
getattr(obj, "1")

works and outputs

42


(2) where in the doc is it?!


https://docs.python.org/3/reference/lexical_analysis.html#identifiers


That refers to identifiers, i.e. names that are recognised as such by 
the lexer, i.e. that can be written directly in Python source code.


As shown above, names that are not identifiers can be used in several 
namespaces and as attributes. It's just a bit harder to use 
non-identifier names than identifiers.

Whether it's a good idea to use them at all is a different question.

I think the OP wondered about the .0 in the local namespace within list 
comprehensions. Unfortunately I cannot say much about that.



Paul


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


How to replace an instance method?

2022-09-16 Thread Ralf M.
I would like to replace a method of an instance, but don't know how to 
do it properly.


My first naive idea was

inst = SomeClass()
def new_method(self, param):
# do something
return whatever
inst.method = new_method

however that doesn't work: self isn't passed as first parameter to
the new inst.method, instead inst.method behaves like a static method.

I had a closer look at the decorators classmethod and staticmethod.
Unfortunetely I couldn't find a decorator / function "instancemethod"
that turns a normal function into an instancemethod.

The classmethod documentation contains a reference to the standard
type hierarchie, and there is an explanation that an instancemethod
is sort of a dynamically created wrapper around a function, which
is accessable as __func__.
So I modified the last line of the example above to

inst.method.__func__ = new_method

but got told that __func__ is read only.

I found some information about methods in the Descriptor HowTo Guide,
but it's about how it works internally and doesn't tell how to solve
my problem (at least it doesn't tell me).

Now I'm running out of ideas what to try next or what sections of the
documentation to read next.

Any ideas / pointers?

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


Re: How to replace an instance method?

2022-09-17 Thread Ralf M.

Am 16.09.2022 um 23:34 schrieb Eryk Sun:

On 9/16/22, Ralf M.  wrote:

I would like to replace a method of an instance, but don't know how to
do it properly.


A function is a descriptor that binds to any object as a method. For example:

 >>> f = lambda self, x: self + x
 >>> o = 42
 >>> m = f.__get__(o)
 >>> type(m)
 
 >>> m.__self__ is o
 True
 >>> m(10)
 52


Thank you and Chris A. for the two suggestions how to replace a method.

I tried both
  inst.method = functools.partial(new_method, inst)
and
  inst.method = new_method.__get__(inst)
and both work in my toy example.
I will try it on the real code next week.

Even though the functools.partial solution is easier to understand (at
least for me), I will probably use the __get__ solution as it avoids
the import of an extra library.

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


Re: How to replace an instance method?

2022-09-17 Thread Ralf M.

Am 17.09.2022 um 00:35 schrieb Dan Stromberg:



On Fri, Sep 16, 2022 at 2:06 PM Ralf M. <mailto:[email protected]>> wrote:


I would like to replace a method of an instance, but don't know how to
do it properly.


You appear to have a good answer, but...  are you sure this is a good idea?


It's definitely a dirty hack.

It'll probably be confusing to future maintainers of this code, and I 
doubt static analyzers will like it either.


I agree that I will have to add sufficient comments for the future
maintainer, should there ever be one (and even for me to still
understand it next year). I don't use static analyzers.

I'm not the biggest fan of inheritance you'll ever meet, but maybe this 
is a good place for it?


Using a derived version of the class in question to overwrite the
method was my first idea, however I don't instantiate the class in
question myself, it is instantiated during the initialisation of
another class, so I would at least have to derive a modified version of
that as well. And that code is rather complex, with metaclasses and
custom decorators, and I feel uncomfortable messing with that, while
the method I intend to change is quite simple and straightforward.

In case anybody is interested what I'm trying to achieve:

It's simple in pandas to read an excel file into a dataframe, but only
the cell value is read. Sometimes I need more / other information, e.g.
some formatting or the hyperlink in a cell. Reopening the file with
openpyxl and getting the info is possible, but cumbersome.
Looking into the pandas code for reading excel files (which uses
openpyxl internally) I noticed a method (of an internal pandas class)
that extracts the value from an openpyxl cell. This method is rather
simple and seems the ideal spot to change to get what I want.

My idea is to instantiate pandas.ExcelFile (official pandas API), get
the reader instance (an attribute of the ExcelFile object) and modify
the method of the reader instance.

The fact that the method I change and the ExcelFile attribute containing
the reader are both private (start with _) doesn't make it any better,
but I'm desperate enough to be willing to adapt my code to every major
pandas release, if necessary.

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


Incomplete sys.path with embeddable python (Windows)!?

2023-04-21 Thread Ralf M.

Hello,

when I run a script with a "normally" installed python, the directory 
the script resides in is automatically added as first element to 
sys.path, so that "import my_local_module" finds my_local_module.py in 
the directory of the script.


However, when I run the same script with embeddable python ("Windows 
embeddable package (64-bit)", download link
https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) 
the script directory is *not* prepended to the path, thus "import 
my_local_module" gives an ImportError.


I couldn't find an option to get the "normal" behaviour. Any ideas how 
to do that?


What I tried so far:

* The start-up value for sys.path seems to be defined in python311._pth. 
It looks that I can add further static paths to it, but I don't know how 
to make it add the script path (which can be different for different 
scripts).


* Uncommenting "import site" in python311._pth doesn't help.

* It seems that I could import something else in python311._pth, but I 
don't know how something imported from there could find out the path of 
the script that is about to be started.


* I read the (rather short) documentation of the embeddable package and 
of the site module several times but couldn't recognize a hint as to how 
to solve the issue.


* I can add the following lines to every script:
import sys
script_path = __file__.rsplit("\\", 1)[0]
if script_path not in sys.path:
sys.path[0:0] = [script_path]
import my_local_modul
That works, but it's ugly, executing code between imports is frowned 
upon, and it needs to be added to every script.


Does anybody have a better idea?
Any help is appreciated.

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


Re: Incomplete sys.path with embeddable python (Windows)!?

2023-04-22 Thread Ralf M.

Am 21.04.2023 um 17:31 schrieb Mats Wichmann:

On 4/20/23 15:47, Ralf M. wrote:

Hello,

when I run a script with a "normally" installed python, the directory 
the script resides in is automatically added as first element to 
sys.path, so that "import my_local_module" finds my_local_module.py in 
the directory of the script.


However, when I run the same script with embeddable python ("Windows 
embeddable package (64-bit)", download link

https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script 
directory is *not* prepended to the path, thus "import my_local_module" gives 
an ImportError.


This is intended behavior - the question comes up from time to time. The 
embeddable distribution is intended to be part of an application, not a 
general-purpose Python you can call for just anything.


There are a bunch of details here, for example:

https://github.com/python/cpython/issues/79022

Thank you for the pointer to the issue. I'll try to remove the ._pth 
completely (and see whether that breaks anything) and may have a look at 
the nuget.org package.


I can see that for many cases the behaviour is appropriate, but I had 
hoped that there is a configuration option for the cases where it is not.


About my use case:
There is a complex application package, consisting of some commercial 
and some freeware software, tied together with scripts in at least four 
different scripting languages. Now I intend to add further functionality 
in a fifth language, Python. The idea is to make the embeddedable 
package part of the application package and have scripts for the new 
functions. Several independent functions are to be added, each 
consisting of a script plus some local modules, and all of them should 
use the same python embedded into the application package.

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


Re: Incomplete sys.path with embeddable python (Windows)!?

2023-04-22 Thread Ralf M.

Am 22.04.2023 um 03:27 schrieb Greg Ewing via Python-list:

How are you invoking your script? Presumably you have some code
in your embedding application that takes a script path and runs
it. Instead of putting the code to update sys.path into every
script, the embedding application could do it before running
the script.


In principle a good idea, but I don't know how to do that:
The script is currently invoked by a .cmd file, but that may change to a 
shortcut (.lnk). This is what the embeddable package documentation calls 
"Python Application - simple approach".

To update sys.path on start up I would need to do something like
  C:\path\to\python.exe --add-path C:\s-path C:\s-path\script.py
but I couldn't find an option like --add-path.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Incomplete sys.path with embeddable python (Windows)!?

2023-04-22 Thread Ralf M.

Am 21.04.2023 um 18:07 schrieb Thomas Passin:

On 4/20/2023 5:47 PM, Ralf M. wrote:

Hello,

when I run a script with a "normally" installed python, the directory 
the script resides in is automatically added as first element to 
sys.path, so that "import my_local_module" finds my_local_module.py in 
the directory of the script.


However, when I run the same script with embeddable python ("Windows 
embeddable package (64-bit)", download link

https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script 
directory is *not* prepended to the path, thus "import my_local_module" gives 
an ImportError.

I couldn't find an option to get the "normal" behaviour. Any ideas how 
to do that?


What I tried so far:
[...]
* I can add the following lines to every script:
 import sys
 script_path = __file__.rsplit("\\", 1)[0]
 if script_path not in sys.path:
 sys.path[0:0] = [script_path]
 import my_local_modul
[...] 


Thank your for your hints.

I haven't worked with embeddable python, but here are some possibilities 
that came to mind, depending on how your system works -


1. If your script is started from the command line, sys.argv[0] gives 
the path to the script; 
I didn't think of sys.argv[0] to get at the path; this might be quite 
useful, I'll try it out next week.


You could use os.path.dirname() to get its 
directory.  This will end up the same place as your code fragment, but 
looks nicer and handles different path separators (e.g., Linux vs Windows);
Yes, but it requires another import and the embedded package is only 
available for windows anyway, I think. I'll consider the idea, though.


2. You could write a little module that figures out the script's path 
and import that first in all your scripts.


3. If you know all the directories that your scripts will be in, you 
could add them all to a xx.pth file (do a search to make sure where to 
put .pth files for an embeddable case).
I thought about that, but for that to work all local modules across all 
script locations must have unique names, otherwise import might get hold 
of a module from the wrong directory. Certainly doable for a few 
scripts, but might become a source of hard to track errors when the 
number of scripts increases and later maintainers are not aware of the 
naming restriction.



[...}


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


Re: "py.ini" question

2021-04-25 Thread Ralf M.

Am 25.04.2021 um 16:30 schrieb Mats Wichmann:


On 4/24/21 2:57 PM, Chris Angelico wrote:
On Sun, Apr 25, 2021 at 5:57 AM Gisle Vanem  
wrote:


With 'py -3.6' or 'py 3.8' I get the expected.
But with 'py -3':
    Python 3.8.9 (default, Apr 13 2021, 15:54:59)  [GCC 10.2.0 64 bit 
(AMD64)] on win32


I believe that's because you're asking for "the latest in the 3.x 
series".


unless differently described by the ini file, which is what the OP is 
trying to do.


I just added a 3.10 alpha to my Windows setup (I don't do my programming 
there, so there hadn't been any need), and set up an ini file to leave 
3.9 as the default and all works as expected - py -0, py, py -3, py 
-3.10 all given me the one I would expect to get based on that setup (-0 
shows 3.9-64 starred, despite 3.10-64 being "the latest).


Personally stumped why it's not working for Gisle.


I think the problem / misunderstanding is that Gisle put in py.ini only
 [defaults]
 python=3.6

and expected this to make py -3 start 3.6. However py -3 looks for a key 
named 'python3' and, not finding it, uses default behaviour (ignoring 
the 'python' key), i.e. starts the most modern stable 3.x.


The py.ini documentation is a bit hard to find in the help file and hard 
to understand as the interesting part talks about environment variables 
and shebang line commands, not py.ini settings and py.exe parameters. 
However, the behaviour is the same in both cases and the relevant 
example is:


"If PY_PYTHON=3.1-32, the command python will use the 32-bit 
implementation of 3.1 whereas the command python3 will use the latest 
installed Python (PY_PYTHON was not considered at all as a major version 
was specified.)"


I tried the (rather insane) py.ini
 [defaults]
 python=3.7
 python2=3.8
 python4=2.7
and it works as documented (py -3 shows default behaviour as there is no 
'python3' in py.ini):


C:\>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 
64 bit(AMD64)] on win32

C:\>py -2
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 
bit (AMD64)] on win32

C:\>py -3
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 
bit (AMD64)] on win32

C:\>py -4
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 
bit (Intel)] on win32





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


Re: version

2018-05-31 Thread Ralf Schoenian

Hi Mike,

you can check for the major version with

import sys
sys.version_info.major


On 01.06.2018 04:44, Mike McClain wrote:

 OK so I installed python 3.2, which is the latest available as a
package in Debian Wheezy, because I've seen so many folks say it's a
waste of time to play with Py2.7.
 Immediately my python playground 'my.python.py' failed as soon as
I changes the '#!' line to python3.2.
 Most of the errors were because I had used 'print' without parens
which 2.7 liked but 3.2 doesn't.
Is there a way in a script to know which version of python is being
run so I can write:
 If (version == 2.7):
 do it this way
 elsif (version == 3.2):
 do it another way

Thanks,
Mike
--
I Don't care how little your country is, you got a right to run it like
you want to. When big nations quit meddling then the world will have peace.
 - Will Rogers


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


Multidimensional dicts

2019-09-06 Thread Ralf M.
Recently I wrote a quick and dirty script to do some counting and 
statistics. When I re-read it a bit later I noticed that I had been 
using two different ways to create two-dimensional (default-)dicts. Now 
I'm wondering whether one of them is "better" or more pythonic than the 
other.


What I did:

ddd_a = collections.defaultdict(set)
ddd_a[(key1, key2)].add(foo)

ddd_b = collections.defaultdict(lambda: collections.defaultdict(set))
ddd_b[key1][key2].add(foo)

Both work as expected.

Trying to think about differences I only noticed that ddd_a more easily 
generalises to more dimensions, and ddd_b has the benefit that 
ddd_b[key1] is a dict, which might help if one "row" needs to be fed to 
a function that expects a dict.


More general ddd_a looks more symmetric (key1 and key2 are exchangeable, 
if done consistently) and ddd_b looks more hierarchic (like a tree 
traversed from root to leaves where key1, key2 etc. determine which way 
to go at each level). ddd_b also is more simmilar to how two-dimensional 
lists are done in python.


Any recommendations / comments as to which to prefer?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Spread a statement over various lines

2019-09-18 Thread Ralf M.

Am 17.09.2019 um 20:59 schrieb Manfred Lotz:

I have a function like follows

def regex_from_filepat(fpat):
 rfpat = fpat.replace('.', '\\.') \
   .replace('%', '.')  \
   .replace('*', '.*')

 return '^' + rfpat + '$'


As I don't want to have the replace() functions in one line my
question is if it is ok to spread the statement over various lines as
shown above, or if there is a better way?

Thanks.



Not related to your question, but:
You seem to try to convert a Windows wildcard pattern to a regex 
pattern. However, wildcards sometimes behave a bit different than what 
you assume. I know for instance that *.* matches any filename, even if 
the filename doesn't contain a dot.


Out of curiosity I played around a bit, details below.
As you can see, there are other wildcard strangenesses, e.g.
- ? does not match a dot
-  between letters etc. matches exactly 4 characters, but
   at the end or directly before a dot matches at most 4 characters

I don't know the exact rules of Windows wildcards, so there may be even 
more cases of unexpected behavior.
If anyone knows where to find the complete rules (or a python module 
that implements them), I would be interested.


Regards,
Ralf

- Details (Win 7 home SP1) -

C:\tmp>more pydirb.py
#!/usr/bin/env python3

import os, re, sys

def regex_from_filepat(fpat):
rfpat = fpat.replace('.', '\\.') \
.replace('?', '.')   \
.replace('*', '.*')
return '^' + rfpat + '$'

regexfilepat = re.compile(regex_from_filepat(sys.argv[1]))

for name in os.listdir():
if regexfilepat.match(name):
print(name)

C:\tmp>dir /b *
foo
foo.bar
foo.bar.c
foo.c
pydirb.py

C:\tmp>pydirb *
foo
foo.bar
foo.bar.c
foo.c
pydirb.py

C:\tmp>dir /b *.*
foo
foo.bar
foo.bar.c
foo.c
pydirb.py

C:\tmp>pydirb *.*
foo.bar
foo.bar.c
foo.c
pydirb.py

C:\tmp>dir /b *.*.*.*.*
foo
foo.bar
foo.bar.c
foo.c
pydirb.py

C:\tmp>pydirb *.*.*.*.*

C:\tmp>dir /b foo.?
foo
foo.c

C:\tmp>pydirb foo.?
foo.c

C:\tmp>dir /b foo.
foo
foo.bar
foo.c

C:\tmp>pydirb foo.

C:\tmp>dir /b foo?bar
Datei nicht gefunden

C:\tmp>pydirb foo?bar
foo.bar

C:\tmp>dir /b f?o.bar
foo.bar

C:\tmp>pydirb f?o.bar
foo.bar

C:\tmp>dir /b f??o.bar
Datei nicht gefunden

C:\tmp>pydirb f??o.bar

C:\tmp>dir /b fo?.bar
foo.bar

C:\tmp>pydirb fo?.bar
foo.bar

C:\tmp>dir /b fo??.bar
foo.bar

C:\tmp>pydirb fo??.bar

C:\tmp>dir /b foo??.bar
foo.bar

C:\tmp>pydirb foo??.bar
--
https://mail.python.org/mailman/listinfo/python-list


Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.

Am 18.09.2019 um 22:22 schrieb Chris Angelico:

On Thu, Sep 19, 2019 at 6:20 AM Ralf M.  wrote:


Am 17.09.2019 um 20:59 schrieb Manfred Lotz:

I have a function like follows

def regex_from_filepat(fpat):
  rfpat = fpat.replace('.', '\\.') \
.replace('%', '.')  \
.replace('*', '.*')

  return '^' + rfpat + '$'


As I don't want to have the replace() functions in one line my
question is if it is ok to spread the statement over various lines as
shown above, or if there is a better way?

Thanks.



Not related to your question, but:
You seem to try to convert a Windows wildcard pattern to a regex
pattern. However, wildcards sometimes behave a bit different than what
you assume. I know for instance that *.* matches any filename, even if
the filename doesn't contain a dot.


Hmm, why do you assume it's a Windows wildcard pattern specifically?

ChrisA

I think I jumped to that conclusion because the example didn't treat [ ] 
as special characters. [ ] are special in a unix shell, but not at a cmd 
prompt. Thinking it over, [ ] would need a much differnt treatment and 
might be left out of the example for that reason, though.


Also I may be biased: I mostly use Windows, Linux only occasionally.

Ralf M.

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


Re: Spread a statement over various lines

2019-09-19 Thread Ralf M.

Am 18.09.2019 um 22:24 schrieb Alexandre Brault:


On 2019-09-18 4:01 p.m., Ralf M. wrote:


I don't know the exact rules of Windows wildcards, so there may be
even more cases of unexpected behavior.
If anyone knows where to find the complete rules (or a python module
that implements them), I would be interested.



fnmatch in the standard library has a translate function that transforms
a glob pattern to a regex

https://docs.python.org/3.7/library/fnmatch.html#fnmatch.translate

Alex


Thank you for the pointer.
However, from the documentation of module fnmatch:
"This module provides support for Unix shell-style wildcards"

And Unix shell-style wildcards differ from Windows cmd wildcards.
For one, [ ] are special in Unix shells, but not in Windows cmd.
For another, cmd wildcards have several quirks, e.g. *.* matching 
filenames that don't contain a dot, or "a???" matching "ab".


Several years ago, when I needed DOS-style globbing, I copied fnmatch.py 
and glob.py from the standard library and modified them to treat [ ] as 
not special. However, that didn't help with the cmd quirks, and I don't 
even know all the rules about cmd wildcards.


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


Enums are Singletons - but not always?

2020-05-23 Thread Ralf M.

Hello,

recently I wrote a small library that uses an Enum. That worked as 
expected. Then I added a main() and if __name__ == "__main__" to make it 
runable as script. Now Enum members that should be the same aren't 
identical any more, there seem to be two instances of the same Enum.


I think I know what's going on, but cannot find a good and elegant way 
to avoid the problem. I hope someone here can help me there.


Below are a simplified code sample, the results when I run it and my 
thoughts.


# Code of mod1.py #
import enum, mod2
class En(enum.Enum):
A = 1
B = 2
def main():
a = mod2.getA()
print("a is En.A:", a is En.A)
print("a:", repr(a), "En.A:", repr(En.A))
print("id(a), id(a.__class__)", id(a), id(a.__class__))
print("id(En.A), id(En)  ", id(En.A), id(En))
if __name__ == "__main__":
main()
# End of mod1.py #

# Code of mod2.py #
import mod1
def getA():
return mod1.En.A
# End of mod2.py #

# Results when run: #
C:\tmp>py mod1.py
a is En.A: False
a:  En.A: 
id(a), id(a.__class__) 33305864 7182808
id(En.A), id(En)   33180552 7183752

C:\tmp>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 
64 bit

(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mod1
>>> mod1.main()
a is En.A: True
a:  En.A: 
id(a), id(a.__class__) 49566792 44574280
id(En.A), id(En)   49566792 44574280
>>>

So: When run as script there are two instances of En (different ids), 
but when mod1 is imported and mod1.main() is run it works as expected 
(just one instance of En, same ids).

BTW: py -m mod1 doesn't work either.

What I thing is happening:
When the script is run, mod1.py is executed and an instance of En and 
its members is created. During the same run mod1 is also imported (via 
mod2), the file mod1.py is executed again as part of the import and 
another, different instance of En and its members is created.


How do I have to change mod1.py to avoid the problem?
Currently I have moved main() into a new file script.py. That works, but 
is not what I wanted.


I doubt it's a bug in the enum module, but should that be the case, I'm 
willing to open an issue on the bug tracker.


Or can nothing be done about it?

Looking forward to any ideas
Ralf M.

P.S.:
As I was about to send this post the following modification occured to 
me (see below). It works, but it doesn't feel right to import a module 
directly from inside itself.

# Modified code of mod1.py (one line added) #
import enum, mod2
class En(enum.Enum):
A = 1
B = 2
from mod1 import En  # NEW LINE, overwrite just defined En
def main():
a = mod2.getA()
print("a is En.A:", a is En.A)
print("a:", repr(a), "En.A:", repr(En.A))
print("id(a), id(a.__class__)", id(a), id(a.__class__))
print("id(En.A), id(En)  ", id(En.A), id(En))
if __name__ == "__main__":
main()
--
https://mail.python.org/mailman/listinfo/python-list


unittest test discovery: regular packages vs. namespace packages

2020-07-10 Thread Ralf M.

Hello,

to my last question I got many helpful and enlightening answers.
So I try again with a completely different topic.

https://docs.python.org/3/library/unittest.html#test-discovery
says about test discovery:

"Unittest supports simple test discovery. In order to be compatible with 
test discovery, all of the test files must be modules or packages 
(including namespace packages) importable from the top-level directory 
of the project (this means that their filenames must be valid identifiers).

[...]
Note: As a shortcut, python -m unittest is the equivalent of python -m 
unittest discover."


Therefore I expected
python -m unittest
to run all tests in the current directory and its subdirectories, 
regardless of whether the subdirectories contain a __init__.py or not.


However, this only works for me if an (empty) __init__.py is present, 
i.e. the package is a regular one. As soon as I delete the __init__.py, 
turning the regular package into a namespace package, unittest doesn't 
find the test files any more. When I recreate __init__.py, the test file 
(e.g. test_demo.py) is found again. See demo session further down.


I tried the following Python versions, all showed the same behavior:
 Python 3.7.1 (python.org) on Win10
 Python 3.7.4 (python.org) on Win7
 Python 3.7.7 (Anaconda) on Win10
 Python 3.8.3 (Anaconda) on Win10

What am I missing / misunderstanding?


Demo session:

F:\demo>dir /s /b
F:\demo\test_we4n7uke5vx
F:\demo\test_we4n7uke5vx\test_demo.py
F:\demo\test_we4n7uke5vx\__init__.py

F:\demo>type test_we4n7uke5vx\__init__.py

F:\demo>type test_we4n7uke5vx\test_demo.py
import unittest
class SomeTestCase(unittest.TestCase):
def test_fail_always(self):
self.assertTrue(False)

F:\demo>py -m unittest
F
==
FAIL: test_fail_always (test_we4n7uke5vx.test_demo.SomeTestCase)
--
Traceback (most recent call last):
  File "F:\demo\test_we4n7uke5vx\test_demo.py", line 4, in test_fail_always
self.assertTrue(False)
AssertionError: False is not true

--
Ran 1 test in 0.001s

FAILED (failures=1)

F:\demo>del test_we4n7uke5vx\__init__.py

F:\demo>py -m unittest

--
Ran 0 tests in 0.000s

OK

F:\demo>echo # > test_we4n7uke5vx\__init__.py

F:\demo>py -m unittest
F
==
FAIL: test_fail_always (test_we4n7uke5vx.test_demo.SomeTestCase)
--
Traceback (most recent call last):
  File "F:\demo\test_we4n7uke5vx\test_demo.py", line 4, in test_fail_always
self.assertTrue(False)
AssertionError: False is not true

--
Ran 1 test in 0.001s

FAILED (failures=1)

F:\demo>
--
https://mail.python.org/mailman/listinfo/python-list


Re: popen4

2005-10-19 Thread Ralf Muschall
Ganesan Rajagopal wrote:

> Try pexpect instead. http://pexpect.sourceforce.net/
   ^

That's a content-free ad site.  You probably mean sourceforGe.

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


Re: Lots of pdf files

2005-07-21 Thread Ralf Muschall
Greg Lindstrom wrote:
> Hello-
> I'm running Python 2.3 on a Linux system and have lots (about 2000)
> files in pdf format to print each day.  If I just wind up and fire all
> the files at the printer at once (as 2000 separate print jobs), the
> print server throws a fit and our system admin comes down and slaps me
> around for a few minutes (which, I guess, is fair).

Are your sure it is the number (and not the sum of the sizes) of
the jobs your admin is worrying about?

What about

#!/bin/sh
for i in *.pdf; do
  lpr $i
  sleep 10
done

(maybe adding something that waits until the queue is empty instead
of sleep)?

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


Using PyGILState_Ensure

2005-09-20 Thread Ralf Riemer
Hi,

I have some questions concerning the global interpreter lock:

I am working with Windows XP Professional Version 5.1, Python version 2.4.1
and Microsoft Visual C++.Net Version 7.1.
>From Python I call a function from a C++ dll using
calldll.call_foreign_function. This C++ function does a callback of a python
function.
Do get it running I use PyGILState_Ensure before PyEval_CallObject and
PyGILState_Release afterwards.
The code looks like this:

static PyObject *my_callback = NULL;

...

// my_callback is set from Python using a 
function SetCallback
...


/* Time to call the callback */
ppyobjArgList = Py_BuildValue("()", NULL);  
   
//General Interpreter Lock (essential for succesful
calling of any python function)
PyGILState_STATE gstate;
//Ensure that the current thread is ready to call
the Python C API 
gstate = PyGILState_Ensure();

ppyobjResult = PyEval_CallObject(my_callback,
ppyobjArgList);
if (!((DWORD_PTR)ppyobjResult))
{
//Error handling
...
} else {
Py_DECREF(ppyobjResult);
}
 
Py_DECREF(ppyobjArgList);

PyGILState_Release(gstate);

Now my questions:
Are there any risks aquiring the global interpreter lock?
Do I invoke by PyEval_CallObject a new python process? (I suppose not)
How long my this call of PyEval_CallObject last? Are there restictions to
the code I use in the called function.
Is it allowed to force the thread to wait (by aquiring the GIL)?
Is there a risk that windows hangs up?
Doing several calls of my dll function with the callback, is there a risk
that the calls overlap and information gets lost?

Thanks for your help!
Ralf

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
-- 
http://mail.python.org/mailman/listinfo/python-list

[ANN] pypiserver 1.1.5 - minimal private pypi server

2014-01-20 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.1.5 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

https://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

I didn't announce the previous version, so here's the changelog for the
last two versions:

1.1.5 (2014-01-20)
--
- only list devpi-server and proxypypi as alternatives
- fix wheel file handling for certain wheels
- serve wheel files as application/octet-stream
- make pypiserver executable from wheel file
- build universal wheel
- remove scripts subdirectory
- add --index-url cli parameter

1.1.4 (2014-01-03)
--
- make pypiserver compatible with pip 1.5
  (https://github.com/schmir/pypiserver/pull/42)


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


Re: Defamation

2015-10-19 Thread Ralf Hildebrandt
* Ian Kelly :

> Which is the same thing the OP was told the last time he posted a
> removal request publicly to this list. I do note that the subject of
> the previous request appears to have since been removed.
> 
> I've taken the liberty of forwarding this request on to
> python-list-owner, on the theory that this will be more useful than
> discussion about it here.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

The right place is [email protected], since the owner cannot clean
the archives.

-- 
Ralf Hildebrandt   Charite Universitätsmedizin Berlin
[email protected] Benjamin Franklin
http://www.charite.de  Hindenburgdamm 30, 12203 Berlin
Geschäftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Defamation

2015-10-20 Thread Ralf Hildebrandt
* Laura Creighton :

> Actually, this one was part of a huge set of defaming articles sent a
> year ago we were requested to remove, and did.  European Law may
> require us to do so.  I checked, and this article wasn't one on
> our list, which is why we missed this one.

Note that the "next in thread" also was of defamatory content. Removed
as well.

-- 
Ralf Hildebrandt   Charite Universitätsmedizin Berlin
[email protected] Benjamin Franklin
http://www.charite.de  Hindenburgdamm 30, 12203 Berlin
Geschäftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Defamation

2015-10-20 Thread Ralf Hildebrandt
* Steven D'Aprano :
> On Tue, 20 Oct 2015 03:28 am, Laura Creighton wrote:
> 
> > Actually, this one was part of a huge set of defaming articles sent a
> > year ago we were requested to remove, and did.  European Law may
> > require us to do so.  I checked, and this article wasn't one on
> > our list, which is why we missed this one.
> 
> I don't believe that the Python mailing list archives are hosted in a
> country under the jurisdiction of European Law.

The Netherlands it is.

-- 
Ralf Hildebrandt   Charite Universitätsmedizin Berlin
[email protected] Benjamin Franklin
http://www.charite.de  Hindenburgdamm 30, 12203 Berlin
Geschäftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Defamation

2015-10-21 Thread Ralf Hildebrandt
> According to Ralf, python.org is hosted in the Netherlands, 

One could change that.

> I want to buy peanut butter, but I don't, because I know that when it comes
> to peanut butter I have no self-control and would eat the entire jar in a
> single sitting. So I simply don't buy it in the first place, and the
> problem is solved.

That's what I do when it comes to candy in general )

-- 
Ralf Hildebrandt   Charite Universitätsmedizin Berlin
[email protected] Benjamin Franklin
http://www.charite.de  Hindenburgdamm 30, 12203 Berlin
Geschäftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] pypiserver 0.3.0 - minimal pypi server

2011-10-07 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.3.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.3.0
-
- pypiserver now scans the given root directory and it's
  subdirectories recursively for packages. Files and directories
  starting with a dot are now being ignored.
- /favicon.ico now returns a "404 Not Found" error
- pypiserver now contains some unit tests to be run with tox

-- 
Cheers,
Ralf

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


[ANNOUNCE] pypiserver 0.4.0 - minimal pypi server

2011-11-20 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.4.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.4.0
-
- add functionality to manage package updates
- updated documentation
- python 3 support has been added

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


[ANNOUNCE] pypiserver 0.5.0 - minimal pypi server

2011-12-05 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 0.5.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just easy_install pypiserver). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver


Changes in version 0.5.0
-
- make setup.py install without calling 2to3 by changing source code
  to be compatible with both python 2 and python 3. We now ship a
  slightly patched version of bottle. The upcoming bottle 0.11
  also contains these changes.
- make the single-file pypi-server-standalone.py work with python 3

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


[ANNOUNCE] greenlet 0.3.2

2011-12-19 Thread Ralf Schmitt
Hi,

I have uploaded greenlet 0.3.2 to PyPI:
http://pypi.python.org/pypi/greenlet

What is it?
---
The greenlet module provides coroutines for python. coroutines allow
suspending and resuming execution at certain locations.

concurrence[1], eventlet[2] and gevent[3] use the greenlet module in
order to implement concurrent network applications.

Documentation can be found here: http://packages.python.org/greenlet/

The code is hosted on github:
https://github.com/python-greenlet/greenlet

Changes in version 0.3.2

The NEWS file lists these changes for release 0.3.2:

* fix various crashes with recent gcc versions and VC90
* Try to fix stack save/restore on arm32
* store and restore the threadstate on exceptions like pypy/stackless do
* Switch to using PyCapsule for Python 2.7 and 3.1
* Port for AIX on PowerPC
* Fix the sparc/solaris header
* Improved build dependencies patch from flub.
* #21 - Can't pass parent=None to greenlet.greenlet()


[1] http://opensource.hyves.org/concurrence/
[2] http://eventlet.net/
[3] http://www.gevent.org/

-- 
Cheers
Ralf Schmitt
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] greenlet 0.3.3

2012-01-06 Thread Ralf Schmitt
Hi,

I have uploaded greenlet 0.3.3 to PyPI:
http://pypi.python.org/pypi/greenlet

What is it?
---
The greenlet module provides coroutines for python. coroutines allow
suspending and resuming execution at certain locations.

concurrence[1], eventlet[2] and gevent[3] use the greenlet module in
order to implement concurrent network applications.

Documentation can be found here: http://greenlet.readthedocs.org

The code is hosted on github:
https://github.com/python-greenlet/greenlet

Changes in version 0.3.3

The NEWS file lists these changes for release 0.3.3:

* Use sphinx to build documentation and publish it on greenlet.rtfd.org
* Prevent segfaults on openbsd 4/i386
* Workaround gcc-4.0 not allowing to clobber rbx
* Enhance test infrastructure
* Fix possible compilation problems when including greenlet.h in C++ mode
* Make the greenlet module work on x64 windows
* Add a test for greenlet C++ exceptions
* Fix compilation on Solaris with SunStudio


[1] http://opensource.hyves.org/concurrence/
[2] http://eventlet.net/
[3] http://www.gevent.org/

-- 
Cheers
Ralf Schmitt
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] pypiserver 1.1.0 - minimal private pypi server

2013-02-14 Thread Ralf Schmitt
Hi,

I've just uploaded pypiserver 1.1.0 to the python package index.

pypiserver is a minimal PyPI compatible server. It can be used to serve
a set of packages and eggs to easy_install or pip.

pypiserver is easy to install (i.e. just 'pip install pypiserver'). It
doesn't have any external dependencies.

http://pypi.python.org/pypi/pypiserver/ should contain enough
information to easily get you started running your own PyPI server in a
few minutes.

The code is available on github: https://github.com/schmir/pypiserver

Changes in version 1.1.0

- implement multi-root support (one can now specify multiple package
  roots)
- normalize pkgnames, handle underscore like minus
- sort files by their version, not alphabetically
- upgrade embedded bottle to 0.11.6
- upgrade waitress to 0.8.2 in the standalone script
- merge vsajip's support for verify, doc_upload and remove_pkg


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


Re: Encoding sniffer?

2006-01-06 Thread Ralf Muschall
Diez B. Roggisch wrote:

> AFAIK iso-8859-1 has all codepoints taken - so you won't go beyond that
> in your example.

IIRC the range 128-159 (i.e. control codes with the high bit set)
are unused.

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


Re: decorator question

2006-01-08 Thread Ralf Schmitt
Schüle Daniel schrieb:
> hello NG,
> 
> consider this code
> 
>  >>> def timelogger(f):
> ... def wrapper(*a,**kw):
> ... print "started at %s" % time.ctime()
> ... t0 = time.time()
> ... f(*a, **kw)
> ... t1 = time.time()
> ... print "ended at %s" % time.ctime()
> ... print "diff = ", t1-t0, "sec"
> ... return wrapper
> ...
>  >>> import time
>  >>> @timelogger
> ... def loops(a,b,c):
> ... sum = 0
> ... for i in range(a):
> ... for j in range(b):
> ... for k in range(c):
> ... sum += 1
> ...
>  >>> loops
> 
>  >>> loops(10,10,10)
> started at Sun Jan  8 23:19:19 2006
> ended at Sun Jan  8 23:19:19 2006
> diff =  0.000367164611816 sec
> 
> the code above works fine
> but I am wondering wheather it's possible to
> write something like this
> 
>  >>> def timelogger(f, logfile=sys.stdout):
> ... def wrapper(*a,**kw):
> ... logfile.write("started at %s" % time.ctime())
> ... t0 = time.time()
> ... f(*a, **kw)
> ... t1 = time.time()
> ... logfile.write("ended at %s" % time.ctime())
> ... logfile.write("diff = %f %s" % (t1-t0, "sec"))
> ... return wrapper
> 
>  >>> import time
>  >>> @timelogger(file("hierher", "a"))### << (1)
> ... def loops(a,b,c):
> ... sum = 0
> ... for i in range(a):
> ... for j in range(b):
> ... for k in range(c):
> ... sum += 1
> ...
> 
> (1) fails to compile
> is it possible to pass parameters to a decorator function?
>

It's possible. The call to timelogger must return a function which 
itself takes a function and returns one:

def timelogger(logfile=sys.stdout):
 def deco(f):
 def wrapper(*a,**kw):
 logfile.write("started at %s" % time.ctime())
 t0 = time.time()
 f(*a, **kw)
 t1 = time.time()
 logfile.write("ended at %s" % time.ctime())
 logfile.write("diff = %f %s" % (t1-t0, "sec"))
 return wrapper
 return deco


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


Re: Railroad track syntax diagrams

2006-08-02 Thread Ralf Muschall
Paddy wrote:

> I googlled and got these:
>   http://www.informatik.uni-freiburg.de/~thiemann/haskell/ebnf2ps/
>   http://www.antlr.org/share/1107033888258/SDG2-1.5.zip

There is another beast, also called ebnf2ps, but in elisp
(runs inside the editor).

It requires no additional software (i.e. no ghc) and is simpler
to use (no questions about inexistent .afm files etc.)

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


Re: 10GB XML Blows out Memory, Suggestions?

2006-06-07 Thread Ralf Muschall
Paul McGuire schrieb:

> meat of the data can be relatively small.  Note also that this XML overhead
> is directly related to the verbosity of the XML designer's choice of tag
> names, and whether the designer was predisposed to using XML elements over
> attributes.  Imagine a record structure for a 3D coordinate point (described
> here in no particular coding language):

> struct ThreeDimPoint:
> xValue : integer,
> yValue : integer,
> zValue : integer

> Directly translated to XML gives:

> 
> 4
> 5
> 6
> 

This is essentially true, but should not cause the OP's problem.
After parsing, the overhead of XML is gone, and long tag names
are nothing but pointers to a string which happens to be long
(unless *all* tags in the XML are differently named, which would
cause a huge DTD/XSD as well).

> This expands 3 integers to a whopping 101 characters.  Throw in namespaces
> for good measure, and you inflate the data even more.

In the DOM, it contracts to 3 integers and a few pointers -
essentially the same as needed in a reasonably written
data structure.

> Try zipping your 10Gb file, and see what kind of compression you get - I'll
> bet it's close to 30:1.  If so, convert the data to a real data storage

In this case, his DOM (or whatever equivalent data structure, i.e.
that what he *must* process) would be 300 MB + pointers.
I'd even go as far and say that the best thing that can happen to
him is a huge overhead - this would mean he has a little data
in a rather spongy file (which collapses on parsing).

> medium.  Even a SQLite database table should do better, and you can ship it
> around just like a file (just can't open it up like a text file).

A table helps only if the data is tabular (i.e. a single relation),
i.e. probably never (otherwise the sending side would have shipped
something like CSV).

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


Re: time.clock() going backwards??

2006-08-29 Thread Ralf Muschall
Grant Edwards wrote:

> This is a _Microsoft_Product_.  There doesn't have to be a
> reason for something to be done in a half-assed manner.

No, it is a quantum effect.  If the energy of a clock has a
lower bound, there must be a nonzero probability for it to
run backwards.

See <[EMAIL PROTECTED]>

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


Gadfly server startup error

2006-09-12 Thread Ralf Muschall
Hello,

I just tried the recent gadfly (from SF), using Python
2.4.2 (hand built, since my Suse 8.2 had only 2.2.2).

The direct operation of gadfly works.

After calling gfserver, I get (in addition to a complete
users manual dumped on the screen) the following error
message:

|Traceback (most recent call last):
|  File "/usr/local/bin/gfserver", line 4, in ?
|main()
|  File 
"/usr/local/python-2.4.2/lib/python2.4/site-packages/gadfly/scripts/gfserver.py",
 line 89, in main
|S = Server(int(port), db, dr, pw, startup)
|NameError: global name 'Server' is not defined


which is factually correct (the script only imports sys,
but then tries to instantiate the class "Server" which is
nowhere defined).

Is this a bug somewhere, or is just my installation broken?

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


Re: Gadfly server startup error

2006-09-13 Thread Ralf Muschall
Steve Holden wrote:

> You're already doing better than I am. On Cygwin 2.5rc2 and Windows 
> 2.4.2 I can't even get it to runs its tests properly:

I don't remember whether I looked into that at all.

...
> NameError: global name 'Server' is not defined

...
> Time to report a bug, methinks? Makes SQLite look good  ...

Carl Waldbieser reported this bug (and a few others, including
fixes) in April 04 (entry 94049[35]).  It seems the project
fell asleep four years ago (but in "News" on SF is a more recent
message from the author pointing to xsdb).

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


Re: Gadfly server startup error

2006-09-13 Thread Ralf Muschall
Steve Holden wrote:

> Yes, the whole Gadfly SF web seems to be a bit of a mess.

Maybe it has been infected by the source code+doc ;-)

I just started the server (after applying Carl's changes)
with

gfserver  foodb . ''

(the DB "foodb" had been created earlier using gfplus
locally).

If I look for it with "nmap localhost -p ", it enters
an endless loop (I don't know whether it would still work
after this, since I could not get it to work at all).

gfplus in client-mode wants the argument order
  DB, port-No, password, host
(inferred from the source, i.e. the manual is wrong).

The argument order of commandlines and functions seems to be
a general problem - maybe I should try all 24 possibilities
(almost each place in the source does them differently).

After that, it says

|gfplus $Revision: 1.7 $ -- Interactive gadfly shell  [readline]
|
|Wednesday September 13, 2006 04:53 PM
|Using:
|Policy: foodb
|Loc: localhost:

i.e. it includes a thing called "Policy" (unexplained, just
mentioned in the "Security" chapter of the server manual)
and fills it with the value of the database name (but comparing
scripts/gfplus.py and client.py, "database" and "policy" seem
to be synonyms (but this disagrees with server.py)).

Entering a lone semicolon+return at the client prompt causes
a timeout in the client and a message

|no such policy: foodb
|main loop on  

|server: waiting for connection(s)

in the server (which is true in some sense, since I never made
a policy - I just want a blood DB).

It seems the proper way to use gadfly over the net is to say

echo 'SQL statement;' | ssh -l remoteuser 'gfplus -localoptions'

:-(

Is anybody out there who has used the server+client operation
mode successfully?

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


Re: problem while going through a tutorial

2006-12-12 Thread Ralf Schönian
Simon Schuster schrieb:
[..]
>>>> x = "fljshfjh"
>>>> x
> 'fljshfjh'
>>>> count(x, 'h')
> Traceback (most recent call last):
>  File "", line 1, in ?
> NameError: name 'count' is not defined
> 
> I'm not sure what changed, because it used to work. anyhow thanks a lot!

You forgot to import the string module:
from string import *

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


Re: Shortest prime number program

2006-02-11 Thread Ralf Muschall
Christoph Zwerschke wrote:
> [EMAIL PROTECTED] schrieb:
>> How about:

>> [2]+[x for x in range(1,99) if 2**x%x==2]

> If the range goes beyond 340, it also gives non-primes...

[2,3]+[x for x in range(1,99) if 2**x%x==2 and 3**x%x==3]
[2,3,5]+[x for x in range(1,99) if 2**x%x==2 and 3**x%x==3 and 5**x%x==5]

SCNR, Ralf

PS: They both break at 561, and further strengthening of the
condition will not help.  Manual loop unrolling as follows works:

[2,3,... ]+[x for x in range(1,99) if False]

For sufficiently small values of 99, this will also be a rather
short program.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determing whether two ranges overlap

2006-02-17 Thread Ralf Muschall
Robin Haswell wrote:

> I can think of lots of ways to do this but it's in a tight loop so I need
> it to be as efficient as possible. Any help welcome :-)

There are 24 possibilities of having 4 numbers in a row, and
the following 6 of them describe nonempty intervals (the remaining
18 are obtained by reversing the endpoints of one or both
intervals, thereby making them empty):

# separate
a0 a1 b0 b1
b0 b1 a0 a1

# inside
a0 b0 b1 a1
b0 a0 a1 b1

# cross
a0 b0 a1 b1
b0 a0 b1 a1

The simplest is to exclude the first pair, i.e.

not (a1=b0 and b1>=a0, given by Fredrik without proof ;-)

You will have to decide whether you want ">" or ">="
(beware of the former when using floats).

If you cannot assume that the pairs are in order, this
will break.

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


Re: Python books?

2007-03-09 Thread Ralf Schönian
Have a look at: Core python programming from Wesley J. Chun printed by 
Prentice Hall.

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


Re: basic web auth and verification

2007-10-24 Thread Ralf Schönian
[EMAIL PROTECTED] schrieb:
> Trying to figure out how to add login verfication. I believe it is
> logging me in, but theres no way to really tell..any ideas? or
> tutorials out there that can exaplain this to me?
> 
> Thanks
> 
> import urllib,urllib2,cookielib
> 
> passlst = open(passfile, 'r').readlines()
> url="http://somesite";
> cj = cookielib.LWPCookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> urllib2.install_opener(opener)
> TheForm = urllib.urlencode({"username":"myid","password":"mypas"})
> request = urllib2.Request(url, TheForm)
> result = urllib2.urlopen(request)
> html=result.read()
> result.close()
> 

I had the same trouble. There was a redirect after login a had to 
follow. Look at the following code.

 def login(self):
 ''' Log into web site. '''

 self._br.set_handle_redirect(True)
 cj = CookieJar()
 self._br.set_cookiejar(cj)
 self._br.open(Config.urlLogin)
 self._br.select_form(name='login')

 self._br['session_key'] = Config.username
 self._br['session_password'] = Config.password
 response=self._br.submit()
 self._br.set_response(response)
 for link in self._br.links(url_regex="www.somesite.com"):
 self._br.follow_link(link)
 if 'Sign In' in self._br.title():
 raise ValueError('Wrong password')


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


Re: Python web app. (advice sought)

2007-01-15 Thread Ralf Schönian
Tim Williams schrieb:
> On 15 Jan 2007 00:52:33 -0800, Torabisu <[EMAIL PROTECTED]> wrote:

> 
> Don't overlook Karrigell either,  with a tiny learning curve its
> always worth consideration, especially if you need rapid development
> and a web server that will sit on top of your exising .py modules.
> 
> www.karrigell.com
> 
> hth :)

I would also like to vote for Karrigell.

BTW: Does anyone knows how to avoid stopping/starting of the webserver 
after changing external libraries? I have some own modules under 
/opt/local/python/lib and import them by extending the path with 
sys.path.append() After changing any file here, I have to restart 
Karrigell.

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


Re: Sourcing Python Developers

2007-01-30 Thread Ralf Schönian
Kartic schrieb:
> Hello,
> 
> My company has quite a few opening involving python expertise. We are 
> always looking for python resources (and find it difficult filling these 
> positions, might I add). Is there any place to find developers' resumes 
> (like finding jobs from http://python.org/community/jobs/)? If any one 
> knows of a resume repository (other than Monster, Dice, 
> Costs-an-arm-and-leg job site) please share.

Do not know if you have to give your arm or your leg away, but maybe the 
following place is of interest for you:

http://www.opensourcexperts.com

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


Re: uml and python

2007-02-07 Thread Ralf Schönian
azrael schrieb:
> hy guys
> 
> i've been googling and got several posts, but nothing that is a
> satisfaction in my eyes. can someone tell me a nice uml diagram tool
> with python export (if possible nice gui), or at least nice uml tool
> 
> gpl or freeware (widows) prefered
> 
> thanks
> 
Take a look at gaphor: http://gaphor.sourceforge.net/


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


Re: [OT] Any Python lullabies?

2006-04-18 Thread Ralf Muschall
Christos Georgiou wrote:
> Since there have been python limmericks, are there any Python lullabies that
> I can sing to my newborn son (actually, born yesterday)?  I tried to murmur
> some select parts from the tutorial, but he somehow wasn't very interested
> :)

There is something near the end of the Camel book (p. 552ff).
This isn't exactly python, but the baby probably won't see
the difference.

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


Re: [silly] Does the python mascot have a name ?

2006-05-19 Thread Ralf Muschall
John D Salt wrote:

> I'll believe you if you can give me a list of ten things that don't have 
> names.

[ sub{$_},  sub{$_+1}, sub{$_+2}, sub{$_+3}, sub{$_+4},
 sub{$_+5}, sub{$_+6}, sub{$_+7}, sub{$_+8}, sub{$_+9}]

That was easy.

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


Re: Name conflict in class hierarchy

2006-05-20 Thread Ralf Muschall
Jeffrey Barish wrote:

[overriding of base class member functions by subclass]

> but then B does not inherit other functions of A that I would like to use. 
> It struck me that this must be a common problem in OOP, so I'm wondering
> whether there is a simple solution that I am missing.

In C++, one has virtual member functions (which behave like python's),
and their purpose is to be overriden (o.g. a print method, whose subclass
version will print more attributes than the base knows about).

Such functions usually are documented - otherwise their being virtual
would make no sense.

In Python, a function not intended to be overriden should be either
have a name starting with an underscore or be documented.  So the person
who should change something is the author of the library, not you.

In your current situation, the following options seem to remain:

1. Use funny names ("foobar239847562384756" instead of "func")
   and hope that the library update will not use them

2. Call dir(classname) at hacking time and avoid names listed
   therein.  This breaks if the library update may happen at the
   user's site without you being able to change your code.

3. Call dir(classname) at runtime and raise an exception
   if it contains a name used by you.

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


Re: Name conflict in class hierarchy

2006-05-23 Thread Ralf Muschall
bruno at modulix wrote:

>> In Python, a function not intended to be overriden should be either
>> have a name starting with an underscore

> actually with *two* underscores. The single-leading-underscore naming
> scheme is the convention for 'protected' (read: 'implementation, not
> API') attributes.

That's what I meant.  "A.func" looked like an internal implementation
detail.

>> or be documented.

Having the implementation details documented too would be nice, but
hardly enforceable in real life.

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


Re: Writing Oracle Output to a File

2007-12-27 Thread Ralf Schönian
t_rectenwald schrieb:
> Hello,
> 
> I attempting to execute an Oracle query, and write the results to a
> file in CSV format.  To do so, I've done the following:
> 
> import cx_Oracle
> db = cx_Oracle.connect('user/[EMAIL PROTECTED]')
> cursor = db.cursor()
> cursor.arraysize = 500
> cursor.execute(sql)
> result = cursor.fetchall()
> 
> The above works great.  I'm able to connect to the database and print
> out the results as a list of tuples.  Here is where I get lost.  How
> do I work with a "list of tuples?"  My understanding is that a "list"
> is basically an array (I don't come from a Python background).  Tuples
> are a "collection of objects."  So, if I do...
> 
> print result[0]
> 
> I get the first row of the query, which would make sense.  The problem
> is that I cannot seem to write tuples to a file.  I then do this...
> 
> csvFile = open("output.csv", "w")
> csvFile = write(result[0])
> csvFile.close
> 
> This generates an exception:
> 
> TypeError: argument 1 must be string or read-only character buffer,
> not tuple
> 
> So, I'm a bit confused as to the best way to do this.  I guess I could
> try to convert the tuples into strings, but am not sure if that is the
> proper way to go.  Any help would be appreciated.  I've also seen a
> csv module out there, but am not sure if that is needed in this
> situation.
> 
> Best Regards,
> Tom

Hi,

have a look at the csv Module: http://docs.python.org/lib/csv-examples.html

Just iterate over your result.

# Untested
import csv
writer = csv.writer(open("some.csv", "wb"))

for row in result:
 row = map(str,row)
 writer.writerows(row)
writer.close()


Ralf Schoenian




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


Re: Writing Oracle Output to a File

2007-12-27 Thread Ralf Schönian
Ralf Schönian schrieb:
> t_rectenwald schrieb:
>> Hello,
>>
>> I attempting to execute an Oracle query, and write the results to a
>> file in CSV format.  To do so, I've done the following:
>>
>> import cx_Oracle
>> db = cx_Oracle.connect('user/[EMAIL PROTECTED]')
>> cursor = db.cursor()
>> cursor.arraysize = 500
>> cursor.execute(sql)
>> result = cursor.fetchall()
>>
>> The above works great.  I'm able to connect to the database and print
>> out the results as a list of tuples.  Here is where I get lost.  How
>> do I work with a "list of tuples?"  My understanding is that a "list"
>> is basically an array (I don't come from a Python background).  Tuples
>> are a "collection of objects."  So, if I do...
>>
>> print result[0]
>>
>> I get the first row of the query, which would make sense.  The problem
>> is that I cannot seem to write tuples to a file.  I then do this...
>>
>> csvFile = open("output.csv", "w")
>> csvFile = write(result[0])
>> csvFile.close
>>
>> This generates an exception:
>>
>> TypeError: argument 1 must be string or read-only character buffer,
>> not tuple
>>
>> So, I'm a bit confused as to the best way to do this.  I guess I could
>> try to convert the tuples into strings, but am not sure if that is the
>> proper way to go.  Any help would be appreciated.  I've also seen a
>> csv module out there, but am not sure if that is needed in this
>> situation.
>>
>> Best Regards,
>> Tom
> 
> Hi,
> 
> have a look at the csv Module: http://docs.python.org/lib/csv-examples.html
> 
> Just iterate over your result.
> 
> # Untested
> import csv
> writer = csv.writer(open("some.csv", "wb"))
> 
> for row in result:
> row = map(str,row)
# should be
   myRow = list(row)
   row = map(str,myRow)
> writer.writerows(row)
> writer.close()
> 
> 
> Ralf Schoenian
> 

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


Re: CGI with URL problem

2008-02-13 Thread Ralf Schönian

rodmc schrieb:
> -- sorry if this has shown up twice, but my browser crashed and ended
> up posting the message when I hit the space bar for some odd reason.
> Also it was not quite ready.
> 
> Hi,
> 
> I am writing a small CGI app which tests if another webpage exists,
> the pages are on a Wiki system. Anyway when I run the same function
> (see below) from within IDLE it is ok, however when it is run from
> within the CGI script I get a socket error::
> 
> "URLError:
>   reason = "
> 
> I am not quite sure what is causing this, is there a special way of
> dealing with such things from within CGI script? I have pasted the
> offending function below, along with only the import statement which
> relates to that function.
> 
> Thanks in advance for any help.
> 
> Kind regards,
> 
> rod
> 
> From the CGI version:
> 
> from urllib2 import urlopen as urlopen
> 
> def urlexists(url):
> path="http://x.y.z/wiki/index.php?title="+url
> sock = urlopen(path)
> page=sock.read()
> if "There is currently no text in this page" in page:
> return True
> else:
> return False
> 
> Ammended IDLE version:
> 
> from urllib2 import urlopen as urlopen
> import os,sys
> 
> def urlexists(url):
> path="http://x.y.z/wiki/index.php?title="+url
> sock = urlopen(path)
> page=sock.read()
> if "There is currently no text in this page" in page:
> print "found"
> return True
> else:
> print "not found"
> return False
> 
> if __name__=="__main__":
> urlexists("cheese_test")

Are you using the same user in your cgi script and within IDLE?

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


Re: Empty string is False right?

2009-01-31 Thread Ralf Schoenian

AJ Ostergaard wrote:

Hello,

First post so bear with me if I'm being a numpty ...

Is it me or is there something slightly counter intuitive and thus not 
so pythonesque about this:


 >>> s = ''
 >>> if s: True
 else: False

False
 >>> s and eval(s)
''
 >>>

Regards,
AJ



Hi,

yes, the following evaluates to False:
empty String: ''
empty list: []
empty tuple: ()
empty dict: {}
0, None
and False of course

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


Re: Which SOAP module?

2009-01-04 Thread Ralf Schoenian

Roy Smith wrote:

I'm starting to play with SOAP.  The zeroth question that needs
answering is, "Which SOAP module should I use?"  There seem to be a
number of different ones to pick from.  Any suggestions?


It depends on whether you want to write a client or a server 
application. If you only want to write a client I found suds ( 
https://fedorahosted.org/suds/ ) very helpful. It is actively developed 
and the documentation is comprehensive. Well, for the server I think you 
have to rely on the ZSI (http://pywebsvcs.sourceforge.net/)
 project. In retrospect my first steps in this library were rather 
painful but som year ago it was the most sophisticated library.


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


Re: Extending Python with C or C++

2009-01-05 Thread Ralf Schoenian

Ryan wrote:

I've been using Python for many years now. It's a wonderful language
that I enjoy using everyday. I'm now interested in getting to know
more about the guts (C/C++) and extending it. But, extending python
still seems like a black art to me. Is there anymore docs or info on
extending it besides the standard sparse ones (http://www.python.org/
doc/2.5.2/ext/intro.html) that may give me more insight? Is there a
class available? How can I learn more about the guts of python? How
would one go about following an interest in contributing to the
development of python.

Thanks,

Ryan


It is not exactly what you are looking for but nevertheless I am 
thinking the  article "Automatic C Library Wrapping -- Ctypes from the 
Trenches" may be interesting for you. You can find it in the latest 
Python Papers issue or simply following the link: 
http://ojs.pythonpapers.org/index.php/tpp/article/view/71


Regards,
Ralf


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


Re: Email Program

2009-03-01 Thread Ralf Schoenian

J wrote:

Is it possible to make a GUI email program in Python that stores
emails, composes, ect?


Hi,

yes, it is possible. There are modules in the standard library like 
email, smtplib and poplib. A gui can be written in wxPython, pyQT, pyGTK 
or tkinter. There are many more toolkits but these are the big ones.
Actually, ff you want to see an Python email client in action have a 
look at Chandler: http://chandlerproject.org/ it's written in wxPython.


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


Re: equivalent of source command in tcl for python

2009-03-18 Thread Ralf Schoenian

[email protected] wrote:

Many times I am developing a code in a file and I want to, for
example, exit at a specific line so that I can test something. In tcl
you can just put an exit command in and source the file. Is there an
equivalent for python? Thanks,


Hi Mark,

there is:

import sys
sys.exit()

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


Re: Network programming ?

2009-05-25 Thread Ralf Schoenian

[email protected] wrote:

Hi everyone,

I am planning to develop a chatting software in Python, for my college
project. I am using Windows Vista. Is it possible to do sockets
programming in Python ? Any books or websites ?  Also, i want to
develop a gui for that program. What are the gui tool kits available
for windows? I already knew about PyGtk and PyQT, but will they work
properly in Windows platform? Any suggestions?

Thank you. Excuse my English.


You forgot to mention the other big gui toolkits tkinter and wxPython. 
Years ago, I decided for wxPython because of its licence and that it is 
useable at windows and linux. For the socket programming I would like to 
suggest using the xmlrpclib. You can find the official documentation 
here: http://docs.python.org/library/xmlrpclib.html


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


matplotlib: is there something like DISLIN's "call newpag" ?

2008-07-13 Thread Ralf . Schaa
Hi there,
hope somebody here can help me out:

is there a command in matplotlib which resembles DISLIN's "CALL
NEWPAG" ?
I am trying to make multiple plots on several pages, all stored in one
ps (or pdf) document.

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


Re: looking for IDE advice or workflow tips

2008-08-04 Thread Ralf Schönian

[EMAIL PROTECTED] schrieb:

I'm a novice developer at best and often work with the R statistical
programming language. I use an editor called TINN-R which allows me to
write a script, then highlight a few lines and send them to the
interpreter. I am using pythonwin and it lacks this funtionality (that
I can tell) and when I copy and paste lines into the interpreter only
the first line is evaluated and the rest appears as returned text.

Is there an editor that allows me to send a few lines out of many
lines of code at a time?

or

How does one check small blocks of code without typing them each time,
running an entire script (with other code) or creating a small script
for every code block?

For example say lines 1-100 work fine and now I'm working on lines
101-105. Should I create a small script with just those lines?

Thanks for any advice


Try another approach. Write unittests for your code. This will lead to
more testable and shorter chunks of code and your test cases will be 
executed on each iteration step.


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


Re: bbfreeze problem

2008-08-12 Thread Ralf Schmitt

Neal Becker wrote:

Any ideas on this?

bb-freeze test5-coded-pre.py



x86_64.egg/bbfreeze/eggutil.py", line 132, in copyDistribution
raise RuntimeError("setup.py not found for development egg")
RuntimeError: setup.py not found for development egg




Can you try the latest bbfreeze version from the mercurial repository 
(either hg clone http://systemexit.de/repo/bbfreeze or download 
http://systemexit.de/repo/bbfreeze/archive/tip.tar.bz2)



I don't think I'm using matplotlib, don't understand what dragged it in (python 
-v on my script does _not_ show any matplotlib)


Try running 'XREF=1 bb-freeze test5-coded-pre.py'. This should open a 
browser window with your dependencies...


Regards,
- Ralf

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


Re: Please help me with linking libraries on Solaris 10 sparc

2008-05-01 Thread Ralf Schönian

idev schrieb:

Hi all,
Please help me with my stuff.

I downloaded python 2.5.1 package from http://blastwave.org it was
compiled using Sun Studio 11 for Solaris 8 sparc.

My system is Solaris 10 sparc and I compiled using SunStudio 11
psycopg2 python binding for PostgreSQL 8.3.1.

Compilation was OK, but when I am trying to import psycopg2 I am
getting this error:

$ python
Python 2.5.1 (r251:54863, Nov  3 2007, 02:54:52) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.

import psycopg2

Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/csw/lib/python/site-packages/psycopg2/__init__.py", line
60, in 
from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: ld.so.1: python: fatal: relocation error: file /opt/csw/
lib/python/site-packages/psycopg2/_psycopg.so: symbol round:
referenced symbol not found

Any suggestions or help will be appreciated.


Hi,

maybe a stupid question - but why don't you want to use the "official" 
package? You can download it here: 
http://sunfreeware.mirrors.tds.net/indexsparc10.html


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


ANN: bbfreeze 0.96.5

2008-09-18 Thread Ralf Schmitt

Hi all,

I uploaded bbfreeze 0.96.5 to the python package index.

bbfreeze creates standalone executables from python scripts (similar to 
py2exe).
bbfreeze works on windows and unix-like operating systems (no OS X 
unfortunately).

bbfreeze is able to freeze multiple scripts, handle egg files and
track binary dependencies.

This release features a new bdist_bbfreeze command, which integrates
bbfreeze into setup.py scripts (contributed by Hartmut Goebel,
thanks).

More information can be found at the python package index:
http://pypi.python.org/pypi/bbfreeze/

Regards,
- Ralf

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


Re: processing the genetic code with python?

2006-03-07 Thread Ralf Muschall
James Stroud wrote:

> I'm writing your name down and this is the last time I'm doing homework 
> for you.

This won't help - she doesn't even know her name
(but google helps with that) ;-)

The fact that she uses E.coli ribosomal protein L1
strongly indicates that this is really homework.

...
> data = data.upper().replace('T', 'U')
...

I'd apply the "inverse" of this line to the codon table
(or a copy thereof, or just adding the entries) in the hope
that changing 37 table entries is less work than changing
each codon in a base sequence.

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


Re: Any advantage in LISPs having simpler grammars than Python?

2006-03-08 Thread Ralf Muschall
Douglas Alan wrote:

> Experienced Lisp programmers use indentation to visually parse the
> program structure, just like Python programmers do for Python.
> Experienced Lisp programmers learn to not see the parentheses when
> they don't need to.

True, and this is IMHO an advantage of lisp to python (both humans
and computers get something they are good at parsing, and mistakes
in the one can be corrected using the other).

> When I did a lot of Lisp programming, I often felt that it would be
> kind of nice to have a version of Lisp that would infer many of the
> parentheses from indentation, so that you could elide most of them.

This is not necessary - just making them barely visible suffices.

(font-lock-add-keywords
 'emacs-lisp-mode
 '(("[()]" . somr-barely-visible-face)))

One can also use nil instead of the mode, wrap the thing into a
defun and use it as a hook (nil means "just the current buffer
whatever mode it is in").

Btw., vim seems to try to become a real editor - look at
http://wiki.alu.org/Vim_ECL

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


Re: "The World's Most Maintainable Programming Language"

2006-04-05 Thread Ralf Muschall
Mirco Wahab wrote:

>  Perl, named after Pearl Biggar (Larry Wall’s fiancée),

His wife was Gloria since at least 1979, perl was published
in 1987.  This seems to be an insider joke (he wanted to call
the language "Gloria" first, then "pearl", then "perl").

>  set a high standard for naming techniques.

So we should rename Python into Cottonmouth to get more attention.

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


Re: Python book

2009-09-30 Thread Ralf Schoenian

lallous wrote:

Hello

Can anyone suggest a good book Python book for advancing from beginner 
level?


(I started with Learning Python 3rd ed)

Regards,
Elias


Hi Elias,

welcome to Python.
I have learned Python with the official tutorial and with the 
outstanding book: Beginning Python, From Novice to Professional by 
Magnus Lie Hetland. This book provides a gently introduction into Python 
and 10 chapters with "complete" projects.


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


Re: Python + webservice

2009-10-07 Thread Ralf Schoenian

Fred Chevitarese wrote:

Hello all... I'm new here and a search in tis group but unfortunately
i didn't find any kind of solution/code/question etc ...

I have to made a python script that communicates with an websevice
over the web. I tried out use SoapPy, ZSI, BeautifullSoap and others,
but get no success...
I have to generate a XML file from a XSD file, and them send it to a
webservice as i have said before.
There's really no need to generate a XML file from a XSD file bu if
it's possible it will be very very good...

Has anyone made something like this and can share with me a bit of
experience?


Did you try suds https://fedorahosted.org/suds ? I've got good results 
with this library.


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


Re: Import python modules from sub-directories

2010-08-05 Thread Ralf Schoenian

Navkirat Singh wrote:

Hi guys,

I am new to python and would like to import certain classes in sub-directories 
of the working directory. I was wondering how will I be able to achieve this?

Regards,
Nav


Hi,

put an empty file with the name __init__.py in your subdirectory. I call 
it sub1 here. Assuming your filename is importme.py and your classname 
is Test you can do the following imports:


from sub1.importme import Test
import sub1.importme

You can find further explainations in the official tutorial 
http://docs.python.org/tutorial/modules.html


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


Re: How to use Python to interface with Web pages?

2009-07-07 Thread Ralf Schoenian

Peter wrote:

Any help would be appreciated :-)

I want to write an auction sniping tool in Python. I know Python, but
I know absolutely nothing about web pages, javascript etc i.e. I want
the program to automatically log me into my eBay account, access the
appropriate item, locate how many mins/seconds until the bid time ends
and then automatically place a bid at the last possible moment.

I can see the web-page source - it looks to be javascript (to my
untutored eye :-)).

But how do I enter data and "simulated" mouse presses on a web-page
that I have accessed via a Python program?

So where can I start to learn how to do this? Any books available? web
resources that show examples or offer tutorials?

I have (in the past) written some python to scoop data off web-sites
but I have never written anything that interactively interacts with
the web-page contents and don't know where to even start on this one.

Thanks for any help/pointers

Peter


Hi,

a good starting point possibly is 
http://wwwsearch.sourceforge.net/mechanize/


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


visual studio 2010 question

2010-09-19 Thread Ralf Haring

After running into the error "Setup script exited with error: Unable
to find vcvarsall.bat" when trying to use easy_install / setuptools a
little digging showed that the MS compiler files in distutils only
support up to Studio 2008. Does anyone know if there is a timetable
for when Studio 2010 will be supported?

I am using python 2.6.5, but web searching seemed to show that 2.7 or
3.X didn't support it yet either.

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


Re: How to make use of .egg files?

2017-04-05 Thread Ralf Hildebrandt
* David Shi via Python-list :
> Can anyone explain please.

http://stackoverflow.com/questions/2051192/what-is-a-python-egg

-- 
Ralf Hildebrandt   Charite Universitätsmedizin Berlin
[email protected] Benjamin Franklin
https://www.charite.de Hindenburgdamm 30, 12203 Berlin
Geschäftsbereich IT, Abt. Netzwerk fon: +49-30-450.570.155
-- 
https://mail.python.org/mailman/listinfo/python-list


Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-02 Thread Ralf W. Grosse-Kunstleve
**
This posting is also available in HTML format:
  http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html
**

Hi fellow Python coders,

I often find myself writing::

class grouping:

def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
# real code, finally

This becomes a serious nuisance in complex applications with long
argument lists, especially if long variable names are essential for
managing the complexity. Therefore I propose that Python includes
built-in support for reducing the ``self.x=x`` clutter. Below are
arguments for the following approach (*please* don't get too agitated
about the syntax right here, it really is a secondary consideration)::

class grouping:

def __init__(self, .x, .y, .z):
# real code right here

Emulation using existing syntax::

def __init__(self, x, y, z):
self.x = x
del x
self.y = y
del y
self.z = z
del z


Is it really that important?


For applications of non-trivial size, yes. Here is a real-world example
(one of many in that source tree):

   
http://cvs.sourceforge.net/viewcvs.py/cctbx/cctbx/cctbx/geometry_restraints/manager.py?view=markup

Fragment from this file::

class manager:

  def __init__(self,
crystal_symmetry=None,
model_indices=None,
conformer_indices=None,
site_symmetry_table=None,
bond_params_table=None,
shell_sym_tables=None,
nonbonded_params=None,
nonbonded_types=None,
nonbonded_function=None,
nonbonded_distance_cutoff=None,
nonbonded_buffer=1,
angle_proxies=None,
dihedral_proxies=None,
chirality_proxies=None,
planarity_proxies=None,
plain_pairs_radius=None):
self.crystal_symmetry = crystal_symmetry
self.model_indices = model_indices
self.conformer_indices = conformer_indices
self.site_symmetry_table = site_symmetry_table
self.bond_params_table = bond_params_table
self.shell_sym_tables = shell_sym_tables
self.nonbonded_params = nonbonded_params
self.nonbonded_types = nonbonded_types
self.nonbonded_function = nonbonded_function
self.nonbonded_distance_cutoff = nonbonded_distance_cutoff
self.nonbonded_buffer = nonbonded_buffer
self.angle_proxies = angle_proxies
self.dihedral_proxies = dihedral_proxies
self.chirality_proxies = chirality_proxies
self.planarity_proxies = planarity_proxies
self.plain_pairs_radius = plain_pairs_radius
# real code, finally

Not exactly what you want to see in a high-level language.


Is there a way out with Python as-is?
-

Yes. If you take the time to look at the file in the CVS you'll find
that I was cheating a bit. To reduce the terrible clutter above, I am
actually using a simple trick::

adopt_init_args(self, locals())

For completeness, the implementation of ``adopt_init_args()`` is here:

   
http://cvs.sourceforge.net/viewcvs.py/cctbx/scitbx/scitbx/python_utils/misc.py?view=markup

While this obviously goes a long way, it has several disadvantages:

  - The solution doesn't come with Python -> everybody has to reinvent.

  - People are reluctant to use the trick since scripts become
dependent on a non-standard feature.

  - It is difficult to remember which ``import`` to use for
``adopt_init_args`` (since everybody has a local version/variety).

  - The ``adopt_init_args(self, locals())`` incantation is hard to
remember and difficult to explain to new-comers.

  - Inside the ``__init__()`` method, the same object has two names,
e.g. ``x`` and ``self.x``. This lead to subtle bugs a few times
when I accidentally assigned to ``x`` instead of ``self.x`` or vice
versa in the wrong place (the bugs are typically introduced while
refactoring).

  - In some cases the ``adopt_init_args()`` overhead was found to
introduce a significant performance penalty (in particular the
enhanced version discussed below).

  - Remember where Python comes from: it goes back to a teaching
language, enabling mere mortals to embrace programming.
``adopt_init_args(self, locals())`` definitely doesn't live up
to this heritage.


Minimal proposal


My minimal proposal is to add an enhanced version of ``adopt_init_args()``
as a standard Python built-in function (actual name secondary!)::

class grouping:

def __init__(self, x, y, z):
adopt_init_args()
# real code

Here is a reference implementation:

   
http://cvs.sourcefor

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-05 Thread Ralf W. Grosse-Kunstleve
uge ** NO! **. If __slots__ improve
performance and reduce memory, what is wrong with using this feature?
I clearly was in situations where I needed __slots__, but I still
don't know what the dangers could be. Could you please explain
a little more?

> All in all, I think there's SOME merit to this idea, in that this
> is a common enough practice that it might be nice to make it easy
> to type (and read). But your proposal entangles the good idea with
> several ideas I rather dislike, and on the whole I think it sounds
> rather dangerous.

I am OK to strip down the proposal to concentrate solely on an
optimal, fast, C-coded built-in function. That alone would be a major
step forward, with a life-changing potential similar to that of zip,
enumerate, or inplace operators (+=, *=, etc.). (I guess I am showing
my age.)

I was also considering working in Josiah Carlson's metaclass solution
(http://mail.python.org/pipermail/python-list/2005-July/288349.html)
to the __slots__ problem, but after reading your message I am not so
sure anymore...

Cheers,
Ralf




 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compatibility of recent GCC/Python versions

2005-07-06 Thread Ralf W. Grosse-Kunstleve
--- David Abrahams <[EMAIL PROTECTED]> wrote:
> Recently people testing Boost.Python with GCC on Linux have reported
> that the extensions being tested have to be compiled with exactly the
> same version of GCC as the Python they're being loaded into, or they
> get mysterious crashes.
> 
> That doesn't correspond to my past experience; it has always been true
> that, as long as the compiler used to build Python and the one used to
> build the extension have compatible 'C' ABIs, we've been okay.  Yes,
> if you were going to pass types like FILE* across the Python/C API,
> then you additionally need to be sure that the two compilers are using
> the same 'C' library.  That said, none of the Boost.Python tests do
> that.
> 
> I'm wondering if there has been a well-known recent change either in Python
> or GCC that would account for these new reports.  Any relevant
> information would be appreciated.

Maybe the problems are due to libstdc++ incompatibilities?
See my other message:

http://lists.boost.org/boost/2005/07/29883.php

Cheers,
Ralf




__ 
Yahoo! Mail 
Stay connected, organized, and protected. Take the tour: 
http://tour.mail.yahoo.com/mailtour.html 

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


Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-09 Thread Ralf W. Grosse-Kunstleve
--- NickC <[EMAIL PROTECTED]> wrote:
> I'd be very interested to hear your opinion on the 'namespace' module,
> which looks at addressing some of these issues (the Record object, in
> particular).  The URL is http://namespace.python-hosting.com, and any
> comments should be directed to the [EMAIL PROTECTED]
> discussion list.

Hi Nick,

The namespace module looks interesting, thanks for the pointer! (I saw your
other message but didn't have a chance to reply immediately.)

I tried out the namespace.Record class. The resulting user code looks nice, but
I have two concerns:

- It requires a different coding style; until it is well established it will
surprise people.

- The runtime penalty is severe.

Attached is a simple adopt_timings.py script. If I run it with Python 2.4.1
under RH WS3, 2.8GHz Xeon, I get:

overhead: 0.01
plain_grouping: 0.27
update_grouping: 0.44
plain_adopt_grouping: 0.68
record_grouping: 10.85

I.e. record_grouping (using namespace.Record) is about 40 times slower than the
manual self.x=x etc. implementation.

My conclusion is that namespace.Record may have merits for specific purposes,
but is impractical as a general-purpose utility like I have in mind.

Note that the attached code includes a new, highly simplified "plain_adopt()"
function, based on the information I got through other messages in this thread.
Thanks to everybody for suggestions!

Cheers,
Ralf




Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/import sys, os

class plain_grouping:
  def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

class update_grouping:
  def __init__(self, x, y, z):
self.__dict__.update(locals())
del self.self

def plain_adopt():
  frame = sys._getframe(1)
  init_locals = frame.f_locals
  self = init_locals[frame.f_code.co_varnames[0]]
  self.__dict__.update(init_locals)
  del self.self

class plain_adopt_grouping:
  def __init__(self, x, y, z):
plain_adopt()

try:
  from namespace import Record
except ImportError:
  Record = None
else:
  class record_grouping(Record):
x = None
y = None
z = None

class timer:
  def __init__(self):
self.t0 = os.times()
  def get(self):
tn = os.times()
return (tn[0]+tn[1]-self.t0[0]-self.t0[1])

def time_overhead(n_repeats):
  t = timer()
  for i in xrange(n_repeats):
pass
  return t.get()

def time(method, n_repeats):
  g = method(x=1,y=2,z=3)
  assert g.x == 1
  assert g.y == 2
  assert g.z == 3
  t = timer()
  for i in xrange(n_repeats):
method(x=1,y=2,z=3)
  return t.get()

def time_all(n_repeats=10):
  print "overhead: %.2f" % time_overhead(n_repeats)
  print "plain_grouping: %.2f" % time(plain_grouping, n_repeats)
  print "update_grouping: %.2f" % time(update_grouping, n_repeats)
  print "plain_adopt_grouping: %.2f" % time(plain_adopt_grouping, n_repeats)
  if (Record is not None):
print "record_grouping: %.2f" % time(record_grouping, n_repeats)

if (__name__ == "__main__"):
  time_all()
-- 
http://mail.python.org/mailman/listinfo/python-list

__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-09 Thread Ralf W. Grosse-Kunstleve
My initial proposal
(http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't
exactly get a warm welcome...

And Now for Something Completely Different:

class autoinit(object):

  def __init__(self, *args, **keyword_args):
self.__dict__.update(
  zip(self.__autoinit__.im_func.func_code.co_varnames[1:], args))
self.__dict__.update(keyword_args)
self.__autoinit__(*args, **keyword_args)

class grouping(autoinit):

  def __autoinit__(self, x, y, z):
print self.x, self.y, self.z

group = grouping(1,2,z=3)
group = grouping(z=1,x=2,y=3)
try: grouping(1)
except TypeError, e: print e
try: grouping(1,2,3,a=0)
except TypeError, e: print e


Almost like my original favorite solution, only better, and it doesn't require
a syntax change.

Under a hypothetical new proposal __autoinit__ would become a standard feature
of object.

Any takers?

Cheers,
    Ralf


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-09 Thread Ralf W. Grosse-Kunstleve
--- Kay Schluehr <[EMAIL PROTECTED]> wrote:
> Ralf, if you want to modify the class instantiation behaviour you

I don't. I simply want to give the user a choice:

__init__(self, ...) # same as always (no modification)
or
__autoinit__(self, ...) # self.x=x job done automatically and efficiently

If someone overrides both __init__ and __autoinit__, the latter will
have no effect (unless called from the user's __init__).

> should have a look on metaclasses. That's what they are for. It is not
> a particular good idea to integrate a new method into the object base
> class for each accidental idea and write a PEP for it.
 ^^
 ??

The flurry of suggestions indicates that many people have tried to find
some way to reduce the boilerplate burden, even though everybody seems
keen to point out that it is not that big a deal. It is not that big a
deal indeed. But it is bigger than the problem solved by, e.g.,
enumerate, and I believe it can be solved with a comparable effort.

> I provide you an example

Thanks.

> which is actually your use case.

Close, but not quite.

> It doesn't
> change the class hierarchy : the metaclass semantics is not "is a" as
> for inheritance but "customizes" as one would expect also for
> decorators.
> 
> class autoattr(type):
> '''
> The autoattr metaclass is used to extract auto_xxx parameters from
> the argument-tuple or the keyword arguments of an object
> constructor __init__
> and create object attributes mit name xxx and the value of auto_xxx
> passed
> into __init__
> '''
> def __init__(cls,name, bases, dct):
> super(autoattr,cls).__init__(name,bases,dct)
> old_init = cls.__init__
> defaults = cls.__init__.im_func.func_defaults
> varnames = cls.__init__.im_func.func_code.co_varnames[1:]
> 
> def new_init(self,*args,**kwd):
> for var,default in zip(varnames[-len(defaults):],defaults):

This doesn't work in general. You are missing "if (defaults is not None):"
as a condition for entering the loop.

> if var.startswith("auto_"):
> self.__dict__[var[5:]] = default
> for var,arg in zip(varnames,args):
> if var.startswith("auto_"):
> self.__dict__[var[5:]] = arg
> for (key,val) in kwd.items():
> if key.startswith("auto_"):
> self.__dict__[key[5:]] = val
> old_init(self,*args,**kwd)
> cls.__init__ = new_init

I couldn't easily time it because your approach changes the user
interface (what are implementation details becomes exposed as "auto_"),
but the code above is sure to introduce a serious runtime penalty.

I stripped your code down to the essence. See attachment.
For the user your approach then becomes:

  class grouping:
__metaclass__ = autoattr
def __init__(self, x, y, z):
  pass

My __autoinit__ suggestion would result in (assuming object supports
this by default):

  class grouping(object):
def __autoinit__(self, x, y, z):
  pass

I think that's far more intuitive.

The timings are:

  overhead: 0.00
  plain_grouping: 0.28
  update_grouping: 0.45
  plain_adopt_grouping: 0.69
  autoinit_grouping: 1.15
  autoattr_grouping: 1.01

Your approach wins out time-wise, mainly since you don't have to repeat
the expensive '*.im_func.func_code.co_varnames[1:]" 3 or 4 * getattr +
slicing operation for each object instantiation. However, I am hopeful
that a built-in C implementation could eliminate most if not all
runtime penalties compared to the hand-coded "plain_grouping"
approach.

Cheers,
Ralf





Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-09 Thread Ralf W. Grosse-Kunstleve
Sorry, I forgot the attachment.




Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/import sys, os

class plain_grouping:
  def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

class update_grouping:
  def __init__(self, x, y, z):
self.__dict__.update(locals())
del self.self

def plain_adopt():
  frame = sys._getframe(1)
  init_locals = frame.f_locals
  self = init_locals[frame.f_code.co_varnames[0]]
  self.__dict__.update(init_locals)
  del self.self

class plain_adopt_grouping:
  def __init__(self, x, y, z):
plain_adopt()

class autoinit(object):

  def __init__(self, *args, **keyword_args):
self.__dict__.update(
  zip(self.__autoinit__.im_func.func_code.co_varnames[1:], args))
self.__dict__.update(keyword_args)
self.__autoinit__(*args, **keyword_args)

class autoinit_grouping(autoinit):

  def __autoinit__(self, x, y, z):
pass

class autoattr(type):
  def __init__(cls, name, bases, dct):
super(autoattr, cls).__init__(name, bases, dct)
old_init = cls.__init__
varnames = old_init.im_func.func_code.co_varnames[1:]
def new_init(self, *args, **keyword_args):
  self.__dict__.update(zip(varnames, args))
  self.__dict__.update(keyword_args)
  old_init(self, *args, **keyword_args)
cls.__init__ = new_init

class autoattr_grouping:
  __metaclass__ = autoattr
  def __init__(self, x, y, z):
pass

try:
  from namespace import Record
except ImportError:
  Record = None
else:
  class record_grouping(Record):
x = None
y = None
z = None

class timer:
  def __init__(self):
self.t0 = os.times()
  def get(self):
tn = os.times()
return (tn[0]+tn[1]-self.t0[0]-self.t0[1])

def time_overhead(n_repeats):
  t = timer()
  for i in xrange(n_repeats):
pass
  return t.get()

def time(method, n_repeats):
  g = method(x=1,y=2,z=3)
  assert g.x == 1
  assert g.y == 2
  assert g.z == 3
  t = timer()
  for i in xrange(n_repeats):
method(x=1,y=2,z=3)
  return t.get()

def time_all(n_repeats=10):
  print "overhead: %.2f" % time_overhead(n_repeats)
  print "plain_grouping: %.2f" % time(plain_grouping, n_repeats)
  print "update_grouping: %.2f" % time(update_grouping, n_repeats)
  print "plain_adopt_grouping: %.2f" % time(plain_adopt_grouping, n_repeats)
  print "autoinit_grouping: %.2f" % time(autoinit_grouping, n_repeats)
  print "autoattr_grouping: %.2f" % time(autoattr_grouping, n_repeats)
  if (Record is not None):
print "record_grouping: %.2f" % time(record_grouping, n_repeats)

if (__name__ == "__main__"):
  time_all()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-09 Thread Ralf W. Grosse-Kunstleve
--- Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Should be:
>  class autoinit(object):
>  def __init__(self, *args, **keyword_args):
>  for name, value in zip(self.__autoinit__.im_func.func_code.
>  co_varnames[1:], args):
>  setattr(self, name, value)
>  for name, value in keyword_args.items():
>  setattr(self, name, value)
>  self.__autoinit__(*args, **keyword_args)

Thanks!
I didn't do it like this out of fear it may be too slow. But it turns out to be
faster:

  overhead: 0.00
  plain_grouping: 0.27
  update_grouping: 0.43
  plain_adopt_grouping: 0.68
  autoinit_grouping: 1.15
  autoinit_setattr_grouping: 1.08 # yours
  autoattr_grouping: 1.06

I am amazed. Very good!

Cheers,
Ralf




Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/import sys, os

class plain_grouping:
  def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

class update_grouping:
  def __init__(self, x, y, z):
self.__dict__.update(locals())
del self.self

def plain_adopt():
  frame = sys._getframe(1)
  init_locals = frame.f_locals
  self = init_locals[frame.f_code.co_varnames[0]]
  self.__dict__.update(init_locals)
  del self.self

class plain_adopt_grouping:
  def __init__(self, x, y, z):
plain_adopt()

class autoinit(object):

  def __init__(self, *args, **keyword_args):
self.__dict__.update(
  zip(self.__autoinit__.im_func.func_code.co_varnames[1:], args))
self.__dict__.update(keyword_args)
self.__autoinit__(*args, **keyword_args)

class autoinit_grouping(autoinit):

  def __autoinit__(self, x, y, z):
pass

class autoinit_setattr(object):
  def __init__(self, *args, **keyword_args):
for name, value in zip(self.__autoinit__.im_func.func_code.
 co_varnames[1:], args):
  setattr(self, name, value)
for name, value in keyword_args.items():
  setattr(self, name, value)
self.__autoinit__(*args, **keyword_args)

class autoinit_setattr_grouping(autoinit_setattr):

  def __autoinit__(self, x, y, z):
pass

class autoattr(type):
  def __init__(cls, name, bases, dct):
super(autoattr, cls).__init__(name, bases, dct)
old_init = cls.__init__
varnames = old_init.im_func.func_code.co_varnames[1:]
def new_init(self, *args, **keyword_args):
  self.__dict__.update(zip(varnames, args))
  self.__dict__.update(keyword_args)
  old_init(self, *args, **keyword_args)
cls.__init__ = new_init

class autoattr_grouping:
  __metaclass__ = autoattr
  def __init__(self, x, y, z):
pass

try:
  from namespace import Record
except ImportError:
  Record = None
else:
  class record_grouping(Record):
x = None
y = None
z = None

class timer:
  def __init__(self):
self.t0 = os.times()
  def get(self):
tn = os.times()
return (tn[0]+tn[1]-self.t0[0]-self.t0[1])

def time_overhead(n_repeats):
  t = timer()
  for i in xrange(n_repeats):
pass
  return t.get()

def time(method, n_repeats):
  g = method(x=1,y=2,z=3)
  assert g.x == 1
  assert g.y == 2
  assert g.z == 3
  t = timer()
  for i in xrange(n_repeats):
method(x=1,y=2,z=3)
  return t.get()

def time_all(n_repeats=10):
  print "overhead: %.2f" % time_overhead(n_repeats)
  print "plain_grouping: %.2f" % time(plain_grouping, n_repeats)
  print "update_grouping: %.2f" % time(update_grouping, n_repeats)
  print "plain_adopt_grouping: %.2f" % time(plain_adopt_grouping, n_repeats)
  print "autoinit_grouping: %.2f" % time(autoinit_grouping, n_repeats)
  print "autoinit_setattr_grouping: %.2f" % time(autoinit_setattr_grouping, 
n_repeats)
  print "autoattr_grouping: %.2f" % time(autoattr_grouping, n_repeats)
  if (Record is not None):
print "record_grouping: %.2f" % time(record_grouping, n_repeats)

if (__name__ == "__main__"):
  time_all()
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-10 Thread Ralf W. Grosse-Kunstleve
--- Kay Schluehr <[EMAIL PROTECTED]> wrote:

>  > I stripped your code down to the essence. See attachment.
> > For the user your approach then becomes:
> >
> >   class grouping:
> > __metaclass__ = autoattr
> > def __init__(self, x, y, z):
> >   pass
> 
> No. This is clearly NOT what I had in mind. I translated your original
> proposal which introduced a punctuation syntax '.x' for constructor
> parameters forcing the interpreter to create equally named object
> attributes into a naming convention that can be handled by a metaclass
> customizer.

I see.

> The grouping.__init__ above does exacly nothing according
> to my implementation. I would never accept dropping fine-tuning
> capabilities. The "auto_" prefix is all the declarative magic.

I got only negative feedback regarding the fine-tuning idea, e.g.
http://mail.python.org/pipermail/python-list/2005-July/288833.html. After
thinking about it for a while I also came to the conclusion that runtime
performance and simplicity is indeed the higher value for a general-purpose
solution. Without a supporting syntax change (the idea received almost hysteric
opposition) I don't think fine-tuning can be supported without a noticeable
runtime-penalty.

My syntax-change proposal was meant not to change the user interface. I.e. it
was meant to preserve "grouping(x=1,y=2,z=3)", no matter how x,y,z are handled
in the constructor. Under your proposal the decision to use "auto init" becomes
 a visible part of the user interface and may therefore be irreversible in
practical applications.

> > My __autoinit__ suggestion would result in (assuming object supports
> > this by default):
> >
> >   class grouping(object):
> > def __autoinit__(self, x, y, z):
> >   pass
> >
> > I think that's far more intuitive.
> 
> Being intuitive is relative to someones intuition. 

If someone looks at the code there is no question he/she knows immediately what
is going on. In contrast, the __metaclass__ statement is potentially separated
from the __init__ definition by unrelated code, leading to surprises (on top of
intimidation for beginners). I don't think that's the best style. It is
generally better if the framework doesn't allow for artificial separations in
the first place.

Cheers,
Ralf

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)

2005-07-11 Thread Ralf W. Grosse-Kunstleve
--- Bengt Richter <[EMAIL PROTECTED]> wrote:
> >I still think it's too specialized. What would, hypothetically, this do?
> >
> >class Bar: pass
> >
> >class Foo:
> >x = Bar()
> >def method_1(self, x.y):
> >pass
> >
> >It's hard to explain that you can autoassign self.y but not x.y.
> >
> No, that limitation wouldn't exist, so you wouldn't have to explain it ;-)
> I.e., the above would act like
> 
>  class Foo:
>  x = Bar()
>  def method_1(self, _anonymous_arg_1):
>  x.y = _anonymous_arg_1
> 
> and would do whatever it would do now (probably look for a global x or a
> closure cell x, but
> it wouldn't find the class variable in a normal method call)

I am a bit afraid of opening a door for weird side effects. E.g.

class unrelated: pass
u = unrelated()

class grouping:
  def __init__(self, self.x, u.y, self.z):
pass

Is this really a good thing to allow? I am afraid it will be abused. My prime
concern was to provide a good solution for a very common problem. If we stray
too far from this most important goal we may get nothing in the end.

"self" (or whatever people prefer as a name for the first argument of a bound
function) *is* special. I think therefore it deserves special support.

I think it would be fantastic if we could push through the

  def __init__(self, self.x, y, self.y)

syntax, with the explicit limitation that only the first argument can be used
on the left side of the dot. I'd also happily settle for a decorator approach,
__autoinit__ or over variations, as long as they are built-in and easy to
remember/use/explain to a novice. However, to me the self.x approach seems to
be "just right" because:

  1. It is a good compromise between "redundant" and "explicit"; i.e.:

  too redundant:

def __init__(self, x, y, z):
  self.x = x
  self.y = y
  self.z = z

  middle ground:

def __init__(self, self.x, self.y, self.z):
  pass

  the other extreme:

def __init__(self, .x, .y, .z):
  pass

I am thinking people can understand the "middle ground" approach even
without looking at release notes and will not be surprised if unrelated.y
doesn't work.

  2. This approach is open to full optimization for runtime performance
 and should therefore be faster than the redundant conventional
 approach. I.e. the arguments can directly be inserted into the
 desired dictionary (or slot), without ever being added to locals().

  3. The user can always write "grouping(x=1,y=2,z=3)". I.e. how the
 arguments are used is strictly an implementation detail, as it
 should be.

Cheers,
Ralf





Sell on Yahoo! Auctions – no fees. Bid on great items.  
http://auctions.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >