output from popen
Hi, I am trying following script...
Re: output from popen
On Mon, Apr 5, 2010 at 1:33 PM, hiral wrote: > Hi, > I am trying following script... > >
Re: In disGuiodoise?
On 04/05/10 00:05, r wrote: However i have also considered that maybe *all* the "well knowns" are in fact the many colorful personalities of Guido. De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds nederlands machtig zijn. -- mph -- http://mail.python.org/mailman/listinfo/python-list
Translation docstrings with gettext
Hello. I found several discussions where this question was asked, but was not answered. Now I am creating Python-API for my application, and want create it with translation support, including documentation strings for modules, classes, methods etc. It is simple to translate special-marked strings with gettext, but it is problem with docstrings: if I mark them for translation like _("""Some documentation string""") then it is not recognized as docstring. If I omit _() markup, then string is not translated. Script pygettext.py has key --docstrings that forces extraction docstrings from module, so I suppose, that it must be way to use thier translations. --- I create small example, that demonstrates this problem: Module with docstrings for translation: {{{ #!python """testmodule docstring""" class TestClass: """testmodule.TestClass docstring""" def testClassMethod(self): """testmodule.TestClass.testClassMethod docstring""" print _("Call TestClass.testClassMethod()") }}} Script for testing translation: {{{ #!python import os, gettext localedir = os.path.join( os.path.dirname(__file__), "locale/" ) t = gettext.translation( 'testmodule', localedir=localedir, languages=['ru'], codeset="cp1251" ) t.install() import testmodule help( testmodule ) testmodule.TestClass().testClassMethod() }}} It successfully translates _("Call TestClass.testClassMethod()") but all docstrings stay untranslated. Full example exists here: https://docs.google.com/leaf?id=0B_rE4w6PFDYWODg5ZWJlYjMtYTQ5ZS00MTE3LTgxOWUtNjc5NzEzNzVjYzdh&hl=en So, question is: How to translate docstrings in my example? -- http://mail.python.org/mailman/listinfo/python-list
pythonrag
I saw this posted in the July issue but did not see any follow-up there: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 500 >>> b = 500 >>> a == b True >>> a is b False >>> p = 50 >>> q = 50 >>> p == q True >>> p is q True >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonrag
Python caches objects for reuse, but I'm not too certain on how it works, either. Seems a bit odd. I just tested on 2.6.5 and got the same result. This hasn't been a problem for me, though. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list
Re: In disGuiodoise?
Martin P. Hellwig wrote: > On 04/05/10 00:05, r wrote: > >> However i have also considered that maybe *all* the "well knowns" are >> in fact the many colorful personalities of Guido. >> > > > De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds > nederlands machtig zijn. > Good sock puppets would at least pretend to understand no Dutch even if they would. N -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonrag
Jason Friedman ha scritto: I saw this posted in the July issue but did not see any follow-up there: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. a = 500 b = 500 a == b True a is b False p = 50 q = 50 p == q True p is q True LOL -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonrag
On Mon, 2010-04-05 at 11:38 +, Jason Friedman wrote: > I saw this posted in the July issue but did not see any follow-up there: > > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> a = 500 > >>> b = 500 > >>> a == b > True > >>> a is b > False > >>> p = 50 > >>> q = 50 > >>> p == q > True > >>> p is q > True > >>> This topic shows here every 3 weeks or so... The short of it: CPython optimizes small integers. It's a feature. Don't rely on it (Google for the rest). -a -- http://mail.python.org/mailman/listinfo/python-list
Re: In disGuiodoise?
On Mon, 05 Apr 2010 13:48:15 +0200 News123 wrote: > Martin P. Hellwig wrote: > > On 04/05/10 00:05, r wrote: > > > >> However i have also considered that maybe *all* the "well knowns" > >> are in fact the many colorful personalities of Guido. > >> > > > > > > De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds > > nederlands machtig zijn. > > > > Good sock puppets would at least pretend to understand no Dutch even > if they would. > Is that in reference to the contents of Martins comment, in whatever language that was? Because I, for one, don't understand a word of it. /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonrag
On 5-4-2010 13:48, superpollo wrote: Jason Friedman ha scritto: I saw this posted in the July issue but did not see any follow-up there: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. a = 500 b = 500 a == b True a is b False p = 50 q = 50 p == q True p is q True LOL I fail to see the fun? Remember that everything in Python is an object, even integers. For integers, I believe Python creates the first 100 integer objects and reuses them. Larger integers are created when needed, and are different objects. The example also shows why it usually is wrong to use object comparison ('is') when you really mean equality (==). -irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Translation docstrings with gettext
On 04/05/10 20:31, sapient wrote: > Hello. > > I found several discussions where this question was asked, but was not > answered. Why would you want to translate docstring? Docstring is meant for developers not users. Maintaining a translated docstring is going to be a maintenance hell and will either hampers your application's agility or you will be left with obsolete docstrings in various languages you don't know. Anyway, my job is to answer questions, not question the economic feasibility of your decision, so try this: #!python __doc__ = _("""testmodule docstring""") class TestClass: __doc__ = _("""testmodule.TestClass docstring""") def testClassMethod(self): __doc__ = _("""testmodule.TestClass.testClassMethod docstring""") print _("Call TestClass.testClassMethod()") If you want to avoid having the explicit assignment to __doc__, you can also try using some metaclass or decorator magic to automatically wraps docstring in a _() call. -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonrag
Jason Friedman wrote: I saw this posted in the July issue but did not see any follow-up there: $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. a = 500 b = 500 a == b True a is b False p = 50 q = 50 p == q True p is q True In a=500 b=500 Python could either: * create two integers containing 500, one for each variable * create one integer referred to by both variables The first option will evaluate "a is b" as False, while the second will evaluate "a is b" as True. In other words, the "is" operator asks something about storage location. *WHY* would you care how the integers are stored? It is considered a *bug* on your part to write a program that depends on the particular storage option Python chooses for any particular integer. The second option is more efficient in memory usage, but requires some run-time to implement, while the first option does not require the run-time tracking of already-used integers, but may result in more memory usage. Python, the language, does not specify which storage option will be used. Python, the C implementation, does both, choosing the second option for small integers (those less 100 last time I checked). Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- http://mail.python.org/mailman/listinfo/python-list
Interfaces
Dear all, PEP 245 and 246 about interfaces for python are both rejected for 'something much better' (GvR in 246's rejection notice). Does anybody know what this is? I am *very* curious! Kind regards, Roald -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Local MAC Address
All, Thanks for all of the great solutions! Sorry I wasn't more specific in my post and will keep that in mind for future posts. Just FYI I was using a Windows machine and running Python 2.6. Once again thanks for all of your help! Gerad -- http://mail.python.org/mailman/listinfo/python-list
Re: unset TCL_LIBRARY and TK_LIBRARY
Wolfman wrote: Hello- was hoping someone could give me a hand in permanently setting my TCL_LIBRARY and TK_LIBRARY. I downloaded Python2.6 to a ThinkPad that came installed with Python2.2, and I can not run IDLE as something automatically sets TCL_LIBRARY and TK_LIBRARY to C:\IBMTools\Python22\ each time i open a new command line window or reboot the machine. i have set them to the appropriate Python26 sub-directory via command line and IDLE opens just fine and dandy, but as soon as I close the command window or reboot computer it sets them back to the aforementioned C:\IBMTools\Python22 subdirectory how can i permanently SET TCL_LIBRARY and TK_LIBRARY? thanks It can be dangerous to change the system-wide default Python that presumably was used for administration on your Thinkpad. I have a later Thinkpad (with XP), and it did not come with any Python. But if you want to change environment variables persistently on Windows, you can go to the Control Panel. The specifics below are with XP, but it'll be similar for other versions between Win2k and later. ControlPanel->System Advanced tab Click button labeled Environment Variables The upper section contains variables specific to your own logon, while the lower panel has variables that will be set for all users. I believe in most cases, a variable defined in both places will get the "user" value. But for PATH, the two are combined into a single, longer string. And perhaps that's true for some others as well. If you have trouble finding that page ("Environment Variables"), see if you can find the System Properties panel. It has an Advanced tab, and you can continue as above. Once you've set these, any new copy of CMD.exe will get the new values, and they are remembered across boot. However, typing start from an existing DOS box just gets a copy with the same variables you've defined locally. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'"
Thanks for the replies. The param style is pyformat. I've tried using the '%s' style with a set and get exactly the same error. c.execute('SELECT * FROM %s LIMIT 1',('mytable',)) psycopg2.ProgrammingError: syntax error at or near "E'mytable'" LINE 1: SELECT * FROM E'mytable' LIMIT 1 MRAB and Steve Holden may be correct, but are at odds with the psycopg2 documentation (http://initd.org/psycopg/docs/ usage.html#passing-parameters-to-sql-queries) which shows named arguments being used with a dictionary. It appears that the real problem is, as Steve mentioned, that the device driver may not allow table name substitution. The following query seems to work... c.execute('SELECT * FROM mytable WHERE id = %(id)s',{'id':'10'}) (Oddly enough, this one doesn't) c.execute('SELECT * FROM mytable WHERE id = %(id)d',{'id':int(10)}) TypeError: int argument required -- http://mail.python.org/mailman/listinfo/python-list
Re: passing command line arguments to executable
On Apr 4, 6:32 am, Simon Brunning wrote: > On 3 April 2010 18:20, mcanjo wrote: > > > I tried doing the following code: > > > from subprocess import Popen > > from subprocess import PIPE, STDOUT > > exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr = > > STDOUT) > > exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0] > > > and the Command Prompt opened and closed, no exceptions were generated > > but the program didn't run. Am I doing something wrong? > > Have you tried running pmm.exe from the command line? What does that > look like? Does it matter what the current working directory is at the > time? > > -- > Cheers, > Simon B. When I run the program from the command line it looks as follows: Enter the Input filename (enter in filename here) Enter the Output filename (enter in filename here) If an absolute path is not specified then the output file is located in the current working directory of the executable. The absolute path for the output and input files may be specified also. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Interfaces
On Apr 5, 4:40 pm, Roald de Vries wrote: > Dear all, > > PEP 245 and 246 about interfaces for python are both rejected for > 'something much better' (GvR in 246's rejection notice). Does anybody > know what this is? I am *very* curious! > > Kind regards, Roald Given that was in 2001, probably Python 2.2. -- http://mail.python.org/mailman/listinfo/python-list
Re: passing command line arguments to executable
On Apr 5, 11:22 am, mcanjo wrote: > On Apr 4, 6:32 am, Simon Brunning wrote: > > > > > On 3 April 2010 18:20, mcanjo wrote: > > > > I tried doing the following code: > > > > from subprocess import Popen > > > from subprocess import PIPE, STDOUT > > > exefile = Popen('pmm.exe', stdout = PIPE, stdin = PIPE, stderr = > > > STDOUT) > > > exefile.communicate('MarchScreen.pmm\nMarchScreen.out')[0] > > > > and the Command Prompt opened and closed, no exceptions were generated > > > but the program didn't run. Am I doing something wrong? > > > Have you tried running pmm.exe from the command line? What does that > > look like? Does it matter what the current working directory is at the > > time? > > > -- > > Cheers, > > Simon B. > > When I run the program from the command line it looks as follows: > > Enter the Input filename > (enter in filename here) > Enter the Output filename > (enter in filename here) > > If an absolute path is not specified then the output file is located > in the current working directory of the executable. The absolute path > for the output and input files may be specified also. > > Chris One thing you should do if you use pipes is to make sure you are accepting data from the program. If the program stalls because it cannot write anything to its stdout, you might have an issue. Pat -- http://mail.python.org/mailman/listinfo/python-list
Tkinter inheritance mess?
For a school project, I'm trying to make a minimalist web browser, and I chose to use Tk as the rendering toolkit. I made my parser classes into Tkinter canvases, so that I would only have to call pack and mainloop functions in order to display the rendering. Right now, two bugs are affecting the program : 1) When running the full app¹, which fetches a document and then attempts to display it, I get a TclError : _tkinter.TclError: bad window path name "{Extensible Markup Language (XML) 1.0 (Fifth Edition)}" 2) When running only the parsing and rendering test², I get a big window to open, with nothing displayed. I am not quite familiar with Tk, so I have no idea of why it acts that way. 1: webbrowser.py 2: xmlparser.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter inheritance mess?
On 5 avr, 12:36, ejetzer wrote: > For a school project, I'm trying to make a minimalist web browser, and > I chose to use Tk as the rendering toolkit. I made my parser classes > into Tkinter canvases, so that I would only have to call pack and > mainloop functions in order to display the rendering. Right now, two > bugs are affecting the program : > 1) When running the full app¹, which fetches a document and then > attempts to display it, I get a TclError : > _tkinter.TclError: bad window path name "{Extensible > Markup Language (XML) 1.0 (Fifth Edition)}" > 2) When running only the parsing and rendering test², I get a big > window to open, with nothing displayed. I am not quite familiar with > Tk, so I have no idea of why it acts that way. > > 1: webbrowser.py > 2: xmlparser.py I just realized I haven't included the Google Code project url : http://code.google.com/p/smally-browser/source/browse/#svn/trunk -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable referenced before assignment
Alf P. Steinbach wrote: Best is however to recognize that you have some state (your variable) and some operations on that state (your callback), and that that is what objects are all about. I.e. wrap your logic in a class. Then 'lastModifiedTime' becomes an instance attribute, and 'handler' becomes a method. It doesn't matter that there will only ever be one object (instance) of that class. Classes were meant for just this sort of thing, state + operations. Yes. Functions with persistent state are generally a bad idea. Unfortunately, the "signal" module requires a callback parameter which is a plain function. So you have to send it a function, closure, or lambda. Here, it's being sent a closure - "handler" bound to the state that existed when "signal.signal" was called. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
case insensitive list ?
hello, AFAIK there's no case insensitive list in Python. By case insentive I mean that that sort and memebr of is case insensitive. Does soeone has a implementation of sucha case insensitive list ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable referenced before assignment
On 2010-04-05 12:08 PM, John Nagle wrote: Alf P. Steinbach wrote: Best is however to recognize that you have some state (your variable) and some operations on that state (your callback), and that that is what objects are all about. I.e. wrap your logic in a class. Then 'lastModifiedTime' becomes an instance attribute, and 'handler' becomes a method. It doesn't matter that there will only ever be one object (instance) of that class. Classes were meant for just this sort of thing, state + operations. Yes. Functions with persistent state are generally a bad idea. Unfortunately, the "signal" module requires a callback parameter which is a plain function. So you have to send it a function, closure, or lambda. Does it? The docs say that it just needs a callable object. An instance with a __call__() method would suffice. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: case insensitive list ?
On 2010-04-05 12:17 PM, Stef Mientki wrote: hello, AFAIK there's no case insensitive list in Python. By case insentive I mean that that sort and memebr of is case insensitive. Does soeone has a implementation of sucha case insensitive list ? mylist.sort(key=lambda x: x.lower()) any(x.lower() == lowercase_query for x in mylist) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: folks, what's wrong with this?
> And now for the most import point: __getattr__ is only called as a > *last* resort. That is, after the attribute lookup mechanism will have > tried *and failed* to find the name in the instance's __dict__. Thanks you all for all the suggestions and thoughts. So in other words, this piece of code: try: return self.__dict__.__getitem__(item) except KeyError: raise AttributeError(item) in __getattr__ is redundant. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to access args as a list?
In <4bb802f7$0$8827$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sat, 03 Apr 2010 22:58:43 +, kj wrote: >> Suppose I have a function with the following signature: >> >> def spam(x, y, z): >> # etc. >> >> Is there a way to refer, within the function, to all its arguments as a >> single list? (I.e. I'm looking for Python's equivalent of Perl's @_ >> variable.) >Does this help? def spam(a, b, c=3, d=4): >... pass >... spam.__code__.co_varnames >('a', 'b', 'c', 'd') That's very handy. Thanks! >The hardest part is having the function know its own name. Indeed. Why Python does not provide this elmentary form of introspection as a built-in variable is extremely puzzling to me (even--no, *more so*--after reading PEP 3130). >I see that you are already using the inspect module. That almost >certainly is the correct approach. I'd be surprised if inspect is too >heavyweight, but if it is, you can pull out the bits you need into your >own function. That's a good idea. Thanks! ~K -- http://mail.python.org/mailman/listinfo/python-list
Re: local variable referenced before assignment
On 2010-04-05 10:08:51 -0700, John Nagle said: Yes. Functions with persistent state are generally a bad idea. Unfortunately, the "signal" module requires a callback parameter which is a plain function. So you have to send it a function, closure, or lambda. Here, it's being sent a closure - "handler" bound to the state that existed when "signal.signal" was called. Uhh, what? class A: ... def handle(self, foo, bar): ... print "Okay" ... a = A() signal.signal(signal.SIGALRM, a.handle) 0 Okay Where after that call to signal.signal, I did kill -ALRM and such in another process. When Python says 'a function', it doesn't mean a -plain- function. A method's a function too. Arguably, really, any callable is almost always (as in I can't think of anywhere it doesn't) sufficient to be Functiony enough to work. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. -- http://mail.python.org/mailman/listinfo/python-list
string.Template question
Can you use dicts with string.Template? e.g. a structure like: game = { 'home': {'team': row['home_team_full'], 'score': row['home_score'], 'record': '0-0', 'pitcher': { 'id': home_pitcher.attrib['id'], 'name': home_pitcher.attrib['last_name'], 'wins': home_pitcher.attrib['wins'], 'losses': home_pitcher.attrib['losses'] }, 'win': home_win} } Then, in the template, 'game' is passed, but I want to access like $home.pitcher.id This doesn't seem to work, though. Is it possible? Or must everything in the dict passed to string.Template be one-level deep string variables? -- http://mail.python.org/mailman/listinfo/python-list
Re: In disGuiodoise?
Andreas Waldenburger wrote: > On Mon, 05 Apr 2010 13:48:15 +0200 News123 wrote: > >> Martin P. Hellwig wrote: >>> On 04/05/10 00:05, r wrote: >>> However i have also considered that maybe *all* the "well knowns" are in fact the many colorful personalities of Guido. >>> >>> >>> De vraag is dan natuurlijk of al zijn persoonlijkheden nog steeds >>> nederlands machtig zijn. >>> >> Good sock puppets would at least pretend to understand no Dutch even >> if they would. >> > Is that in reference to the contents of Martins comment, in whatever > language that was? Because I, for one, don't understand a word of it. > Yes indeed: Freely (and as far as I understand) translated: "Question is of course whether all his personalities would still be knowledgable in dutch" -- http://mail.python.org/mailman/listinfo/python-list
Re: string.Template question
Wells Oliver wrote: > Can you use dicts with string.Template? > > e.g. a structure like: > > game = { > 'home': {'team': row['home_team_full'], 'score': row['home_score'], > 'record': '0-0', 'pitcher': { > 'id': home_pitcher.attrib['id'], 'name': > home_pitcher.attrib['last_name'], 'wins': home_pitcher.attrib['wins'], > 'losses': home_pitcher.attrib['losses'] > }, 'win': home_win} > } > > Then, in the template, 'game' is passed, but I want to access like > $home.pitcher.id > > This doesn't seem to work, though. Is it possible? Or must everything > in the dict passed to string.Template be one-level deep string > variables? If you're unclear about the capabilities of a piece of python it's time to have a look at the source code ;) My conclusion: you can make string.Template accept dotted variables and nested dicts, but not without subclassing and a few lines of custom code. $ cat extended_template.py import string class DotDict(object): def __init__(self, d): self._nested = d def __getitem__(self, key): result = self._nested for k in key.split("."): result = result[k] return result class Template(string.Template): idpattern = r'[_a-z][_a-z0-9.]*' def substitute(self, *args, **kw): assert not kw [d] = args return string.Template.substitute(self, DotDict(d)) if __name__ == "__main__": game = {"home": {"pitcher": {"id": 42}}} print Template("home/pitcher/id is $home.pitcher.id").substitute(game) $ python extended_template.py home/pitcher/id is 42 Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Interfaces
On Mon, Apr 5, 2010 at 8:40 AM, Roald de Vries wrote: > Dear all, > > PEP 245 and 246 about interfaces for python are both rejected for 'something > much better' (GvR in 246's rejection notice). Does anybody know what this > is? I am *very* curious! Abstract Base Classes (ABCs) fulfill a similar purpose: http://www.python.org/dev/peps/pep-3119/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
PIL question
I'm trying to cut a BMP with 80 adjacent frames down to 40 using the Image.copy and .paste functions but I'm getting error "ValueError: images do not match" on the paste line. Here is the source --- import sys from PIL import Image if len(sys.argv) == 2: file = sys.argv[1] else: print "Usage: python rotate.py image.bmp" exit print "Loading image "+file image = Image.open(file) if image: print "Successful" else: print "Something didn't work out right." cols = [] size = image.size framew = int(raw_input("Frame width: ")) frameh = int(raw_input("Frame height: ")) ncols = size[0]/framew print str(ncols)+" Columns, "+str(size[1]/frameh)+" Rows\n" c = 1 while c <= ncols: cols += [image.crop((framew*c, 0, frameh*(c+1), frameh*(c+1)))] c += 1 print "New image size "+str(framew*ncols/2)+"x"+str(frameh) print "Resizing image, could take a minute..." newimage = image.resize(((framew*(ncols/2)), frameh), Image.NEAREST) print "Image resized. Starting rotation loop." f = 0 while f < (framew*(ncols/2)): if f%2 == 0: print "Pasting at "+str(f*framew)+"x0 to "+str(f*framew+framew) +"x192" newimage.paste(cols[f], (f*framew, 0, (f*framew)+192, 192)) f += 1 newimage.save('NEWIMAGE.BMP') -- http://mail.python.org/mailman/listinfo/python-list
Re: C-style static variables in Python?
> Another approach would be to stuff the static values in the function's > __dict__. That's how I did it when I wanted something similar. I created this decorator: def static(**kw): ''' Used to create a decorator function that will add an attribute to a function and initialize it. >>> @static(foo=5) ... def bar(): ... print bar.foo ... bar.foo += 1 ... >>> bar() 5 >>> bar() 6 ''' def decorator(f): f.__dict__.update(kw) return f return decorator _ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 -- http://mail.python.org/mailman/listinfo/python-list
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas j
"ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs
Re: C-style static variables in Python?
Ethan Furman wrote: Steven D'Aprano wrote: On Fri, 02 Apr 2010 19:48:59 -0700, Ethan Furman wrote: The heuristic I use is, if I expect the try block to raise an exception more than about one time in ten, I change to an explicit test. In this case, since the exception should only be raised once, and then never again, I would use a try...except block. That was my reasoning as well, but when I timed it for one million runs (so 1 instantiation, 999,999 simple calls), the __getattr__ time was .5 seconds, the try...execpt block was .6; at ten million it was 5 and 6. Care to share your timing code? Not that I don't trust your results, but timings are very sensitive to the exact thing you do, and I'd like to see what that is. Happy to do so -- if I made a mistake I'd like to know about it and learn. It'll have to wait two days 'til I get back to work, though... I'll post it asap. Well, so much for asap, but here's what I used (with one correction: in the 'if' code I had forgotten to actually reference the missing attribute, so the __getattr__ look up never happened; now the try...except block is /slightly/ faster, as opposed to 20% slower). class spam_except(object): def __call__(self, x, y, z): try: mongo = self.mongo except AttributeError: mongo = self.mongo = 1 return class spam_if(object): def __getattr__(self, name): if name != 'mongo': raise AttributeError self.mongo = 1 return self.mongo def __call__(self, x, y, z): self.mongo # didn't have this line before. d'oh! return --> timeit.Timer('spammer(1,2,3)','from spam import spam_except; spammer=spam_except()').timeit() 0.65764130543749388 --> timeit.Timer('spammer(1,2,3)','from spam import spam_if; spammer=spam_if()').timeit() 0.66972877235545525 ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: C-style static variables in Python?
On Apr 5, 6:50 pm, Ethan Furman wrote: (Posted some code with a timeit...) Well, I'm not going to debug this, but with the *original* thing you posted, and the thing I posted, with a call and everything (more realistic scenario), the exception version seems slower on my machine: #!/usr/bin/env python import timeit def frobnicate(a,b,c,d): pass def heavy_lifting_at_runtime(): print 'heavy' class spam_except(object): def __call__(self, x, y, z): try: mongo = self.mongo except AttributeError: mongo = self.mongo = heavy_lifting_at_runtime() return frobnicate(x, y, z, mongo) se = spam_except() class spam_if(object): def __getattr__(self, name): if name != 'mongo': raise AttributeError self.mongo = heavy_lifting_at_runtime() return self.mongo def __call__(self, x, y, z): return frobnicate(x, y, z, self.mongo) si = spam_if() tse = timeit.Timer('se(1,2,3)', "from __main__ import se") tsi = timeit.Timer('si(1,2,3)', "from __main__ import si") for i in range(5): ve = tse.timeit(1000) vi = tsi.timeit(1000) print ve, vi, '%.1f' % ((ve-vi) / vi * 100) -- heavy heavy 5.45695090294 5.10844397545 6.8 5.43381404877 5.01345705986 8.4 5.42474508286 5.02641201019 7.9 5.40713405609 5.04178905487 7.2 5.38063693047 4.96194696426 8.4 The output indicates that the exception one is, on average, around 7.5% slower. Regards, Pat -- http://mail.python.org/mailman/listinfo/python-list
How to output the commands that are executed in a python script?
I want to show what commands have been executed when I run a python script. Is there an option which can instruct python to print the commands automatically? (If you are familiar with R, what I am asking is essentially options(echo=T) in R.) -- Regards, Peng -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter inheritance mess?
On 04/06/10 02:38, ejetzer wrote: > On 5 avr, 12:36, ejetzer wrote: >> For a school project, I'm trying to make a minimalist web browser, and >> I chose to use Tk as the rendering toolkit. I made my parser classes >> into Tkinter canvases, so that I would only have to call pack and >> mainloop functions in order to display the rendering. Right now, two >> bugs are affecting the program : >> 1) When running the full app¹, which fetches a document and then >> attempts to display it, I get a TclError : >> _tkinter.TclError: bad window path name "{Extensible >> Markup Language (XML) 1.0 (Fifth Edition)}" >> 2) When running only the parsing and rendering test², I get a big >> window to open, with nothing displayed. I am not quite familiar with >> Tk, so I have no idea of why it acts that way. >> >> 1: webbrowser.py >> 2: xmlparser.py > > I just realized I haven't included the Google Code project url : > http://code.google.com/p/smally-browser/source/browse/#svn/trunk Check your indentation xmlparser.py in line 63 to 236, are they supposed to be correct? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to output the commands that are executed in a python script?
On 04/06/10 12:38, Peng Yu wrote: > I want to show what commands have been executed when I run a python > script. Is there an option which can instruct python to print the > commands automatically? > > (If you are familiar with R, what I am asking is essentially > options(echo=T) in R.) > It's not exactly the same, but pdb (Python Debugger) can do something similar. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to output the commands that are executed in a python script?
You need a debugger here. On Tue, Apr 6, 2010 at 8:41 AM, Lie Ryan wrote: > On 04/06/10 12:38, Peng Yu wrote: > > I want to show what commands have been executed when I run a python > > script. Is there an option which can instruct python to print the > > commands automatically? > > > > (If you are familiar with R, what I am asking is essentially > > options(echo=T) in R.) > > > > It's not exactly the same, but pdb (Python Debugger) can do something > similar. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
[Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "te
[Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas houston" "jobs in texas city" "jobs in texas government" "jobs in texas austin" "texas jobs" "texas jobs online" texas job search" http://jobsintexas-usa.blogspot.com/ [Click the star to watch this topic] "ADVERTISED JOBS IN TEXAS" "jobs in texas" "jobs in texas usa" "jobs in texas h
Re: How to access args as a list?
On Apr 5, 11:49 am, kj wrote: > In <4bb802f7$0$8827$c3e8...@news.astraweb.com> Steven D'Aprano > writes: > > >On Sat, 03 Apr 2010 22:58:43 +, kj wrote: > >> Suppose I have a function with the following signature: > > >> def spam(x, y, z): > >> # etc. > > >> Is there a way to refer, within the function, to all its arguments as a > >> single list? (I.e. I'm looking for Python's equivalent of Perl's @_ > >> variable.) > >Does this help? > def spam(a, b, c=3, d=4): > >... pass > >... > spam.__code__.co_varnames > >('a', 'b', 'c', 'd') > > That's very handy. Thanks! > > >The hardest part is having the function know its own name. > > Indeed. Why Python does not provide this elmentary form of > introspection as a built-in variable is extremely puzzling to me > (even--no, *more so*--after reading PEP 3130). > The Rejection Notice in the PEP certainly not give very many details for why the PEP was rejected. The first question in the Open Issues could easily be answered "yes." -- http://mail.python.org/mailman/listinfo/python-list
per-method jit compiler
On 4 abr, 00:09, Steven D'Aprano wrote: > On Sat, 03 Apr 2010 22:58:43 +, kj wrote: > > Suppose I have a function with the following signature: > > > def spam(x, y, z): > > # etc. > > > Is there a way to refer, within the function, to all its arguments as a > > single list? (I.e. I'm looking for Python's equivalent of Perl's @_ > > variable.) > > Does this help? > > >>> def spam(a, b, c=3, d=4): > > ... pass > ...>>> spam.__code__.co_varnames > > ('a', 'b', 'c', 'd') > > The hardest part is having the function know its own name. > > I see that you are already using the inspect module. That almost > certainly is the correct approach. I'd be surprised if inspect is too > heavyweight, but if it is, you can pull out the bits you need into your > own function. > > -- > Steven The above post gave me an idea (very naive, of couse). What if I write a simple decorator to figure out the types of every function, and then we use it as a base for a simple method-jit compiler for python? example: def typer(f): def wrap(*args): a = f.func_code.co_varnames b = [type(i) for i in args] return dict(zip(a,b)) return wrap @typer def spam(a, b, c=3, d=4): pass >>> spam(8,'hello',9.9, 10) {'a': , 'c': , 'b': , 'd': } So by using this information, we record all the argument types used the first time each function/method is executed, and then we generate optimized code for them. >From this point on, a guard should check if all arguments remain the same and, if so, the optimized code is run. Otherwise, just fall back to the interpreter. He! I have no idea how to implement it... Any guru out there? Luis -- http://mail.python.org/mailman/listinfo/python-list
per-method jit compiler
On 4 abr, 00:09, Steven D'Aprano wrote: > On Sat, 03 Apr 2010 22:58:43 +, kj wrote: > > Suppose I have a function with the following signature: > > def spam(x, y, z): > > # etc. > > Is there a way to refer, within the function, to all its arguments as a > > single list? (I.e. I'm looking for Python's equivalent of Perl's @_ > > variable.) > Does this help? > >>> def spam(a, b, c=3, d=4): > ... pass > ...>>> spam.__code__.co_varnames > ('a', 'b', 'c', 'd') > The hardest part is having the function know its own name. > I see that you are already using the inspect module. That almost > certainly is the correct approach. I'd be surprised if inspect is too > heavyweight, but if it is, you can pull out the bits you need into your > own function. > -- > Steven The above post gave me an idea (very naive, of couse). What if I write a simple decorator to figure out the types of every function, and then we use it as a base for a simple method-jit compiler for python? example: def typer(f): def wrap(*args): a = f.func_code.co_varnames b = [type(i) for i in args] return dict(zip(a,b)) return wrap @typer def spam(a, b, c=3, d=4): pass >>> spam(8,'hello',9.9, 10) {'a': , 'c': , 'b': , 'd': } So by using this information, we record all the argument types used the first time each function/method is executed, and then we generate optimized code for them. >From this point on, a guard should check if all arguments remain the same and, if so, the optimized code is run. Otherwise, just fall back to the interpreter. He! I have no idea how to implement it... Any guru out there? Luis -- http://mail.python.org/mailman/listinfo/python-list
per-function jit compiler
This post gave me an idea: http://groups.google.com/group/comp.lang.python/msg/5d75080707104b76 What if I write a simple decorator to figure out the types of every function, and then we use it as a base for a simple method-jit compiler for python? example: def typer(f): def wrap(*args): a = f.func_code.co_varnames b = [type(i) for i in args] return dict(zip(a,b)) return wrap @typer def spam(a, b, c=3, d=4): pass >>> spam(8,'hello',9.9, 10) {'a': , 'c': , 'b': , 'd':} So by using this information, we record all the argument types used the first time each function/method is executed, and then we generate optimized code for them. >From this point on, a guard should check if all arguments remain the same and, if so, the optimized code is run. Otherwise, just fall back to the interpreter. He! I have no idea how to implement it... Any guru out there? Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: per-function jit compiler
2010/4/5 Luis M. González : > This post gave me an idea: > http://groups.google.com/group/comp.lang.python/msg/5d75080707104b76 > > What if I write a simple decorator to figure out the types of every > function, and then we use it as a base for a simple method-jit > compiler for python? > > example: > > def typer(f): > def wrap(*args): > a = f.func_code.co_varnames > b = [type(i) for i in args] > return dict(zip(a,b)) > return wrap > > @typer > def spam(a, b, c=3, d=4): > pass > spam(8,'hello',9.9, 10) > {'a': , 'c': , 'b': , 'd': 'int'>} > > So by using this information, we record all the argument types used > the first time each function/method is executed, and then we generate > optimized code for them. > >From this point on, a guard should check if all arguments remain the > same and, if so, the optimized code is run. > Otherwise, just fall back to the interpreter. > > He! I have no idea how to implement it... Guido's been lending out his time machine again: http://psyco.sourceforge.net/introduction.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list