Re: O'Reilly Python Certification
On Wednesday, September 3, 2014 5:53:12 PM UTC-4, jaron...@gmail.com wrote: > Ethan, Steve, Tim, and others: > > > > I'm thinking of taking the program. How long, in hours, does it take to > complete all four Python courses? I'm currently taking the first out of four modules. I have extensive PHP knowledge and I also have a certification by Zend so programming is not new to me. I've never done anything at all with Python. I've already completed 12 out of the 16 lessons and so far the reading has taken me from 15 to 30 minutes and the code assignments no more than 10. There was one exception that took me 30 minutes as I wasn't sure what the hell they were asking (it was a very obscure and useless algorithm which hasn't been the case on any of the other assignments). On top of that you have to answer 2 quizzes and each quiz usually has 2 questions (no more than 5). Those usually take 1 to 3 minutes max as they are mostly syntax or concepts but not coding. As I said, this is only true for the first module as I haven't taken the others yet. But if you already know programming and have a few years of coding experience you will breeze through the first module in probably 3 days (assuming you only do that). The syllabus for the other modules suggests (to me) that going so fast would not be that easy. -- https://mail.python.org/mailman/listinfo/python-list
adding python scripting to my application
Hi, first of all, I have to say I am new to Python. I have been working with a finite element analysis program written in c++. now, I am trying to 'rebuild' this code (possibly a full re-write) with scripting capability. I did some reading on the web, and found that there are two ways to do this : extending and embedding. and I still haven't figured out what I should be using. I guess the first thing is to figure out what I am to do with the scripting capability - at the very least, I would like to run parametric analyses - run multiple analysis models by changing certain parameters using for loops. i found that the commercial fea package - abaqus uses python as well - I don't know whether they embedded or extended ? is there any way to find out? another fea application called OOF2 (http://www.ctcms.nist.gov/oof/oof2/#features) says "OOF2 is completely scriptable in Python". and I don't really understand what that means... maybe I haven't grasped the full potential of what python scripting could do for an fea program. can you tell me how to decide what path I should take - embed or extend ? or maybe some one could point me to some document/webpage that talks about this. thanks a lot, Julian. PS, my fea program uses its own script to read the analysis model information using the c++ iostream and our own parsing functions - but I don't have to stick to those function when I am writing the new code. -- http://mail.python.org/mailman/listinfo/python-list
Re: adding python scripting to my application
"martdi" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Jerry wrote: >> I am not a Python guru by any means, but I believe that when an >> application says that you can "script" their application with Python, >> it means that you can actually write Python code to interact with the >> application. Embedding may be the same thing. Extending (as I read >> it) involves writing portions of your program in Python and have do the >> logic portions. >> >> If you would like to allow users to write small scripts that interact >> with your program and control it (a la VBScript or AppleScript), then I >> believe embedding Python in your program is what you want. >> >> If you would like Python to run various parts of your program in order >> to make some portions easier to write/manage/whatever, then you want to >> "extend" your program using Python. >> >> The key difference being that you aren't providing a way for someone >> else to interact with your program using Python if you are extending. >> >> Again, I am not a guru and a read through the docs on python.org would >> probably be the best place to get sound technical advice on these >> subjects. >> >> -- >> Jerry > > > I'm not sure either, but I though Extending was making the C/C++ Code > available from Python, while Embedding was making Python Code Available > in your app. > Like I mentioned in my first post, one of the purposes of linking to python would be to run multiple cases in a for loop. that would mean passing information from the python script to my c++ application. mean python would have to be the top-level program. so, I think I should be looking at extending my program. I am going to look at using swig for this.. thanks, Julian. -- http://mail.python.org/mailman/listinfo/python-list
nested popen4
Hi all, I know it's a kind of bizarre question but here I go: I want to execute an script using popen4. This script executes a command in turn using popen4 too. The first one throws a 256 exit code. Any suggestions? Thanks J. -- http://mail.python.org/mailman/listinfo/python-list
Design question about pretree classifier
Hello, I've got a design problem for a classifier. To make it short: it maps strings on strings. Some strings have exactly one classification, some none and some more than one. There's a method classify(self, word) wich classifies a word. For the first case there's no problem: - one classification: return the value (it's a string) But: - none classification: return an exception or None? I think None is better, hence its not an exception that there is no classification but a defined state. What do you think? - many classifications: what to do? retun a sequence of strings? raise an exception and implement another method wich returns than the classifications? what should I do here? thanks for your answers! -- http://mail.python.org/mailman/listinfo/python-list
Re: Design question about pretree classifier
On 18 Dez., 18:59, Steve Holden wrote: > Julian wrote: > > Hello, > > > I've got a design problem for a classifier. To make it short: it maps > > strings on strings. > > > Some strings have exactly one classification, some none and some more > > than one. > > > There's a method classify(self, word) wich classifies a word. For the > > first case there's no problem: > > > - one classification: return the value (it's a string) > > > But: > > > - none classification: return an exception or None? I think None is > > better, hence its not an exception that there is no classification but > > a defined state. What do you think? > > - many classifications: what to do? retun a sequence of strings? raise > > an exception and implement another method wich returns than the > > classifications? what should I do here? > > > thanks for your answers! > > Always return a list or tuple. For no classifications it should be > empty, for one classification it should have one element, ... , for N > classifications it should have N elements. > thanks, sounds simple and good! > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list
Your beloved python features
Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread "hidden features of Python". I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask "why should I use python?". For those guys would be a poster quite cool which describes the most popular and beloved python features. So, may you help me please? If there's a similar thread/blogpost/ whatever, please give it to me, google couldn't. Regards Julian -- http://mail.python.org/mailman/listinfo/python-list
unable to mkvirtualenv
Hi, when creating a virtualenv with mkvirtualenv, I receive an error: http://pastebin.com/1N8yRZUv I've updated the relating packages (virtualenv, virtualenvwrapper, distutils, distribute, pip) and couldn't solve my problem via google. -- http://mail.python.org/mailman/listinfo/python-list
add bitbucket repo url to install_requires
Hi, I'm developing a django app which depends on an app in a private bitbucket repository, for example ssh://h...@bitbucket.org/username/my-django-app. is it possible to add this url to the list of install_requires in my setup.py? tried various possibilities, but none worked. -- http://mail.python.org/mailman/listinfo/python-list
Re: unable to mkvirtualenv
On 5 Okt., 10:17, Julian wrote: > Hi, > > when creating a virtualenv withmkvirtualenv, I receive an error: > > http://pastebin.com/1N8yRZUv > > I've updated the relating packages (virtualenv, virtualenvwrapper, > distutils, distribute, pip) and couldn't solve my problem via google. jannis leidel posted the solution via twitter: http://bitbucket.org/tarek/distribute/issue/168/ solution was commenting the following line: # export PYTHONDONTWRITEBYTECODE=1 in .bashrc. -- http://mail.python.org/mailman/listinfo/python-list
Please can i have your attention
Dear , Please can I have your attention and possibly help me for humanity's sake please. I am writing this message with a heavy heart filled with sorrows and sadness. Please if you can respond, i have an issue that i will be most grateful if you could help me deal with it please. Julian -- https://mail.python.org/mailman/listinfo/python-list
Re: Ref-strings in logging messages (was: Performance issue with CPython 3.10 + Cython)
On Fri, 7 Oct 2022 18:28:06 +0100 Barry wrote: > > On 7 Oct 2022, at 18:16, MRAB wrote: > > > > On 2022-10-07 16:45, Skip Montanaro wrote: > >>> On Fri, Oct 7, 2022 at 9:42 AM Andreas Ames > >>> > >>> wrote: > >>> 1. The culprit was me. As lazy as I am, I have used f-strings all over the > >>> place in calls to `logging.logger.debug()` and friends, evaluating all > >>> arguments regardless of whether the logger was enabled or not. > >>> > >> I thought there was some discussion about whether and how to efficiently > >> admit f-strings to the logging package. I'm guessing that's not gone > >> anywhere (yet). > > Letting you pass in a callable to call might help because that you could > > use lambda. > > Yep, that’s the obvious way to avoid expensive log data generation. > Would need logging module to support that use case. I have some logging code that uses eval() to evaluate expressions using locals and globals in a parent stack frame, together with a parser to find `{...}` items in a string. I guess this constitutes a (basic) runtime implementation of f-strings. As such it can avoid expensive evaluation/parsing when disabled, though it's probably slow when enabled compared to native f-strings. It seems to work quite well in practise, and also allows one to add some extra formatting features. For details see: https://git.ghostscript.com/?p=mupdf.git;a=blob;f=scripts/jlib.py;h=e85e9f2c4;hb=HEAD#l41 - Jules -- http://op59.net -- https://mail.python.org/mailman/listinfo/python-list
Re: UDP decode
Thanks for response! I don't know what can appear because the values changes 30 times per second. I only know the format. -- https://mail.python.org/mailman/listinfo/python-list
Creating anonymous functions using eval
I've been playing with a function that creates an anonymous function by compiling a string parameter, and it seems to work pretty well: def fn( text): exec 'def foo' + text.strip() return foo This can be used like: def foo( x): print x( 2, 5) foo( fn( ''' ( x, y): print 'x^2 + y^2 = ', x*x + y*y return y ''')) - which outputs: x^2 + y^2 = 29 5 You can also mimic conventional function definitions: f = fn( ''' ( x, y): print 'x, y=', x, y print 1.0*x/y return y ''') print 'calling f' f( 5, 6) This outputs: calling f x, y= 5 6 0.8333 You do things like allow/require an initial `def' for clarity, check that all the lines of text are indented so that nothing is executed when the anonymous function is created, etc etc. Obvious disadvantages are that the function text may have to escape quotes, and will not be showed with syntax colouring in editors. Apart from that, it seems quite a useful way of overcoming the limitations of python's lambda. But... I haven't seen this technique mentioned anywhere, so does anyone know of any problems that I should be wary of? - Julian -- http://www.op59.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating anonymous functions using eval
On 12 Jul 2005 08:28:45 -0700 "Devan L" <[EMAIL PROTECTED]> wrote: [ here's some context: > > I've been playing with a function that creates an anonymous function by > > compiling a string parameter, and it seems to work pretty well: > > > > def fn( text): > > exec 'def foo' + text.strip() > > return foo > > > > This can be used like: > > > > def foo( x): > > print x( 2, 5) > > > > foo( fn( ''' > > ( x, y): > > print 'x^2 + y^2 = ', x*x + y*y > > return y > > ''')) > > > > - which outputs: > > > > x^2 + y^2 = 29 > > 5 ] > How is this different from a nested function? It's different because it is defined in an expression, not by a statement. So you can create a new function inside a function call, for example. Like I said in the original post, it's a way of overcoming the limitations of python's lambda. The simple version I posted fails to lookup things in the caller's context, which one can easily fix by passing locals() as an extra parameter. Hopefully it'll be possible to grab the caller's locals() automatically using traceback or similar. Here's a version I've been using for a while which seems to work pretty well: def fn( text, globals_={}, locals_={}): ''' Returns an anonymous function created by calling exec on . should be a function definition, ommiting the initial `def ' (actually, leading `def' can be retained, for clarity). Any leading/trailing white space is removed using str.strip(). Leading white space on all lines will be handled automatically by exec, so you can use an indented python triple-quoted string. In addition, newlines and backslashes are re-escaped inside single/double-quoted strings. this enables nested use of fn(). example usage: fn( """ def ( target, state): if target != 'foo':return None return [], None, 'touch foo' """, globals(), locals()) Would be nice to grab our caller's globals() and locals() if globals_/locals_ are None, using some sort of introspection. For now, you'll have to pass globals() and locals() explicitly. ''' text = text.strip() if text.startswith( 'def'): text = text[ 3:].strip() if not text.startswith( '('): raise Exception( 'fn string must start with `(\'') def _escape_quotes( text): ''' escape newlines and backslashes that are inside single/double-quoted strings. should probably do something about backslashes inside triple-quoted strings, but we don't bother for now. ''' quote = None ret = '' for c in text: if quote: if c=='\n': ret += '\\n' elif c=='\\': ret += '' else: if c==quote: quote = None ret += c else: if c=='\'' or c=='"': quote = c ret += c return ret text = _escape_quotes( text) #print 'execing:', text # the exec will put the fn in the locals_ dict. we return it after # removing it from this dict. exec 'def _yabs_fn_temp' + text in globals_, locals_ ret = locals_['_yabs_fn_temp'] del locals_['_yabs_fn_temp'] return ret - Julian -- http://www.op59.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Doc Problem Example: os.path.split
> Please don't feed the trolls. > In other words, if everybody ignores this loser, he might crawl back under > the rock he came from. Well, comp.lang.python people would do better to accept the suggested rewrite and ignore at the rest at their discretion. -- http://mail.python.org/mailman/listinfo/python-list
Iterate through dictionary of file objects and file names
Hi all, I'm trying to get some ideas on the best way to do this. In this particular coding snippet, I was thinking of creating a dictionary of file objects and file names. These would be optional files that I could open and parse. At the end, I would easily close off the files by iterating through the dictionary. ---< CODE FOLLOWS >--- optionalfiles = {fileAreaCode: "areacode.11", fileBuild: "build.11"} # Try to see if optional file exists, if so, open. try: for key, optionalFile in optionalFiles.iteritems(): key = open(optionalFile, "r") except IOError: key = False ... # Close optionally open files for key, optionalFile in optionalFiles.iteritems(): if optionalFile: print "Closing: %s" % optionalFile key.close() ---< END CODE >--- My questions are: Is this even possible in a dictionary to have a key of a file object? If so, how do I initialise an empty file object? I mean, something along the lines of: fileAreaCode = open("", "r") If not, any suggestions on achieving openning optional files in a loop? Otherwise I'm stuck with: ---< BEGIN >--- # Optional input files try: fileAreaCode = open("areacode.11", "r") except: fileAreaCode = False try: fileBuild = open("build.11", "r") except: fileBuild = False ... # Close files for optionalFile in [fileAreaCode, fileBuild]: if optionalFile: print "Closing: %s" % str(optionalFile) optionalFile.close() ---< END >--- Thanks, Julian -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterate through dictionary of file objects and file names
Brian Beck wrote: File objects as keys sounds pretty dangerous. I'm curious why the first thought that popped into your head wasn't using the file NAMES as keys instead? Here's my go at it. (Is Google Groups nice to indentation using spaces? I can't remember.) optionalFiles = dict.fromkeys(['areacode.11', 'build.11'], None) # To open optionalFiles... for fileName in optionalFiles: try: optionalFiles[fileName] = open(fileName, "r") print "Opened: %s" % fileName except IOError: # Values are already initialized to None. print "File not found: %s" % fileName # To close optionalFiles... for fileName, fileObject in optionalFiles.iteritems(): if fileObject: fileObject.close() print "Closed: %s" % fileName # Rebinding fileObject here won't modify the dictionary, # so access it through the key. optionalFiles[fileName] = None Brain, Thanks for your help. I never thought of it like that. I guess in my original thinking, in the processing of the optional files I would start off each code block with something like: if fileAreaCode: ... But now I can just do: if optionalFiles['areacode.11']: ... I think I was just too much in the above mindset to think clearly about the dictionary. Using a file object as a key!? What was I thinking :P Julian -- http://mail.python.org/mailman/listinfo/python-list
Re: Anonymus functions revisited
On 23 Mar 2005 08:31:36 GMT Antoon Pardon <[EMAIL PROTECTED]> wrote: > Can someone who thinks this way, please explain why this is acceptable > > [ x * x for x in some_iterator ] > > But this is not > > map(lambda x: x * x, some_iteraror) > > and should be replaced with > > def sqr(x): return x * x > map(sqr , some_iterator) I guess I have similar feelings. I've only been using python for a year or two, so I'm still a relative newcomer. Like a lot of people, I found Python to be magically simple and intuitive. But I've never really found list comprehensions particularly clear. I don't know whether it's my backgroud (mainly C/C++), or my brain or what, but they are probably the only thing in Python that hasn't seemed transparent and obvious to me (apart from shadowing of variables in nested functions). Of course, I'm sure I could get used to them, given time. But that rather defeats one of the main reasons for using python in the first place - the lack of a steep learning curve. In contrast, I find lambdas, even with their significant restrictions, to be much more obvious. In fact, the proposal (sorry, don't have a link to hand) about extending lambda to allow things like `myfn = def ' was something that I initially assumed would become part of the language in time. Is there some definitive information that explains why python is moving away from lambdas and towards things like list comprehensions? - Julian -- http://www.op59.net/ -- http://mail.python.org/mailman/listinfo/python-list
How to inspect slot wrappers arguments in Python?
Hi, I would like to get the list of parameters I need to initialize an AST node. I'm trying to use the `inspect` module, however it seems I can't use it on a built-in (native?) class, or else I misunderstood. I'm using Python 2.7 and tried with Python 3.2. This is working: >>> import inspect >>> class C: ... def __init__(a,b=4): ... self.sum = a + b ... >>> inspect.getargspec(C.__init__) ArgSpec(args=['a', 'b'], varargs=None, keywords=None, defaults=(4,)) This is not working: >>> import inspect >>> import ast >>> inspect.getargspec(ast.If.__init__) Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 813, in getargspec raise TypeError('{!r} is not a Python function'.format(func)) TypeError: is not a Python function I am wondering if there is another way to get these parameters automatically? (ie. without compiling myself a dict) Regards, J. Bilcke -- http://mail.python.org/mailman/listinfo/python-list
Live Coding in pygame
Here is a more visual example of the technique presented in Logan Koester's article, "Live Coding in Python" (http://www.logankoester.com/mt/2006/07/live_coding_with_python_1.html). It's very quick-and-dirty in style, partly because half of the program was written in a moment of inspiration, and the other half was written and rewritten in real-time... :-D I've only tested this on Linux, using python 2.4.3. Reports of working or non-working on other platforms are very welcome. You will of course need pygame installed. :-) Paste the following snippets into live.py and livetest.py respectively. Run python live.py. Edit livetest.py while the program is running, and save livetest.py to see your results unfold. Other fun misuses include: (1) running multiple instances at once (slow!) and watching your changes affect them all; (2) nested live coding [live.py reloads live-prime.py, which in turn reloads livetest.py on each iteration]; and (3) having livetest.run() return data, and making live.py cache non-null data received... and pass it back as an argument to livetest.run(). You could then have reachable, usable data (say, a bitmap picture) floating around in your program's running instance, yet no longer mentioned in the program's source code. Ephemeral programming! Enjoy. :-) Julian live.py import pygame from pygame.locals import * from pygame import display try: import livetest except ImportError: livetest = None pygame.init() screen = display.set_mode((800, 600)) step = 0 while 1: try: reload(livetest) except: print "Failed to reload livetest.py" livetest.run(screen, step) step += 1 if step > 2400:# just a nice, round number ;-) step = 0 livetest.py import pygame from pygame.locals import * from pygame import display def run(screen, step): background = 0x00, 0x00, 0x00 textcolor = 0x00, 0xcc, 0xff text = "Live coding rocks!" myfont = pygame.font.SysFont("Arial" , 50) textimg = myfont.render(text, 1, textcolor) x = step % 800 y = step % 600 screen.fill(background) screen.blit(textimg, (x, y)) display.flip() # -- http://mail.python.org/mailman/listinfo/python-list
Re: Attaching a live interpreter to a script?
On Mon, 12 Jan 2009 23:35:14 -0800 (PST) Kannon wrote: > What I'd like to do is attach an interpreter to a program running from > a script (I.E, not something I typed into the live interpreter). It'd > be an awesome way to debug programs, as well as tweak parameters and > such at runtime. Ideally, I'd like it to be something in pure python > so I could throw it into Jython and IronPython as well. (Though, I can > actually code Java and C#, so implementing it is something I could do > myself, if needed.) I was thinking maybe something I could throw into > a tkinter window or similar, but I wasn't able to find anything on how > to pass stuff directly to the interpreter. > > Any ideas, or if this is even possible would be nice. Thanks in > advance. I have a few lines of code that runs a debug-server in its own thread, listening on a socket, and exec-ing text that is sent to the socket. The exec happens in the debug-server thread. It's very useful - you can get a backtrace for all threads (on python-2.5 and later), look at globals, call functions, etc etc, all while the main programme is running. If anyone's interested, i'll put the code somewhere. It's all very simple; some would say crude, too. - Jules -- http://op59.net/ http://undo-software.com/ -- http://mail.python.org/mailman/listinfo/python-list
Using the `email' module in a bazaar plugin
I don't seem to be able to use the `email' module from within a bazaar plugin. Other modules work ok, e.g. nntplib. Here's my plugin, cut-down to show just the email problem: import sys print 'sys.version', sys.version import nntplib n = nntplib.NNTP( 'jsmith-ubuntu2' ) print n import email m=email.MIMEText.MIMEText('text of email') - and here's the output when i run any bazaar command: > bzr status sys.version 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] 'module' object has no attribute 'MIMEText' Unable to load plugin 'js_notify' from '/home/jsmith/.bazaar/plugins' ... The plugin runs fine on its own, it's only when loaded into Bazaar that things go wrong. I thought perhaps this could be caused by the `email' module's use of LazyImporter. I've tried various things such as `from email.mime.text import MIMEText', and they fail in similar ways. I'm using bzr-1.9, python 2.5.2, on Ubuntu-8.xx. Does anyone have any ideas ? Thanks, - Julian -- http://op59.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Using the `email' module in a bazaar plugin
On Wed, 10 Dec 2008 12:13:28 + Matt Nordhoff <[EMAIL PROTECTED]> wrote: > Julian Smith wrote: > > I don't seem to be able to use the `email' module from within a bazaar > > plugin. Other modules work ok, e.g. nntplib. > > > > Here's my plugin, cut-down to show just the email problem: > > > > import sys > > print 'sys.version', sys.version > > > > import nntplib > > n = nntplib.NNTP( 'jsmith-ubuntu2' ) > > print n > > > > import email > > m=email.MIMEText.MIMEText('text of email') > > > > - and here's the output when i run any bazaar command: > > > > > bzr status > > sys.version 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] > > > > 'module' object has no attribute 'MIMEText' > > Unable to load plugin 'js_notify' from '/home/jsmith/.bazaar/plugins' > > ... > > > > The plugin runs fine on its own, it's only when loaded into Bazaar that > > things > > go wrong. > > > > I thought perhaps this could be caused by the `email' module's use of > > LazyImporter. I've tried various things such as `from email.mime.text import > > MIMEText', and they fail in similar ways. > > > > I'm using bzr-1.9, python 2.5.2, on Ubuntu-8.xx. > > > > Does anyone have any ideas ? > > > > Thanks, > > > > - Julian > > The built-in email module is probably getting shadowed by another one > (perhaps bzrlib.plugins.email?), so "import email" is importing the > wrong module. You'll have to rename it to something else. > > Have your plugin print email.__path__ to see which module it is. Ah, you're quite right. Curiously, email.__path__ is: /usr/lib/python2.5/site-packages/bzrlib/plugins/email - but sys.path is: ['/usr/bin', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/gst-0.10', '/var/lib/python-support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/var/lib/python-support/python2.5/gtk-2.0'] - i.e. no occurrence of `/usr/lib/python2.5/site-packages/bzrlib/plugins'. So i guess bazaar is redefining __import__() to look in the the plugins directory first, or something. Anyway, I can get things to work with the following: import imp email = imp.load_module( 'email', *imp.find_module( 'email', sys.path)) Many thanks, - Julian -- http://op59.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Fascinating interview by Richard Stallman on Russia TV
On 2010-07-18, Emmy Noether wrote: > DEFUN ("or", For, Sor, 0, UNEVALLED, 0, > "Eval args until one of them yields non-NIL, then return that value. > \n\ > The remaining args are not evalled at all.\n\ > If all args return NIL, return NIL.") > (args) > Lisp_Object args; > { > register Lisp_Object val; > Lisp_Object args_left; > struct gcpro gcpro1; > > if (NULL(args)) > return Qnil; > > args_left = args; > GCPRO1 (args_left); > > do > { > val = Feval (Fcar (args_left)); > if (!NULL (val)) > break; > args_left = Fcdr (args_left); > } > while (!NULL(args_left)); > > UNGCPRO; > return val; > } > > I saw that on comp.lang.c and found no one capable of explaining it. What do you need explained? Other than what's already in the manual (Gnu Emacs Internals section of the Elisp manual.) > And where does the manual explain the C struct or ADT of the basic > cons cell ? which file has the definition ? where is his eval_quote > function definition ? Try lisp.h RMS doesn't really believe in ADTs - that's one of the main complaints from XEmacs. As for finding functions, I believe Emacs has commands to help with that, but personally I just go grep eval_quote *.c -- http://mail.python.org/mailman/listinfo/python-list
convert user input to Decimal objects using eval()?
Hi ! This is maybe a silly question, but... is there a "easy way" to make eval() convert all floating numbers to Decimal objects and return a Decimal? for example: eval('1.0001+0.111') --> convert each number to a Decimal object, perform the sum and obtain a Decimal object as a result? maybe a parser is needed, but eval() already do the job, but I need the precision that Decimal offers for numerical applications. Thanks in advance. -- Julián -- http://mail.python.org/mailman/listinfo/python-list
Re: convert user input to Decimal objects using eval()?
On Tuesday 29 March 2005 03:04, Raymond Hettinger wrote: > from decimal import Decimal > import re > > number = re.compile(r"((\b|(?=\W))(\d+(\.\d*)?|\.\d+)([eE][+-]?\d{1,3})?)") > deciexpr = lambda s: number.sub(r"Decimal('\1')", s) > > for s in ('1.0001+0.111', > '+21.3e-5*85-.1234/81.6', > '1.0/7'): > print '%s\n --> %r' % (s, eval(s)) > s = deciexpr(s) > print '%s\n --> %r\n' % (s, eval(s)) Wow! Thank you so much!!! now I can do my simple math function evaluator much more reliable ! Thanks again! -- Julián -- http://mail.python.org/mailman/listinfo/python-list