Re: string to list of numbers conversion
[EMAIL PROTECTED] skrev: > Hi, > I have a string '((1,2), (3,4))' and I want to convert this into a > python tuple of numbers. I think your question is deeper and more natural than is clear from the many recepies given so far in this thread, so I'll take on another point of view, >From a language design perspective, there is no reason why not the parsing capacity of the Python interpreter would be accessible in a modular fashion to the user/programmer. E.g used like this: I an imaginable Python, define you expect for an answer. In this case: (1) # import junctions, types from maybefuture:-) string = ((1,2), (3,4)) type a = tuple a | int myTuple = eval(string, goal=a) Obviously, if you expect _only_ the given form, then this might be better: (2) # import types from maybefuture:-) type a = ((int,int),(int,int)) myTuple = eval(string, goal=a) Note the use of a "a|b" in line 2 (I think Perl 6 is among the few programming languages giving a reasonable semantics to junctions so far). Version 2 above sholud not be a big addition to Python conceptually. Motivation: It is easy to think clearly about. It makes it easier to use eval safely and makes code more readable. This is a topic of interest to me, so feel free to post either on list or directly to me. Thanks/Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: Best practices for software architecture in Python
On 2021-02-10, Python wrote: > Hi, > > If you had to train engineers who are used to write > Python scripts for image processing, data format conversion, > etc. (so they know most the basics of Python types and > programming structures except advanced OOP techniques) > who now are about to develop quite a big application > in the same field (to get rid of some well known proprietary > scientific software monoliths), and would like to study in-depth > an existing open source application in order to study how > to organize classes hierarchy, modules, packages, etc. which > one would you recommend ? > > P. Looks like you (the project leader?) needs training, not the software engineers. "Making Things Happen" by Scott Berkun -H -- Henning Follmann | hfollm...@itcfollmann.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Best practices for software architecture in Python
On 2021-02-11, Oscar wrote: > In article , > Henning Follmann wrote: >>On 2021-02-10, Python wrote: >>> Hi, >>> >>> If you had to train engineers who are used to write >>> Python scripts for image processing, data format conversion, >>> etc. (so they know most the basics of Python types and >>> programming structures except advanced OOP techniques) >>> who now are about to develop quite a big application >>> in the same field (to get rid of some well known proprietary >>> scientific software monoliths), and would like to study in-depth >>> an existing open source application in order to study how >>> to organize classes hierarchy, modules, packages, etc. which >>> one would you recommend ? >>> >>> P. >> >>Looks like you (the project leader?) needs training, not the >>software engineers. >> >>"Making Things Happen" by Scott Berkun > > This looks like a very interesting book to add to my reading list, but > how do you think it will help the OP with his/her quest? > Well the question makes it very obvious that it is a leadership issue. Does he really think giving all engineers the Gang of 4 book will magically lead to a well run OOP project. It all but always is about the leader. > Of course your answer might just as well be: read the book! But since > you clearly did that already, what knowledge did you gain that triggered > this response? Well this book exemplifies how to brake down the task of leadership in the context of software development. For me this seems like a match. -H -- Henning Follmann | hfollm...@itcfollmann.com -- https://mail.python.org/mailman/listinfo/python-list
Importing from upper packages
I have a library with the following structure: library /app /db /gui /interface.py /wx /class.py Each __init__.py file imports the next sub-package. E.g.: library/__init__.py: import app, db, gui library/gui/__init__.py: import wx from interface import * library/gui/wx/__init__.py: from class import * >From the lowest layer "wx" I need to import an interface defined in the gui package. Therefore I tried the following in library/gui/wx/class.py: import library class ClassTest( libor.gui.Interface): pass I also set the PYTHONPATH to top directory, but I still get an ImportError. How could this problem be solved or otherwise, how should I import from upper packages in general? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing from upper packages
Am Tue, 01 Mar 2005 21:45:17 +0100 schrieb Henning Kage: > import library > > class ClassTest( libor.gui.Interface): >pass Sorry, a small mistake: class ClassTest( library.gui.Interface): pass -- http://mail.python.org/mailman/listinfo/python-list
MySQL-python-1.0.0.win32-...
Could anybody please provide me with a "compiled" version of the above (MySQLdb 1.0.0 for Python on Win 2000 / XP) for Python version 2.4, as I do not have any possibility of compiling?? Many thanks in advance Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: ANNOUNCE: Ice 2.0 released
> Does the Ice team claim any advantages to their Python bindings to > CORBA over omniORBpy (The one I am currently using). [...] > But I was wondering if there are any dynamic language > oriented improvements in ICE bindings? The Ice Python mapping is simpler than the CORBA one because Ice has a simpler object model with fewer data types. So, Ice avoids the complexities caused by things such as type Any, TypeCodes, value types, bounded sequences, arrays, unions, the fixed type, unsigned versus signed types, and wide versus narrow characters and strings. Other than that, the Ice Python mapping is quite similar to the CORBA one, mainly because, for most language mapping issues, the design problems and (sensible) solutions are the same. As far as dynamic improvements are concerned, Ice for Python is a bit more flexible than omniORBpy. As with omniORBpy, you can put interface definitions through a compiler to generate stubs and skeletons but, in addition, you can also use Ice for Python without precompiling the interface definitions and, instead, load them at run time. As an example, assume you have a definition as follows: module M { enum Color { red, green, blue }; }; Instead of compiling the definition, you can write: Ice.loadSlice("Color.ice") import M print "My favourite color is ", M.Color.blue Which approach (precompiled or dynamically loaded) you use depends on the specifics of your application. Dynamically loaded definitions are useful especially for things such as test harnesses and short throw-away programs, because not having to compile the definitions first reduces complexity and makes the application more compact (because it doesn't depend on a bunch of additional files that would be created by pre-compiling the definitions). Of course, the price you pay is a (small) delay during start-up because the code is generated at run time rather than compile time. Cheers, Michi. -- Michi Henning Ph: +61 4 1118-2700 ZeroC, Inc.http://www.zeroc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ANNOUNCE: Ice 2.0 released
On Thu, 9 Dec 2004, Duncan Grisby wrote: > In article <[EMAIL PROTECTED]>, > Michi Henning <[EMAIL PROTECTED]> wrote: > > [...] > >Instead of compiling the definition, you can write: > > > >Ice.loadSlice("Color.ice") > >import M > > > >print "My favourite color is ", M.Color.blue > > Just like this then? > > omniORB.importIDL("Color.idl") > import M > > print "My favourite color is ", M.blue Oops, my apologies! I wasn't aware that omniORBpy does this as well. Cheers, Michi. -- Michi HenningPh: +61 4 1118-2700 ZeroC, Inc. http://www.zeroc.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Resuming a program's execution after correcting error
Sheldon wrote: > MRAB wrote: >> Sheldon wrote: >>> MRAB wrote: >>>> Sheldon wrote: >>>>> Hi. >>>>> >>>>> Does anyone know if one can resume a python script at the error point >>>>> after the error is corrected? >>>>> I have a large program that take forever if I have to restart from >>>>> scratch everytime. The error was the data writing a file so it seemed >>>>> such a waste if all the data was lost and must be recalculated again. >>>>> Sorry if this is off-topic here but Dylan (http://www.opendylan.org) is a nice language (I sometimes like even more than python itself) that allows you to continue the work right where the exception was thrown. Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: python3 - the hardest hello world ever ?
> Many thanks, it works when setting the LANG environment variable. BTW: For Windows users, when running Python command-line programs, you can also modify the properties of the "cmd.exe" window and tell windows to use the TT Lucida Console font instead of the raster font. Then, before starting the Python program, do a CHCP 1252 This way the sys.stdout.encoding will be cp1252 (tested with Python 2.4.3 and 2.5.1). -- http://mail.python.org/mailman/listinfo/python-list
How to build Python 2.6.2 on HP-UX Itanium with thread support?
Our program that makes use of cx_Oracle and multi-threading (and works fine on Windows, Linux and other platforms, including HP-UX PA-RISC), fails to run on HP-UX Itanium. When trying to start the first daemon thread, the program raises an exception: ... File "/usr/local/lib/python2.6/threading.py", line 471, in start _start_new_thread(self.__bootstrap, ()) error: can't start new thread I guess there's something wrong with the way we built Python, but I have absolutely no clue what (I'm not too familiar with HP-UX). >From what I found in the internet, it's probably something about the threading libraries at the C level. So the question is: Which steps are necessary to build Python 2.6.2 (32bit or 64bit) on HP- UX Itanium 11.31 with working multi-threading support? Note: For whatever reasons, in order to get cx_Oracle 5.0.1 to work on HP- UX, I have to build it as a built-in module. That's why I have to build Python myself (and unfortunately there's no Python 2.6.2 binary distribution for HP-UX itanium available). Everything works fine except multi-threading. Before running configure and make, I set up the environment like this: export PATH=$PATH:/usr/local/bin export CPPFLAGS=-I/opt/openssl/0.9.8/include export LDFLAGS="-L/usr/lib/hpux32 -L/usr/local/lib/hpux32 -L/opt/ openssl/0.9.8/lib" I have the files generated by configure and make available, but it's too much to post it all, as as I don't know what is relevant and what not. So, here's just the first few lines of the config.log output: This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by python configure 2.6, which was generated by GNU Autoconf 2.61. Invocation command line was $ ./configure --with-zlib --with-openssl ## - ## ## Platform. ## ## - ## hostname = polref4 uname -m = ia64 uname -r = B.11.31 uname -s = HP-UX uname -v = U -- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
New info: The problem is not related to the specific program - it is definitely a build problem, as the following test shows: Python 2.6.2 (r262:71600, Apr 28 2009, 17:38:15) [GCC 4.2.3] on hp-ux11 Type "help", "copyright", "credits" or "license" for more information. >>> import threading >>> threading._test() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/threading.py", line 952, in _test t.start() File "/usr/local/lib/python2.6/threading.py", line 471, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread >>> The compiler I used was GCC 4.2.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to build Python 2.6.2 on HP-UX Itanium with thread support?
Daniel: > What do you get with: > import thread > thread.start_new_thread(int, ('1',2)) > This results in the same error message: thread.error: can't start new thread Aahz: > You probably want to start by figuring out which threading library is > being used -- Python normally wants Posix threads, but IIRC, that's not > the default on HP-UX, and you may need to fix the build process to use > Posix. You're probably right, but I'm lost here, since I'm neither a *nix nor a HP-UX expert in building software from source. I'm used to "configure; make; make install", which usually works well on other platforms... Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: re.search much slower then grep on some regular expressions
When trying to find an alternative way of solving my problem i found that running this script: #!/usr/bin/env python import re row="" for a in range(156000): row+="a" print "How many, dude?" print re.search('/[^ "=]*',row) (the / has moved) wouldn't take even a second (The re.search part of course) This is for me very strange since this, in theory, is the same problem as before. /Henning Thornblad -- http://mail.python.org/mailman/listinfo/python-list
Re: re.search much slower then grep on some regular expressions
On Jul 8, 2:48 am, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 8, 2:51 am, Henning Thornblad <[EMAIL PROTECTED]> > wrote: > > > > > When trying to find an alternative way of solving my problem i found > > that running this script: > > > #!/usr/bin/env python > > > import re > > > row="" > > for a in range(156000): > > row+="a" > > print "How many, dude?" > > print re.search('/[^ "=]*',row) (the / has moved) > > > wouldn't take even a second (The re.search part of course) > > > This is for me very strange since this, > > in theory, is the same problem as before. > > In theory. In practice, it is the same problem *iff* you start at the > end of the text and work backwards. > > Your original pattern can be characterised as X*Y, where X and Y are > character classes; your new one is YX*. You are asking each to search > a text that contains many Xs and no Ys. > > The second pattern will cause a naive search engine to examine each > character in the text (is it a Y?) as a candidate for the start of a > successful match; each test fails, and the whole expedition has cost > O(N). > > OTOH, the first pattern will start at offset 0, cheerfully cruising > past all those lovely Xs, but failing (no Y) at the end of the text. > It will then think that it's been too greedy, reduce the matched span > of X* from N characters to N-1, fail to find Y, N-2, fail, ... so > that's O(N) just for the first trial starting from offset 0. Being > naive, it will try again starting from offset 1, 2, 3, ... an O(N**2) > process. If Y were instead something more complicated, it would be > worse than O(N**2). > > If you were to tell us what you are actually trying to do, we could > probably help you with a faster method. > > BTW, if the text is 'aaa///bbb///ccc', your original search will find > 'aaa///bbb///'; if you want it to find 'aaa/', the pattern should be: > '[^ "=/]*/' > > Cheers, > John What we had was a regex that searched textfiles, row for row, for an absolute path starting/ending with ", = or blank space. The path have a known signature which is pretty unique and the regex looked like this: [^ ="]*/[^ ="]*signature[^ =]*/ So we didn't really see any performance loss until we got an textfile with some really long rows, one reaching 156,000 characters. We removed the cause of these long rows. But also decided to tune the regex making it more scalable. I have though of two possible soultions: 1. Invert [^ ="] so that it becomes [alot of charcters you could find in a path] 2. Add [ ="]: [ ="][^ ="]*/[^ ="]*signature[^ =]*/[ ="] and just trim them later They both work good performance wise but i can't figure out which one is the less ugly. Anyway, I'm glad I asked the question. I have learned more about regex then i ever thought i'd need :) Many Thanks Henning Thornblad -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing different versions of a module
Why not set up PYTHONPATH together with other environment variables in a shell script (bash, or CMD on Windows) and call that shell script instead of your Python script directly? This is probably the easiest and still a very powerful and generic solution for this kind of problem. We do it that way regardless of the programming language used. Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: A Lambda Logo Tour
Scripsit "Xah Lee" <[EMAIL PROTECTED]> > Subroutines in lisps easily have side-effects, and sometimes > non-functional programing methodologies such as OOP are actually > encouraged in lisp. As most of you know, the lambda symbol chosen by > functional languages is to signify no side-effects. What are you smoking? You're sure you could stop anytime you wanted, right? -- Henning Makholm"What a hideous colour khaki is." -- http://mail.python.org/mailman/listinfo/python-list
Cast into custom type
Hi, I created a plugin mechanism for my application orientating at the mechanism described by Martin Alchy in http://martyalchin.com/2008/jan/10/simple-plugin-framework/ Now I'd like to call methods like `initialize(parent)' when the user chooses to use a plugin. As described in the blog mentioned above, I only have access to the general type called `PluginMount' (holding all the actual plugin instances). I tried to define "abstract" methods in PluginMount type raising a `NotImplementedError' but it seems, there is no late binding (similar to Java), so the right method would be called. Only the message TypeError: unbound method initialize() must be called with GeoCache instance as first argument (got PluginMount instance instead) `GeoCache' would be the plugin type. What is strange, is the fact, that when asking what instances are hold by PluginMount [] is listed. So it seems, that no late binding is applied when calling the `initialize(self, parent)' method. I'm quite new using Python, so this might be a quite basic question caused by some misunderstandings in general. Feel free to point me to appropriate site to solve my problem. Thanks in advance. Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: Cast into custom type
Diez, Gabriel, Steven, thanks for your answers. I'll mainly give response in this posting, so I hope not repeating myself. On Tue, 03 Nov 2009 10:18:29 +, Steven D'Aprano wrote: > On Tue, 03 Nov 2009 09:41:37 +, Henning Bredel wrote: > >> Now I'd like to call methods like `initialize(parent)' when the user >> chooses to use a plugin. As described in the blog mentioned above, I >> only have access to the general type called `PluginMount' (holding all >> the actual plugin instances). >> >> I tried to define "abstract" methods in PluginMount type raising a >> `NotImplementedError' but it seems, there is no late binding (similar >> to Java), so the right method would be called. > > You need to give some actual examples of what you are trying to do, and > what you are expecting to happen. How is initialized() being called? Example: Assume a framework which offers common functionality for a plugin or a module a user can choose at the beginning. The framework does not know the concrete type of the plugin so it is possible to extend it by implementing a well known interface or abstract class. The framework reads the plugin directory, loads each module and creates buttons for each plugin with a callback method for initializing. To use common functionality of the framework, initialization method takes it as the parent parameter. I think this listing makes the most sense to you: # initialize all plugins self._plugin_modules = _load_plugins() # imp loading here LOGGER.debug(ActionProvider.plugins) # print what was loaded for plugin in ActionProvider.plugins: # create button for each app_button = gtk.Button(plugin.title) LOGGER.debug('Title of plugin: %s' % plugin.title) app_button.connect("clicked", plugin.initialize(plugin, self), None) self.set_canvas(app_button) app_button.show() >> TypeError: unbound method initialize() must be called with GeoCache >> instance as first argument (got PluginMount instance instead) > > Sounds like you are calling initialize on the class instead of on an > instance. I'm *guessing* that you are doing something like this: Oh, I didn't expext PluginMount to hold only classes :/. When calling `LOGGER.debug('Title of plugin: %s' % plugin.title)' the global (not class attribute) `title' attribute is printed out though. Probably some misinterpretation, too ..?! > (1) Change the for-loop to: > > for cls in plugin_manager.plugins: > cls().initialize(plugin_Manager) Good guess .. but calling it in that way another error says app_button.connect("clicked", plugin().initialize(self), None) TypeError: __init__() takes exactly 2 arguments (1 given) But also app_button.connect("clicked", plugin().initialize(plugin, self), None) TypeError: __init__() takes exactly 2 arguments (1 given) That is strange, because neither initialize() nor __init__ of the plugin is called .. only a logging statement shall print a msg. I hope it got a bit clearer what I am intended to do. Thanks for your help. Henning -- http://mail.python.org/mailman/listinfo/python-list
Re: Cast into custom type
Gabriel, thanks for your reply. See my comments below. On Tue, 03 Nov 2009 21:31:27 -0300, Gabriel Genellina wrote: > En Tue, 03 Nov 2009 09:07:01 -0300, Henning Bredel > escribió: >> On Tue, 03 Nov 2009 10:18:29 +, Steven D'Aprano wrote: > > Then forget about the code you read in that blog post, doesn't apply to > your use case. Well, but it shows how to mount plugins into the application without creating instances instantly. I only use one plugin/module at a time, so I'd like to avoid holding instances which aren't used. If the solution from the blogpost are meant completely different, I'd appreciate if you could point me on some concrete arguments why I shouldn't realize plugin mechanism in that way. BTW: I made it work now (was only a(nother) misinterpretation of how a callable should look like. > Try something like this: [...] > class PluginManager: > def __init__(self, plugin_directory): > self.plugin_directory = plugin_directory self.plugins = [] > > def load_all(self): > for fn in glob(os.path.join(self.plugin_directory, '*.py')): > namespace = {} > execfile(fn, namespace) > for name, obj in namespace.items(): > if (isinstance(obj, type) and > issubclass(obj, Plugin) and > obj is not Plugin): > # obj is a Plugin subclass > cls = obj > print cls.__name__, fn > print cls.__doc__ > print > plugin = cls(self) # call the constructor > self.plugins.append(plugin) [...] Yes, I get your point. But you instantiate all available plugins. I'd like to avoid that. Will a callable like `plugin().initialize' avoid that, or is an instance created immediately when passing this callable? > Plugin is the base class; all plugins must inherit from it. PluginMgr > scans the plugin directory, executes all modules it finds there (be > careful...), and looks for Plugin subclasses. Then creates an instance > of each Plugin subclass. Well, as far I understand it, I'd say that the ActionProvider class from the blogpost is the (nearly) the same as your Plugin base class. All new plugins has to implement the abstract ActionProvider class. The module loading/recognizing is done by my main application. So what would be the main difference here? Thanks for your advice Henning -- http://mail.python.org/mailman/listinfo/python-list