Re: A Python 3000 Question
On Fri, 02 Nov 2007 03:40:59 +, Tim Roberts wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 31 Oct 2007 22:48:12 -0700, Carl Banks wrote: I hope you're not serious that $# would make a good operator. If you happen to know where I borrowed it from, it would be pretty evident that I wasn't being serious. Ooh, now I'm curious. Seriously? You didn't know that $#x in perl returns the length of the array @x, minus 1? I don't speak Perl. You know there are million of us who have managed to avoid it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: AOP and pep 246
On Nov 1, 4:46 pm, Kay Schluehr [EMAIL PROTECTED] wrote: On 1 Nov., 16:18, Rustom Mody [EMAIL PROTECTED] wrote: I am interested in AOP in python. From here one naturally (or google-ly) reaches peak. But peak seems to be discontinued. Whereas pep-246 on adaptors seems to be rejected in favor of something else. What?? Can someone please throw some light on whats the current state of the art? AOP was a research that gone nowhere - at least not in its orginal AspectJ form: If you Verify integrated circuits then you might know of the Specman e language (http://en.wikipedia.org/wiki/Specman), That pre-dates AspectJ and is very much alive. Its AOP feature-set is different to that of AspectJ. Our Verification engineers find the AOP paradigm to be very productive. It allows them to write a testbench in e and use AOP to extend it to create different testcases. Just found a version of the LRM online (search for 'extend'): http://www.ieee1647.org/downloads/prelim_e_lrm.pdf - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
RE: posting to a form with no form name
On Behalf Of [EMAIL PROTECTED] posting to a form with no form name or it's just that i cant find the form name. can anyone explain how to either post to a form with no name or, find the name of the form..here my current output, but i dont see a form name, also, there is only 1 form on the page I believe you want Browser.select_form(nr=0) # Using mechanize # http://wwwsearch.sourceforge.net/mechanize/ from mechanize import Browser browser = Browser() browser.open(http://example.com;) browser.select_form(nr=0) browser['username'] = me browser['password'] = secret browser.submit() Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt with embedded python in Qt App
Friday 02 of November 2007 01:06:58 Diez B. Roggisch napisał(a): So how to pass this object into embeded python interpreter (executed script)? Anyone know any example? You don't pass it, you _retrieve_ it in the embedded interpreter by invoking the code given to you. Know any example, please? For better understand this :) I wan't add scripting to one application wrotten with Qt. Bart. -- http://mail.python.org/mailman/listinfo/python-list
Re: AOP and pep 246
On Nov 2, 12:10 am, Paul Rubin http://[EMAIL PROTECTED] wrote: Rustom Mody [EMAIL PROTECTED] writes: On 11/1/07, Kay Schluehr [EMAIL PROTECTED] wrote: AOP was a research that gone nowhere - at least not in its orginal AspectJ form: declaring aspect code that targets business code... My own guess is that AOP via higher order functions and metaclasses will be more successful than via aspectj and code-generation. I've never been able to figure out what AOP was supposed to mean. AOP is a programming paradigm in the same way indie is a genre of film. It essentially means, anything that is congnitively simple but not simply implemented in your language of choice. Hence the oft-heard purpose of AOP to address cross-cutting concerns. If you don't have a convenient representation in your language of some cognitively simple thing (aspect), then you have break up the implementation of it in unpleasant ways. Your concern must cross many files. Java, for instance, supports only one simple congitive concept--the object--and not as well as it could. Pretty much any concern that isn't nicely encapsulated in an object would be a cross-cutting concern and hence aspect that AOP would address. For example, suppose after careful consideration you were to decide to centralize XML serialization of many different object types in its own package. Java's strict object-orientated paradigm is your enemy here, especially without the benefit of multiple inheritance(**). AOP to the rescue. With AOP, you can say, No problem. I'll just use AspectJ to weave that XML serialization into the classes, and then I can keep the serialization in a central location where it belongs. Needless to say, Python there is broad support for many aspects of design, so that many cross-cutting concerns in Java would be ordinary programming in Python. Python culd handle the above problem without any code weaving, and some solutions would be natural enough that it wouldn't even occur to someone that they were using a different paradigm. That's why I prefer the term Aspect-Aware Programming, or Aspect-Aware Design. The idea is that different aspects aren't necessarily organized the same way. Many things fit neatly into an OO organization; other things do not. With AAP you organize some aspects in one way, other aspects in other ways, and it works out. A dynamic language like Python has good support for AAP already, but a rigid, static, precriptive language like Java needs to resort to hacks like AspectJ. Footnote: (**) One sometimes-effective way to tack behavior onto an existing set of classes is to derive a new set that multiply inherits from the existing set and a bunch of mixins with your own behavior. The approach has drawbacks, but sometimes it works ok, and would be quite useful in Java. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Readline and record separator
Dennis Lee Bieber a écrit : On Wed, 31 Oct 2007 11:13:21 +0100, Bruno Desthuilliers [EMAIL PROTECTED] declaimed the following in comp.lang.python: [1] Coma Separated Values - but the separator can be almost anything. Comma... oops... though at this time of night I feel like I should be in a coma G -- http://mail.python.org/mailman/listinfo/python-list
Re: posting to a form with no form name
On Nov 2, 12:04 am, Ryan Ginstrom [EMAIL PROTECTED] wrote: On Behalf Of [EMAIL PROTECTED] posting to a form with no form name or it's just that i cant find the form name. can anyone explain how to either post to a form with no name or, find the name of the form..here my current output, but i dont see a form name, also, there is only 1 form on the page I believe you want Browser.select_form(nr=0) # Using mechanize #http://wwwsearch.sourceforge.net/mechanize/ from mechanize import Browser browser = Browser() browser.open(http://example.com;) browser.select_form(nr=0) browser['username'] = me browser['password'] = secret browser.submit() Regards, Ryan Ginstrom also, thank you for your response -- http://mail.python.org/mailman/listinfo/python-list
Re: posting to a form with no form name
On Nov 2, 12:04 am, Ryan Ginstrom [EMAIL PROTECTED] wrote: On Behalf Of [EMAIL PROTECTED] posting to a form with no form name or it's just that i cant find the form name. can anyone explain how to either post to a form with no name or, find the name of the form..here my current output, but i dont see a form name, also, there is only 1 form on the page I believe you want Browser.select_form(nr=0) # Using mechanize #http://wwwsearch.sourceforge.net/mechanize/ from mechanize import Browser browser = Browser() browser.open(http://example.com;) browser.select_form(nr=0) browser['username'] = me browser['password'] = secret browser.submit() Regards, Ryan Ginstrom Yes, that is what i had there already, however, im tryin to get rid of the - for form in self._br.forms(): print form - I have a different for loop im tryin to implement outside of that one, and it's just not cycleing through.So is there any way to get rid of the for loop? this is the origanal code piece for line in open('passwds.txt'): for form in self._br.forms(): print form self._br.select_form(nr=0) self._br['username'] = Crawler.usrname self._br['password'] = line.strip() response=self._br.submit() if 'incorrect' in response.read(): print 'password incorrect =', line.strip() by the outside for loop isnt working, so i figured that maybe i could hard code the form name and i wouldnt need that inner loop..there a way to do that? -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
On Thu, 01 Nov 2007 19:39:20 -0500, Robert Kern [EMAIL PROTECTED] wrote: David C. Ullrich wrote: [why doesn't CoreGraphics work?] That's different than the one that is referenced. The one those articles reference is only available in the Python that came with the system in /System/Library/Frameworks/Python.framework, not one that you might have installed from www.python.org into /Library/Frameworks/Python.framework. The module was made by Apple, and they have not released the source code, so it cannot be made to work with the www.python.org distribution. usenet is amazing - your reply appears to have been posted a half hour before my question! Thanks. So CoreGraphics is a builtin in Apple-Python, explaining why I didn't find the relevant CoreGraphics.py anywhere on the hard drive, eh? Fine. Now what? Please feel free to bear in mind that I have very little experience with the Mac and with Unix - I'm certain that if I knew what I was doing there I wouldn't need to ask the questions below, sorry. And sorry about the length of this post - there's a second issue that maybe you could explain, that I'd really love to have an explanation for before modifying things. Anyway: Since I didn't do anything special to remove it when I installed the Python-Python, the Apple-Python should still be there, yes? I'd appreciate any advice on how to get things set up the way I'd like. Below when I refer to the MacPython stuff I mean ApplicationLauncher (or however it's spelled, the Mac's at the office and I'm at home) and Idle; the stuff that gives convenient access to Python scripts in the GUI. Note that I don't have any particular reason to want to use the latest version of Python - I was actually getting along fine with 1.5 until very recently. I'd be perfectly happy to set things up so everything used the Apple-Python. (i) If I just uninstalled the Python-Python (how?) would everything (Terminal, the MacPython stuff) automagically find the Apple-Python instead? (ii) If not, what would I have to do to make things use the Apple-Python instead? (And if I have to do something to make that happen, would doing that still work if I just left the Python-Python sitting there?) OR: Is there something special I could do with CoreGraphics scripts and/or how I invoke them so that _they_ would use the Apple-Python while other scripts would just use the Python-Python as now? (A last choice would be a setup where most scripts work as they do now and I somehow make CoreGraphics work from Terminal but not in Finder...) (Hmm, a wild guess: something somewhere is an alias to Python-Python, and I just change that (how?) to an alias to Apple-Python?) I'm a little nervous about making any changes, because something very mysterious happened when I was setting things up the way they are now - since I have no idea what I did to make things work the way they are now I don't know that I could set things up the way they are now again if I had to. If you can explain the following that will be something (I've been meaning to ask about the following sometime, hasn't been important til now when I'm contemplating changing the setup): The history: I get a Mac. I discover that it includes Python, can't figure out how to execute .py files in Finder. I hear about MacPython. I install the small MacPython download, that's supposed to just add ApplicationLauncher(?), Idle, etc on top of the existing Python. Works fine _except_ that when I double-click a .py file in Finder it executes with the cwd equal to the root directory instead of the directory where the script is located. Trying to fix that I install the full MacPython, including Python itself. Doesn't help, scripts still execute in /. A few weeks later I decide to try to fix that. The plan is to edit whatever.py, the script that's supposed to run before everything else allowing customizations (always takes me a while to find the magic name in the docs - probably you know the name I mean). The plan is to extract the directory I want from sys.argv and then chdir. And here's the mysterious part: The day I plan on modifying whatever.py I find the problem has fixed itself! When I double- click .py files they execute in the right directory. If you asked what I was smoking I wouldn't blame you. (Not that I really think that's it, but the _only_ thing I can imagine I did that could have led to the change was that perhaps I hadn't yet tried out Idle when things were executing in the wrong directory, and somehow the first time I ran Idle it fixed something for me.) Anyway. You have any idea what was going on there, and/or any idea about what to do to fix that problem if it appears again? Something somewhere changed - what, and how do I change it manually? defaults write what.what.what what what? Or what? I'd be much happier understanding what happened here before making any changes... Evidently you've read this far - thanks. Long posts are irritating. Of course so are posts that don't describe
Re: raw_input() and utf-8 formatted chars
On Thu, 01 Nov 2007 19:21:03 -0700, 7stud wrote: BeautifulSoup can convert an html entity representing an 'A' with umlaut, e.g.: Auml; into an without every touching my keyboard. How does BeautifulSoup do it? It maps the HTML entity names to unicode characters. Take a look at the `htmlentitydefs` module. from BeautifulSoup import BeautifulStoneSoup as bss s1 = h1Auml;/h1 #_Auml;_ #I added the comment after the line to show the #format of the html entity. In case a browser #might render the comment into the actual character, #I added underscores to the html entity: soup = bss(s1) text = soup.contents[0].string #gets the 'A' with umlaut out of the html new_s = bss(text, convertEntities=bss.HTML_ENTITIES) print repr(new_s) print new_s I see the same output for both print statements, and what I see is an 'A' with umlaut. I expected that the first print statement would show the utf-8 encoding for the character. Well it does, and apparently your terminal, or wherever the output goes, decodes that UTF-8 encoded 'Ä' and shows it. If you expected the output '\xc3\x84' then remember that you ask the soup object for its representation and not a string. The object itself decides what `repr(obj)` returns. Soup objects represent themselves as UTF-8 encoded strings. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some help...
Ricardo Aráoz wrote: Boris Borcic wrote: Ricardo Aráoz wrote: Boris Borcic wrote: [EMAIL PROTECTED] wrote: I want to create a program that I type in a word. for example... chaos each letter equals a number A=1 B=20 and so on. So Chaos would be C=13 H=4 A=1 O=7 S=5 I want to then have those numbers 13+4+1+7+5 added together to be 30. How can I do that? Also, just curious, but, how could I then have the 3 and 0 added together to be 3? Please help me out. Thank you. sum(dict(C=13,H=4,A=1,O=7,S=5)[_] for _ in 'CHAOS') 30 sum(eval(ch) for ch in str(_)) 3 def sumToOneDigit(num) : if num 10 : return num else : return sumToOneDigit(sum(int(i) for i in str(num))) sumToOneDigit(sum(ord(ch) for ch in 'chaos'.upper())) 6 HTH HTH what ? HTH : Hope that helps Citing your post : Not me, the OP [EMAIL PROTECTED]. Also, just curious, but, how could I then have the 3 and 0 added together to be 3? you have the function sumToOneDigit that adds the digits of a number till you get one digit (isn't that what you where curious about?) I had provided a solution that conformed to the OP's 2 questions. Your non-conform addition simply proved that you hadn't bothered to read. Or else you meant to read the OP's mind beyond what he specified; but then you should adress him, not me. And answering the main question : sum(ord(ch) for ch in 'chaos'.upper()) which is inside the sumToOneDigit funtion in my answer. No, you did not adress the original questions. My hth what ? was an invitation to rectify. Sorry it wasn't enough for you, but the verbosity was probably worth what you paid for it. Sorry if that is not enough for you, but the answer is probably worth what you paid for it. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: oops the code is like this but doesn't work class Test(object): def m1(self,v): return v def m2(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Well, what do you think: In [9]: gert = Test() In [10]: print gert.m1('1') : print Test.m2('2') : 1 --- type 'exceptions.TypeError' Traceback (most recent call last) /home/wildemar/ipython console in module() type 'exceptions.TypeError': unbound method m2() must be called with Test instance as first argument (got str instance instead) (Another hint: look at what m1 has that m2 lacks.) /W -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? I don't recall Python supporting non-existent method-calls (such as m1/m2 when they aren't actually defined) in ANY version of Python. But once you change that, you'll likely also want to investigate the classmethod decorator if you want to create class-methods. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? Look at the error you get. Repeat: LOOK AT THE ERROR YOU GET! (Hint: m1 not in (execute, escape)) Nothing to do with old- or new-style classes. /W -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
On Nov 2, 12:31 pm, gert [EMAIL PROTECTED] wrote: On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? oops the code is like this but doesn't work class Test(object): def m1(self,v): return v def m2(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
On 2 nov 2007, at 02.10, David C. Ullrich wrote: Running OS X 10.4 Tiger. Various references by Apple and others say that there exists a module that gives Quartz bindings, allowing all sort of graphics things in Python. Sure enough, after installing Xcode I have some sample scripts. They all start with from CoreGraphics import * (as do all the examples in two books, both of which say they're talking about Tiger.) I get an ImportError trying to import CoreGraphics. I found a CoreGraphics.py in a folder named Carbon; when I change the script to read import Carbon from Carbon.CoreGraphics import * there's no import error, but all of the Quartz things are NameErrors. I look at CoreGraphics.py, it's just about twenty lines long, defining a few constants with Quartz-sounding names. What gives? I'm supposed to do something else? Someone accidentally deleted all the code from my CoreGraphics.py? (Is there a working CoreGraphics.py around somewhere? I found a file somewhere on the net that was the same as mine except it ended with from CG import * Adding that doesn't change anything.) (Yes, the XCode installation seems to be working fine.) ??? David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list There are Python wrappers for the Cocoa API. These can be used with binaries from Python.org. The name of the module is PyObjC, and can be downloaded from sourceforge. There are binary builds for Python up to version 2.4.1. For Python 2.5.1, it is necessary to build it yourself, which I've found out requires modifying setup.py. (The problem is that setup.py tries to use two modules that's not installed by default on Tiger) -- What is a woman that you forsake her, and the hearth fire and the home acre, to go with the old grey Widow Maker. --Kipling, harp song of the Dane women Tommy Nordgren [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert == gert [EMAIL PROTECTED] writes: gert Why doesn't this new style class work in python 2.5.1 ? Whether you declare your class as a new style class or an old style class, your code is completely and utterly broken. Calling non-existing methods has never been a good way of getting things done. :-) Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt with embedded python in Qt App
Friday 02 of November 2007 12:21:06 BlueBird napisał(a): On Nov 2, 8:03 am, Bart. [EMAIL PROTECTED] wrote: Friday 02 of November 2007 01:06:58 Diez B. Roggisch napisa (a): So how to pass this object into embeded python interpreter (executed script)? Anyone know any example? You don't pass it, you _retrieve_ it in the embedded interpreter by invoking the code given to you. Know any example, please? For better understand this :) I wan't add scripting to one application wrotten with Qt. So, you have Qt/C++ application which you want to script through python. But why do you need PyQt for ? If you design a script api in python and bind it using whatever binding technology (manually, boost, sip, pyrex, ...), you should not need to use PyQt. Or do you mean to use PyQt as the binding technology ? Or I want to use PyQt in scripts to have similar gui for plugins written in python Or I want to extend application by scripts with PyQt. Or better question: How to easy add python scripting in Qt application and have almast all objects of app accesible in scripts? Kross could be good solution? I realy need some examples :( I'm looking for solutions. You are proffesional programmers so that is why write on this list :) Thanks for Your answars. Bart. -- http://mail.python.org/mailman/listinfo/python-list
sell all NIKE.shox.Air max.AF1.TN.Jordan.shoes.Apple Ipods Nano, Xbox 360, Sony PS3, Sony PSP.wii.all laptops http://www.new-nikeshoes.com
hi We are the biggest wholesale suppliers..We have a lot of very nice quality merchandises with the very special price We are wholesaler of Nike Jordan and Other Shoes in China. We are big Shoes Manufacturer in China. We supply many kinds of Shoes, such as Nike Shoes, Jordan 1-22, Air Jordan, AF1, DUNK, Air max series etc. Most of them are in stock and can be supplied surely on time. All these shoes are packed with original-boxes and cards. So we can offer series of brand Nike shoe with the lowest price and high quality, We are looking forward to doing business with you Very fast and safety delivery by TNT, UPS, DHL OR EMS, we can delivery within 24 hours upon receiving your payment. It is very safe door to door service, never get problems with customs. There are various and latest styles for your choice in our website. Our main markets are the USA, the UK, Germany, France, Italy, Greece, Jordan, Australia, Canada,Sweden, and many other countries in Europe and the Middle East regions. our brands , Ipod nano 1G 2G 4G 8G 30G 60G ,Ps3 ,psp ,wii,are also available for sale at cheaper rate. They are all brand new with full accessories and 1 year international warranty, unlocked, work effectively with any network worldwide and come with user manual guide in various languages. Ipod nano 1G 45$ ,2G 55$, 4G 65$,8G 70$, 30G 100$ ,60G 120$ ps3 60GB 300$ 20GB 180$ psp 150$ wii 200$ We have all models of nokia NOKIA N95 $250 NOKIA N93 $190 NOKIA N92 $160 NOKIA N91 $170 NOKIA N90 $180 Nokia N70 $165 NOKIA N73 $180 NOKIA 7600 (UNLOCK) $150 Nokia 8800 Sirocco Gold Edtion -$250 Nokia 8800 Sirocco Black$250 We wholesale all laptops Sony VGN-CR13/B 380$ Sony VGN-CR13/L350$ Sony VGN-CR15/B 320$ Sony VGN-CR13/P 480$ Sony VGN-C21CH 450$ Sony VGN-SZ44CN 580$ Sony VGN-C22CH/W 620$ Sony VGN-N17C 480$ Sony VGN-CR13/W 580$ Sony VGN-FZ15 560$ Apple MacBook 580$ Apple MacBook Pro(MA896CH/A)680$ Apple MacBook Pro(MA896CH/A) 630$ Apple MacBook (MB063CH/A) 580$ Apple MacBook Pro(MA895CH/A) 580$ Apple MacBook(MB062CH/A) 590$ Apple MacBook(MA700CH/A) 580$ Apple MacBook(MA701CH/A) 550$ Apple MacBook Pro (MA610CH/A) 650$ Apple MacBook Pro (MA611CH/A) 680$ Apple MacBook (MA699CH/A) 580$ (1).all products are all original and new (2).they have 1year international warranty. (3).free shipping include ems, tnt, dhl, ups. you may choose one kind (4).deliver time is in 7 days to get your door We insist the principia: Prestige first,high-quality,competitive price, best services,and timely delivery. Website: http://www.new-nikeshoes.com msn: [EMAIL PROTECTED] Hong-da Co., Ltd. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
BartlebyScrivener wrote: On Nov 2, 8:51 am, Jim Hendricks [EMAIL PROTECTED] wrote: New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: Did you look at THE tut? You would seem to be the perfect reader for it, because you are already a programmer. http://docs.python.org/tut/node6.html#SECTION00660 rd I initially looked at THE tut, and it came across so techy that it's such a slow read. Therefore, I looked to other tuts that were very easy reads and could give me the basic lowdown of the language. Problem of course is the easy read tuts don't get into the details. That said, I looked at the section of the tutorial you provided (thanks) and I am still confused. It specifies a global var cannot be assigned unless it's specified in the global statement. Here's an example of what I am asking: def my_function(): global x x = open( before calling my_function, x does not exist in my program. So, my question is in my_function, the combination of using the global statement, then implicitly creating x via assignment to the result of the open function, is x created in the global namespace? -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: Could not one of you just say @staticmethod for once damnit :) I did, did I not ? -- http://mail.python.org/mailman/listinfo/python-list
http client using ssh -D
Is there a python library which supports using SOCKS proxy which I create by ssh -D port remote-host? I was trying to use that socket by SocksiPy, but I get channel 3: open failed: administratively prohibited: open failed on the server side. And I can use that channel freely with firefox. Any other library I might use? -- Now the storm has passed over me I'm left to drift on a dead calm sea And watch her forever through the cracks in the beams Nailed across the doorways of the bedrooms of my dreams -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On 2007-11-02, Jim Hendricks [EMAIL PROTECTED] wrote: New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: 1) global vars - python sets scope to the block a var is declared (1st set), I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, or, when 1st set in a function where it is listed as a global, does that then declare the necessary global. Names that are assigned in an assignment statement are assumed to be defined in the current scope. Names that are assigned to in a function are considered local variables to that function. This allows them to be faster to access than other attributes or global variables (which are just attributes of a module). def foo(): x = 7 In function foo x is a local variable. This is true even if there is an x defined in foo's enclosing scope. x = 5 def foo(): x = 7 x is a local variable, which shadows the module scope (global) x. x = 5 If x is referenced, but not assigned to, then Python does not create a local variable for it, and normal lookup rules will cause x to be found in the enclosing scope of the bar function, below: def bar(): print x In bar, the x name refers to the global x. In order to inform Python that you would like to make modifications to a global variable in a function, you use the global statement to declare your intation. This overrides Python's assumption that that name is a local variable. x = 5 def foo2(): global x x = 7 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. If a module is an object, would not every function be a method of that module and every variable be a field of that module? You are almost correct. Every identifier/name in Python is conceptually an attribute of an object. But identifiers in Python are not typed. It is the objects that they refer to that are typed. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Bjoern Schliessmann [EMAIL PROTECTED] wrote: Jim Hendricks wrote: I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, You can't just declare in Python, you always define objects (and bind a name to them). Yes, globals need to be defined before you can access them using global. Why not try it out for yourself (both of you). Globals do not need to be defined in the global scope so long as the first 'access' is to bind a value to the variable: aglobal Traceback (most recent call last): File pyshell#0, line 1, in module aglobal NameError: name 'aglobal' is not defined def f(): global aglobal aglobal = 1 f() aglobal 1 If a module is an object, would not every function be a method of that module and every variable be a field of that module? They are. A function is an attribute of the module which contains it, not a method. It is just like when you do: class AClass(object): pass def f(): print hi c = AClass() c.f = f c.f() hi 'f' is an attribute of 'c', not a method of 'c'. To be a method of 'c', 'f' would have to be an attribute of the type 'AClass'. To be a method of a module, a function would have to be defined in the module type, not a specific module instance. Modules do have a few methods, e.g. __repr__, but you cannot assign additional methods to the module type nor can you subclass it. import string string.__repr__() module 'string' from 'C:\\Python25\\lib\\string.pyc' The difference, of course, is that the module method __repr__ has a self parameter which it may use to get at the module. Functions don't have easy access to their module. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
Wildemar Wildenburger wrote: Bjoern Schliessmann wrote: No, since everyone's crystal balls are in repair. I don't even have crystal balls! Not many are rich *and* impotent. :) Regards, Björn -- BOFH excuse #14: sounds like a Windows problem, try calling Microsoft support -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Please use a more informative subject next time. Jim Hendricks wrote: 1) global vars - python sets scope to the block a var is declared (1st set), http://docs.python.org/ref/global.html I'm afraid not. Python only interprets the listed name(s) as globals. I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, You can't just declare in Python, you always define objects (and bind a name to them). Yes, globals need to be defined before you can access them using global. 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. Because they are different things to achieve different goals. One holds data, the other does stuff. But nonetheless, both a function and a string literal have their own set of methods. You can look at them using dir, a function to show attributes (the pythonic word for fields/methods) of objects. def test(): ... print test ... dir(test) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] dir(honk) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] If a module is an object, would not every function be a method of that module and every variable be a field of that module? They are. BTW, don't confuse class and object. Classes also are objects. import os dir (os) [[...], '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list', '_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', '_spawnvef', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'chown', 'chroot', 'close', 'confstr', 'confstr_names', 'ctermid', 'curdir', 'defpath', 'devnull', 'dup', 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fchdir', 'fdatasync', 'fdopen', 'fork', 'forkpty', 'fpathconf', 'fstat', 'fstatvfs', 'fsync', 'ftruncate', [...]] Regards, Björn -- BOFH excuse #205: Quantum dynamics are affecting the transistors -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On Nov 2, 8:51 am, Jim Hendricks [EMAIL PROTECTED] wrote: New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: Did you look at THE tut? You would seem to be the perfect reader for it, because you are already a programmer. http://docs.python.org/tut/node6.html#SECTION00660 rd -- http://mail.python.org/mailman/listinfo/python-list
PyQt with embedded python in Qt App
On Fri Nov 2 12:59:48 CET 2007, Bart. wrote: Or I want to use PyQt in scripts to have similar gui for plugins written in python Or I want to extend application by scripts with PyQt. Or better question: How to easy add python scripting in Qt application and have almast all objects of app accesible in scripts? Kross could be good solution? You can use PyQt, Kross or PythonQt for this, but only PyQt will give you a comprehensive API out of the box. There is code in the PyQt source distribution that shows how to set up the Python interpreter inside a C++ plugin and import modules - it's used to load custom Python widgets into Qt Designer. Look at the designer/pluginloader.cpp file to get an idea of what you need to do. There are simpler ways to initialize Python, but this code should be helpful if you want to extend what you've done at a later time. David -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a usenet library for Python?
On 2007-11-02, Just Another Victim of the Ambient Morality [EMAIL PROTECTED] wrote: I'm interested in the former, an NNTP client. Thank you Grant and Jean-Paul (who answered this question in another post). I should have guessed at searching for NNTP instead of usenet... What to Google for is always obvious after the fact. :) -- Grant Edwards grante Yow! Th' MIND is the Pizza at Palace of th' SOUL visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
Abandoned == Abandoned [EMAIL PROTECTED] writes: Abandoned Yes i understand thank you. Now i find that maybe help the Abandoned other users. Abandoned import os Abandoned os.system(su postgres) Abandoned ... I get the distinct impression that you're trying to replace simple shell scripting with Python. While it's possible, you're probably making things much more complicated than they need to be. Unless you're actually doing something with all that data of yours, don't use Python where a simple shell script will be much smaller and cleaner. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
On Nov 2, 4:19 pm, Paul McNett [EMAIL PROTECTED] wrote: Abandoned wrote: Hi. I want to copy my database but python give me error when i use this command. cursor.execute(pg_dump mydata old.dump) What is the problem ? And how can i copy the database with python ? You are just going to have to give us more to go on. Please post the entire traceback of the error that you see (copy/paste it from your terminal). You can't issue system commands using the cursor's execute() method and expect that to work. execute() is for executing SQL, DML, or DDL, not for doing shell stuff. Try: import os os.system(pg_dump mydata /tmp/old.dump) but I'm not versed in postgressql, so this probably won't work exactly as written. You'd need to run that code from the server hosting the postgresql database. Note: The database's size is 200 GB Well, then you may want to make sure you have enough room on the target volume before trying to dump the file! Note that the dump file could conceivably be much larger (or much smaller) than the database itself. -- pkm ~http://paulmcnett.com Are there any way to copy database without dump or any temp files ? (If there is a temp my harddisk not enough for this operation :( ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
On Nov 2, 4:11 pm, Martin Sand Christensen [EMAIL PROTECTED] wrote: Abandoned == Abandoned [EMAIL PROTECTED] writes: Abandoned I want to copy my database but python give me error when i Abandoned use this command. cursor.execute(pg_dump mydata old.dump) Abandoned What is the problem ? cursor.execute() is for executing SQL commands, and this is not an SQL command, but rather a shell command. Abandoned And how can i copy the database with python ? Note: The Abandoned database's size is 200 GB If you want to do this from Python, run it as a separate process. Martin Yes i understand thank you. Now i find that maybe help the other users. import os os.system(su postgres) ... .. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
Abandoned wrote: Hi. I want to copy my database but python give me error when i use this command. cursor.execute(pg_dump mydata old.dump) What is the problem ? And how can i copy the database with python ? You are just going to have to give us more to go on. Please post the entire traceback of the error that you see (copy/paste it from your terminal). You can't issue system commands using the cursor's execute() method and expect that to work. execute() is for executing SQL, DML, or DDL, not for doing shell stuff. Try: import os os.system(pg_dump mydata /tmp/old.dump) but I'm not versed in postgressql, so this probably won't work exactly as written. You'd need to run that code from the server hosting the postgresql database. Note: The database's size is 200 GB Well, then you may want to make sure you have enough room on the target volume before trying to dump the file! Note that the dump file could conceivably be much larger (or much smaller) than the database itself. -- pkm ~ http://paulmcnett.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
Abandoned == Abandoned [EMAIL PROTECTED] writes: Abandoned I want to copy my database but python give me error when i Abandoned use this command. cursor.execute(pg_dump mydata old.dump) Abandoned What is the problem ? cursor.execute() is for executing SQL commands, and this is not an SQL command, but rather a shell command. Abandoned And how can i copy the database with python ? Note: The Abandoned database's size is 200 GB If you want to do this from Python, run it as a separate process. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
On Fri, 2007-11-02 at 06:51 -0700, Abandoned wrote: Hi. I want to copy my database but python give me error when i use this command. cursor.execute(pg_dump mydata old.dump) cursor.execute executes SQL queries. pg_dump is not an SQL query, it is an operating system command. To execute OS commands, use os.system(...) or the subprocess module. Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Copy database with python..
Hi. I want to copy my database but python give me error when i use this command. cursor.execute(pg_dump mydata old.dump) What is the problem ? And how can i copy the database with python ? Note: The database's size is 200 GB -- http://mail.python.org/mailman/listinfo/python-list
python newbie
New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: 1) global vars - python sets scope to the block a var is declared (1st set), I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, or, when 1st set in a function where it is listed as a global, does that then declare the necessary global. 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. If a module is an object, would not every function be a method of that module and every variable be a field of that module? I'm sure I will have other questions, but, I have a specific task that I am coding in python, and having a better understanding of the language will keep me from writing crap based on other language bias. TIA, Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb.string_literal
On Fri, 2007-11-02 at 12:24 +, gert wrote: I want to escape binary data so i can insert data into a blob No, you don't want to escape binary data. You want to bind it to a parametrized query: http://informixdb.blogspot.com/2007/07/filling-in-blanks.html Keep in mind, though, that MySQLdb uses %s as parameter markers instead of the SQL standard question mark. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Bjoern Schliessmann wrote: Please use a more informative subject next time. Jim Hendricks wrote: 1) global vars - python sets scope to the block a var is declared (1st set), http://docs.python.org/ref/global.html I'm afraid not. Python only interprets the listed name(s) as globals. I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, You can't just declare in Python, you always define objects (and bind a name to them). Yes, globals need to be defined before you can access them using global. This sounds like an issue of terminology. I understand that I don't declare variables like I would in C or Java, but that they are implicitly declared via the first assignment. And the define objects and bind a name to them makes no sense to me. I can only assume that if I say: my_file = open( ... the techy explaination is that the open function defines a file object and binds the name my_file to it. To me, it's easier to say that the open function creates a file object and assigns a reference to the my_file variable. If my_file does not exist, it is created, if my_file does exist, prior to the assignment, the type of my_file is checked to ensure type safety. You state that globals need to be defined before you can access them using global, so, now the question is, how to define in the global scope. I guess I'm too function driven as a programmer. I have a function which opens a file. I have a bunch of other functions which access that opened file. Traditionally, I would declare the file_handle var as a global, then my function which opens the file can assign the file_handle, and all the functions that access the file can also access the file_handle. Since Python you do not declare variables, and from what I've read so far, Python is type strict, I don't know how I would outside a function create my file_var without actually opening my file outside a function. 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. Because they are different things to achieve different goals. One holds data, the other does stuff. You misinterpreted my question, I understand the difference between a function and a variable and the difference between a field and a method. What I didn't understand is that if a module is an object, then a function is a method of the module, so, why confuse things and call a chunk of functionalized code a function when it is in a module, but call it a method when it is part of an object. IMHO, if a module is an object then it is a whole lot less confusing to call a function definition a method definition, unless there is a real distinction between a function and a method. But nonetheless, both a function and a string literal have their own set of methods. You can look at them using dir, a function to show attributes (the pythonic word for fields/methods) of objects. def test(): ... print test ... dir(test) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] dir(honk) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] If a module is an object, would not every function be a method of that module and every variable be a field of that module? They are. K, then that gives further argument that making a distinction between the term function and method, or the term field and variable is just an exercise in confusion. BTW, don't confuse class and object. Classes also are objects. I'm a long time Java programmer, I understand that distinction. import os dir (os) [[...], '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_copy_reg', '_execvpe', '_exists', '_exit', '_get_exports_list', '_make_stat_result', '_make_statvfs_result', '_pickle_stat_result', '_pickle_statvfs_result', '_spawnvef', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'chown', 'chroot',
Re: compiling python 3000 on debian etch
On Nov 2, 6:56 pm, Carl Banks [EMAIL PROTECTED] wrote: Here is the home page for the Debian source package for Python 2.5--it lists the build dependencies. http://packages.debian.org/source/etch/python2.5 Ok Thanks With that help Ive got it down to this (output of (end of) make) Failed to find the necessary bits to build these modules: _bsddb_sha256 _sha512 dbm Cant figure out what they are or where they should come from... -- http://mail.python.org/mailman/listinfo/python-list
Re: compiling python 3000 on debian etch
On Nov 2, 8:24 am, Rustom Mody [EMAIL PROTECTED] wrote: Ive been trying to compile python 3000 on debian etch And on running test I get: 4 skips unexpected on linux2: test_tcl test_dbm test_ssl test_bsddb Can someone tell me what packages I am missing? Here is the home page for the Debian source package for Python 2.5--it lists the build dependencies. http://packages.debian.org/source/etch/python2.5 These dependencies shouldn't be much different for Python 3.0. Be sure to use dev versions of libraries, the packages should have -dev on the end. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: Could not one of you just say @staticmethod for once damnit :) why were you asking if you knew the answer? yeesh -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On Nov 2, 10:13 am, Jim Hendricks [EMAIL PROTECTED] wrote: Here's an example of what I am asking: Try this example from Beazley (pg 82) a = 42 def foo(): a = 13 foo() print a 42 By contrast: a = 42 b = 13 def foo(): global a, b a = 13 b = 0 foo() print a 13 print b 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb.string_literal
On Nov 2, 1:48 pm, Carsten Haese [EMAIL PROTECTED] wrote: On Fri, 2007-11-02 at 12:24 +, gert wrote: I want to escape binary data so i can insert data into a blob No, you don't want to escape binary data. You want to bind it to a parametrized query: http://informixdb.blogspot.com/2007/07/filling-in-blanks.html Keep in mind, though, that MySQLdb uses %s as parameter markers instead of the SQL standard question mark. ok thx, this is one of those questions i wished i asked way sooner. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: On Nov 2, 12:27 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? I think what Boris was being exceedingly unhelpful in saying was why should it work when you're calling methods that do not exist I don't see 'm1' or 'm2' defined for the class 'Test'. n -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
Bjoern Schliessmann wrote: gert wrote: Could not one of you just say @staticmethod for once damnit :) No, since everyone's crystal balls are in repair. I don't even have crystal balls! /W -- http://mail.python.org/mailman/listinfo/python-list
Re: Syntax coloring in Python interpreter
On Nov 1, 12:45 pm, braver [EMAIL PROTECTED] wrote: Greetings -- as a long time user of both Python and Ruby interpreters, I got used to the latter's syntax-coloring gem, wirble, which colorizes Ruby syntax on the fly. Is there anything similar for Python? What's wrong with IDLE? There's a plug-in for Eclipse that does syntax highlighting and more as well. So does ActiveState's ActivePython. Even Notepad++ can do highlighting. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? why should it ? -- http://mail.python.org/mailman/listinfo/python-list
Re: marshal vs pickle
On Nov 1, 11:42 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: Aaron Watters [EMAIL PROTECTED] writes: marshal.loads('RKp,U\xf7`\xef\xe77\xc1\xea\xd8\xec\xbe\\') Segmentation fault ... I'll grant you the above as a denial of service attack. ... Can you give me an example where someone can erase the filesystem using marshal.load? You should always assume that if an attacker can induce a memory fault (typically through a buffer overflow) then s/he can inject and run arbitrary machine code ... Yes yes yes, but this takes an extraordinary amount of skill and criminal malice. With pickle an innocent person on another continent could potentially delete all the files on your computer by accident. In summary my view is this. - pickle is way too complicated and not worth the extra overhead and danger in most cases. - marshal is an excellent tool for getting large amounts of data in and out of Python that can be much faster than pickle and is always much less dangerous than pickle. I think it's safe enough for most RPC uses, for example. - It's a damn shame that the Python developers can't be bothered to make marshal portable across platforms and versions. It's a silly mistake. Sorry for all the fuss. -- Aaron Watters === http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=limiting+perl -- http://mail.python.org/mailman/listinfo/python-list
Re: Syntax coloring in Python interpreter
On 2007-11-02, Tim Golden [EMAIL PROTECTED] wrote: Neil Cerutti wrote: On 2007-11-01, Chris Mellon [EMAIL PROTECTED] wrote: On Nov 1, 2007 3:01 PM, Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-11-01, Lee Capps [EMAIL PROTECTED] wrote: On Nov 1, 2007, at 1:45 PM, braver wrote: Greetings -- as a long time user of both Python and Ruby interpreters, I got used to the latter's syntax-coloring gem, wirble, which colorizes Ruby syntax on the fly. Is there anything similar for Python? I believe IPython can do this: http://ipython.scipy.org/moin/ IPython's syntax coloring doesn't work with Windows 2000 and up, since (last I checked) it relies on a readline.py file, which relies on ANSI.SYS, which is not supported by the Windows console. If you scroll down about half a page in the above link you'll find a link to a readline implementation for Windows. That pyreadline.py appears to be an improvement on the Windows support when I last looked (6 months or so ago). Thanks for the heads up. And it's worth looking at ipykit[1] which is a standalone bundle of ipython py2exe-ed for Windows users. TJG [1] http://ipython.scipy.org/moin/IpyKit I installed the new version and the coloring works out of the box on Windows 2000 with Gary's PyReadline 1.4.4. -- Neil Cerutti If you throw at someone's head, it's very dangerous, because in the head is the brain. --Pudge Rodriguez -- http://mail.python.org/mailman/listinfo/python-list
using the filter function within class return error
I'm trying to use the __builtin__ filter function within a class; however, I receive the following error: NameError: global name 'MajEthnic' is not defined The line of code is: EthMaj = filter(self.MajEthnic,flist) So, I'm trying to use the MajEthnic function to filter the list flist. Any ideas? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On Fri, Nov 02, 2007 at 11:13:00AM -0400, Jim Hendricks wrote regarding Re: python newbie: BartlebyScrivener wrote: On Nov 2, 8:51 am, Jim Hendricks [EMAIL PROTECTED] wrote: New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: Did you look at THE tut? You would seem to be the perfect reader for it, because you are already a programmer. http://docs.python.org/tut/node6.html#SECTION00660 rd I initially looked at THE tut, and it came across so techy that it's such a slow read. Therefore, I looked to other tuts that were very easy reads and could give me the basic lowdown of the language. Problem of course is the easy read tuts don't get into the details. That said, I looked at the section of the tutorial you provided (thanks) and I am still confused. It specifies a global var cannot be assigned unless it's specified in the global statement. Here's an example of what I am asking: def my_function(): global x x = open( before calling my_function, x does not exist in my program. So, my question is in my_function, the combination of using the global statement, then implicitly creating x via assignment to the result of the open function, is x created in the global namespace? Yes. y Traceback (most recent call last): File pyshell#8, line 1, in module y NameError: name 'y' is not defined def f(): global y y = 123 f() y 123 Remember, the interactive interpreter is your friend. Just type 'python' at the command line and hammer away. (It's even better through a decent IDE). Oh yeah, you have to actually call f before y will get defined. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Leo 4.4.4 Final released
Leo 4.4.4 Final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html Leo 4.4.4 contains many important features originally planned for later releases. The highlights of Leo 4.4.4: - The Great Graph Aha: simple scripts allow Leo outlines to represent arbitrary directed graphs. There is no need for a separate 'graph world'. The graphed.py plugin is a direct result of this Aha. The graphed.py plugin allows you to create general graphs from Leo outlines. - @menus trees in settings files create all of Leo's menus. It is now dead easy to make Leo's menus look the way you want. - @buttons trees in settings files create common @button nodes created in all Leo outlines. - @auto nodes eliminate sentinels in derived files, thereby allowing people to collaborate using Leo more easily. **Warning**: for now, please make backup copies of files imported with @auto. - New commands for resolving cvs conflicts. - A threading_colorizer plugin replaces the __jEdit_colorizer__ plugin. This plugin features much better performance and a new, elegant algorithm. - Leo is now compatible with jython. - Better support for icons in headlines. - Many bug fixes and other minor improvements. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterable Flattener with Depth.
thebjorn wrote: On Nov 2, 6:32 am, praddy [EMAIL PROTECTED] wrote: On Nov 1, 5:03 pm, [EMAIL PROTECTED] wrote: Pradeep Jindal: Any comments? Something with similar functionality (plus another 20 utility functions/classes or so) has probably to go into the std lib... :-) Bye, bearophile Same Here! - Pradeep Yeah, everyone has to write a flatten sooner or later :-) My version is at: http://blog.tkbe.org/archive/python-flatten/ -- bjorn And here is mine. Note that it is very similar to Michael Spencer's implementation[1]. The only difference is that this adds a depth counter. def iflat(itr, depth=0): itr = iter(itr) stack = [] cur_depth = 0 while True: try: elem = itr.next() if hasattr(elem, __iter__) and cur_depth depth: stack.append(itr) itr = iter(elem) cur_depth += 1 else: yield elem except StopIteration: if not stack: raise StopIteration cur_depth -= 1 itr = stack.pop() if __name__ == __main__: test1 = ((0, 1, 2), ((3, 4), 5), (((6, 7), 8), 9)) test2 = [1,[2,[3,4,5],'bash'],6,[7,[8,[9,10,['hi', 'hello', 11, 12] for x in (test1, test2): print print list(iflat(x)) print print list(iflat(x, 1)) print list(iflat(x, 2)) print list(iflat(x, 3)) print list(iflat(x, 4)) print iflat(x, 10) Ian [1] http://mail.python.org/pipermail/python-list/2005-March/312022.html -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
On Nov 2, 4:04 pm, Boris Borcic [EMAIL PROTECTED] wrote: gert wrote: Could not one of you just say @staticmethod for once damnit :) I did, did I not ? i am sorry, yes you did :) -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
J. Clifford Dyer wrote: before calling my_function, x does not exist in my program. So, my question is in my_function, the combination of using the global statement, then implicitly creating x via assignment to the result of the open function, is x created in the global namespace? Yes. y Traceback (most recent call last): File pyshell#8, line 1, in module y NameError: name 'y' is not defined def f(): global y y = 123 f() y 123 tks, and tks also for the example. Remember, the interactive interpreter is your friend. Just type 'python' at the command line and hammer away. (It's even better through a decent IDE). yes, you are correct, last time I had the advantage of a console was when I was working in Forth. Working with Java PHP for a living makes one forget that Python has the console. Oh yeah, you have to actually call f before y will get defined. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On Nov 2, 3:35 pm, Jim Hendricks [EMAIL PROTECTED] wrote: This sounds like an issue of terminology. I understand that I don't declare variables like I would in C or Java, but that they are implicitly declared via the first assignment. And the define objects and bind a name to them makes no sense to me. I can only assume that if I say: my_file = open( ... the techy explaination is that the open function defines a file object and binds the name my_file to it. To me, it's easier to say that the open function creates a file object and assigns a reference to the my_file variable. If my_file does not exist, it is created, if my_file does exist, prior to the assignment, the type of my_file is checked to ensure type safety. Objects have types, names (what you're calling variables) don't. my_file = open ... binds the name 'my_file' to a file object. A subsequent my_file = 7 will bind the name 'my_file' to an int object. No type-checking involved (but neither is there any loss of type safety). James -- http://mail.python.org/mailman/listinfo/python-list
Re: Is pyparsing really a recursive descent parser?
On Nov 2, 5:47 am, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: Pyparsing is no recursive descent parser. It doesn't go back in the input stream. The ``OneOrMore(Word(alphas))`` part eats the 'end' and when it can't get more, the parser moves to the ``Literal('end')`` part which fails because the 'end' is already gone. Is there a way to get pyparsing to parse a grammar like this? Negative lookahead maybe: grammar = (OneOrMore(NotAny(Literal('end')) + Word(alphas)) + Literal('end')) Ciao, Marc 'BlackJack' Rintsch- Hide quoted text - - Show quoted text - Well I'll be darned! All this time, I thought recursive descent described the recursive behavior of the parser, which pyparsing definitely has. I never knew that backing up in the face of parse mismatches was a required part of the picture. In pyparsing, each construction gets composed from more fine-grained constructions, and they are called recursively to match or not match against the input string. For example, taking your working parser example: grammar = (OneOrMore(NotAny(Literal('end')) + Word(alphas)) + Literal('end')) This creates the following data structure: - And - OneOrMore - And - NotAny - Literal('end') - Word(alphas) - Literal('end') Every instance in this structure derives from the base class ParserElement, which defines a method parse(). parse() in turn calls preParse(), parseImpl(), and postParse(). If parseImpl succeeds, it returns a ParseResults object and the next location within the input string to continue parsing. The parseImpl methods are most often overridden in the subclasses (a few override postParse as well), such as: - And.parseImpl invokes parse() (note the recursion) on each of the expressions in its list. All must succeed or And.parseImpl throws an exception. - OneOrMore.parseImpl invokes parse() on its contained expression, which must succeed at least once; if not, the exception is rethrown. If the contained expression succeeds once, then its parse() method is called again and again until it fails, but no exceptions are rethrown, since only one match was actually required. - NotAny inverts the success/failure of its contained expression. If the expression's parse() method succeeds, NotAny.parseImpl throws an exception. If the contained expression's parse() method throws an exception, NotAny returns successfully. (NotAny does not advance the parse location, nor does it return any tokens.) - Literal and Word are terminals, in that they do not invoke any other expression's parse() method. Literal.parseImpl tests whether its string exists at the current parse location, and throws an exception if it doesn't. Word.parseImpl tests whether the current parse location contains a letter in the Word instance's set of valid initial characters - if so success; if not, throws an exception. It then advances through the input string, matching characters in the Word instance's set of valid body characters. The entire matched string is then returned, along with an updated string index at which to continue parsing. In my concept of recursive descent parsing, I was under the impression that pyparsing's use of this data structure, and *recursive* calls of parse() as it *descends* through the data structure, constituted a recursive descent parser. What the OP requested was a more regular expression-ish matcher, with backup (or backtracking). Your example did not include either of the alternation classes, MatchFirst or Or. These classes implement a form of backtracking on the stack, that if we descend into an expression on the list of alternatives, and that expression fails, then MatchFirst or Or will back up to the same starting location and try the next alternative. (MatchFirst is an eager matcher, in that it will pick the first matching expression in its list - Or is an exhaustive matcher, in that it will evaluate all of the alternatives, and select the longest match.) The Wikipedia entry for Recursive Descent Parser describes this parser model as a predictive parser, and later goes on to say that some (uncited) authors equate predictive parser with recursive descent parsers. The article makes a special distinction for a recursive parser with backup, which is what I believe the OP was asking for. Yes, pyparsing is definitely *not* a recursive descent parser with backup. The solution, as you correctly posted, is to add a negative lookahead. NotAny is also represented using the '~' operator. By the way, there are a couple of other places where pyparsing diverges from the standard model: - implicit whitespace skipping - user-definable comment skipping - attachment of parse actions to expressions These features, while atypical, provide some added capability and ease- of-use in creating quick and simple parsers. So I will take my stance with the uncited authors who lump predictive parsers in with recursive descent parsers. -- Paul --
Re: new style class
On Nov 2, 2:10 pm, Wildemar Wildenburger [EMAIL PROTECTED] wrote: Bjoern Schliessmann wrote: gert wrote: Could not one of you just say @staticmethod for once damnit :) No, since everyone's crystal balls are in repair. I don't even have crystal balls! /W lol -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: [...] Why doesn't this new style class work in python 2.5.1 ? why should it ? I don't know I thought it was supported from 2.2? oops the code is like this but doesn't work class Test(object): def m1(self,v): return v def m2(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') You should put a '@staticmethod' decorator before your m2 method definition -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb.string_literal
I want to escape binary data so i can insert data into a blob Using MySQLdb.string_literal(data) doesn't seem to escape everything ? -- http://mail.python.org/mailman/listinfo/python-list
compiling python 3000 on debian etch
Ive been trying to compile python 3000 on debian etch And on running test I get: 4 skips unexpected on linux2: test_tcl test_dbm test_ssl test_bsddb Can someone tell me what packages I am missing? -- http://mail.python.org/mailman/listinfo/python-list
Re: os.readlink returning value
On 2 Nov, 05:30, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' [EMAIL PROTECTED] escribió: I was reading os.readlink doc which says: readlink( path) Return a string representing the path to which the symbolic link points. The result may be either an absolute or relative pathname; if it is relative, it may be converted to an absolute pathname using os.path.join(os.path.dirname(path), result). Availability: Macintosh, Unix. ...It's not clear to me when the returning result could be absolute and when it could be relative. Could someone clarify this point? That depends on how the symlink was created. Assume the current directory is /usr/home/giampaolo/any/dir ln -s ../foo/bar creates a symbolic link at /usr/home/giampaolo/any/dir/bar pointing to ../foo/bar (relative to where the link resides). That is, actually pointing to /usr/home/giampaolo/any/foo/bar (but this absolute path is NOT stored on the link itself - only ../foo/bar) Now, a program whose current directory is /usr/home/giampaolo executes this: readlink(any/dir/bar) It will return the string ../foo/bar. One must resolve the .. reference relative to where the link resides, NOT relative to the current directory. That is, relative to any/dir. os.path.dirname(any/dir/bar) returns exactly that. Then, the suggested expression in the docs evaluates to any/dir/../foo/bar - it's not an absolute pathname yet, one should use abspath() on it. Or instead os.path.join(os.path.abspath(os.path.dirname(path)), result) -- Gabriel Genellina Thanks for the examplanation. I'd only want to do the same as what ls does in such cases. Imho, os.readlink() should have the same behaviour of ls, isn't it? -- http://mail.python.org/mailman/listinfo/python-list
new style class
class Test(object): def execute(self,v): return v def escape(v): return v if __name__ == '__main__': gert = Test() print gert.m1('1') print Test.m2('2') Why doesn't this new style class work in python 2.5.1 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt with embedded python in Qt App
On Nov 2, 8:03 am, Bart. [EMAIL PROTECTED] wrote: Friday 02 of November 2007 01:06:58 Diez B. Roggisch napisa (a): So how to pass this object into embeded python interpreter (executed script)? Anyone know any example? You don't pass it, you _retrieve_ it in the embedded interpreter by invoking the code given to you. Know any example, please? For better understand this :) I wan't add scripting to one application wrotten with Qt. So, you have Qt/C++ application which you want to script through python. But why do you need PyQt for ? If you design a script api in python and bind it using whatever binding technology (manually, boost, sip, pyrex, ...), you should not need to use PyQt. Or do you mean to use PyQt as the binding technology ? Philippe -- http://mail.python.org/mailman/listinfo/python-list
difference between IDLE and command line
New to Python, and just had something strange happen. I've been running my new code in IDLE running in windows. My IDLE version shows as 1.2.1, Python version displaying in IDLE is 2.5.1. I have been editing my code in UltraEdit then testing in IDLE by choosing open, then F5. I didn't see an easy way to refresh in IDLE, so each edit I've been closing the file (not IDLE itself), then opening again. Since IDLE does not keep track of what directory I last opened from, this gets tedious, so I decided to run my code from the command line. Here's where it got interesting for me. From the command line, I'm in the directory containing my source, I execute via python mycode.py, I receive an error in my code. Specifically, it's erroring because I have a copyright character in a string that I am outputting via the file.write method. The error has to do with no encoding declared. What surprised me is that this code runs with no problems in IDLE. Should I expect different execution behavior between IDLE and a command prompt? Oh, and executing python all by itself in the command prompt shows the same version as what is displayed in IDLE. -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Bjoern Schliessmann a écrit : Jim Hendricks wrote: (snip) I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, You can't just declare in Python, you always define objects (and bind a name to them). def toto(): global p p = 42 Here I declared 'x' as global without defining it. Yes, globals need to be defined before you can access them using global. For which definition of 'defined' ? p Traceback (most recent call last): File stdin, line 1, in module NameError: name 'p' is not defined toto() p 42 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. Because they are different things to achieve different goals. One holds data, the other does stuff. Hem... I'm not sure you're really addressing the OP's question here. But anyway: in Python, everything's an object, so the only thing that makes functions a bit specials is that they are callable - as are classes, methods, and every instance of a class implementing __call__ FWIW. So saying 'variables holds data, functions do stuff' is unapplyiable to Python. (snip) If a module is an object, would not every function be a method of that module and every variable be a field of that module? They are. functions are *not* methods of their module. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: oops the code is like this but doesn't work For sake of the god of your choice, please always provide runnable code as well as hints to - what you think it should do - what you want it to do - what exact error message(s) you get NOT just it doesn't work. Regards, Björn -- BOFH excuse #279: The static electricity routing is acting up... -- http://mail.python.org/mailman/listinfo/python-list
Writing GTK UI for Python apps in XUL
Hi everyone, Is it possible to write UI code in XUL for a GTK Python application? I found NuFox, which does the reverse (lets me write Python to generate XUL) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterable Flattener with Depth.
On Nov 2, 6:32 am, praddy [EMAIL PROTECTED] wrote: On Nov 1, 5:03 pm, [EMAIL PROTECTED] wrote: Pradeep Jindal: Any comments? Something with similar functionality (plus another 20 utility functions/classes or so) has probably to go into the std lib... :-) Bye, bearophile Same Here! - Pradeep Yeah, everyone has to write a flatten sooner or later :-) My version is at: http://blog.tkbe.org/archive/python-flatten/ -- bjorn -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCheck for a classes defined in python and user data in PyObject_HEAD
Note that there is a mailing list dedicated to the Python/C API, http://mail.python.org/mailman/listinfo/capi-sig [EMAIL PROTECTED] writes: issue #2 I'm in a situation when i don't really need to extend python with any classes of my own but i do have extra luggage for the python data structures such as tuples, lists, dictionaries, etc on the c++ side. I see no place in PyObject_HEAD where i can stick a void* to my extra data. Adding additional luggage is a valid definition of extending. :-) Simply inherit from the desired data structure, and add the pointers you need to the extended structure. If you must add extra data to existing Python objects created by someone else, then you can use a weak dictionary: import weakref _map = {} # can't use WeakKeyDictionary because we need # mapping by identity def set_extra_data(obj, data): # use id(obj) as key to map by object identity ident = id(obj) ref = weakref.ref(obj, lambda x: _map.pop(ident)) _map[ident] = ref, data def extra_data(obj): if id(obj) not in _map: raise TypeError(object has no extra data) ref, data = _map[id(obj)] assert ref() is obj return data -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python 3000 Question
Steven D'Aprano a écrit : On Fri, 02 Nov 2007 03:40:59 +, Tim Roberts wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Wed, 31 Oct 2007 22:48:12 -0700, Carl Banks wrote: I hope you're not serious that $# would make a good operator. If you happen to know where I borrowed it from, it would be pretty evident that I wasn't being serious. Ooh, now I'm curious. Seriously? You didn't know that $#x in perl returns the length of the array @x, minus 1? I don't speak Perl. Nor do I, but such an ugly syntax is a sure hint !-) -- http://mail.python.org/mailman/listinfo/python-list
looping
hi everybody, I have a file: A_16_P21360207 304 A_14_P136880783 A_16_P21360209795 A_16_P21360210173 A_16_P036419591177 A_16_P036419601944 A_16_P03641962999 A_16_P036419633391 A_16_P415636493626 A_16_P03641964180 A_16_P415636551216 A_16_P036419651170 A_16_P03641966194 A_16_P21360229290 my script: import math values_lis = [] fh = open('test5','r') for line in fh.readlines(): data = line.strip().split('\t') probe = data[0].strip() values= data[1].strip() value = values[0].strip() value =float(values) old = 0 if value =old: old = value print '%s\t%s'%(probe,old) I am aiming to remove the lowest values in the second column by iterating one over the othersay for example 304 , is lesser than the second row value 783 so i omit the first column first value.. in the same case in the third row 795 is greater the 783 so i omit the 783the second row... this to be carried out for attaining my destination... i have written the sript but it doesnot not remove the lesser values...can you please chek where i go wrong... -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding GNU Readline after installation?
On Nov 2, 3:37 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I compiled Python from source on a bunch of my development machines without enabling the readline modules. Is it possible to add readline support after installation? I really just want to get my up arrow history working... Google for rlwrap. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Syntax coloring in Python interpreter
Neil Cerutti wrote: On 2007-11-01, Chris Mellon [EMAIL PROTECTED] wrote: On Nov 1, 2007 3:01 PM, Neil Cerutti [EMAIL PROTECTED] wrote: On 2007-11-01, Lee Capps [EMAIL PROTECTED] wrote: On Nov 1, 2007, at 1:45 PM, braver wrote: Greetings -- as a long time user of both Python and Ruby interpreters, I got used to the latter's syntax-coloring gem, wirble, which colorizes Ruby syntax on the fly. Is there anything similar for Python? I believe IPython can do this: http://ipython.scipy.org/moin/ IPython's syntax coloring doesn't work with Windows 2000 and up, since (last I checked) it relies on a readline.py file, which relies on ANSI.SYS, which is not supported by the Windows console. If you scroll down about half a page in the above link you'll find a link to a readline implementation for Windows. That pyreadline.py appears to be an improvement on the Windows support when I last looked (6 months or so ago). Thanks for the heads up. And it's worth looking at ipykit[1] which is a standalone bundle of ipython py2exe-ed for Windows users. TJG [1] http://ipython.scipy.org/moin/IpyKit -- http://mail.python.org/mailman/listinfo/python-list
Re: 3 number and dot..
On Fri, 02 Nov 2007 16:39:12 +, Roberto Bonvallet wrote: On 31 oct, 22:21, Paul Rubin http://[EMAIL PROTECTED] wrote: def convert(n): assert type(n) in (int,long) I'd replace this line with n = int(n), more in the spirit of duck typing. Not necessarily. Something duck typing is too liberal in what it accepts. You might want convert(math.pi) to raise an exception, although I'd suggestion an assert is the wrong test. A better test would be an explicit type check with raise: if not isinstance(n, (int, long)): raise TypeError('n not an integer') assert is for this can never happen tests rather than type checking. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
Could not one of you just say @staticmethod for once damnit :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy database with python..
Abandoned wrote: On Nov 2, 4:19 pm, Paul McNett [EMAIL PROTECTED] wrote: Abandoned wrote: Hi. I want to copy my database but python give me error when i use this command. cursor.execute(pg_dump mydata old.dump) What is the problem ? And how can i copy the database with python ? You are just going to have to give us more to go on. Please post the entire traceback of the error that you see (copy/paste it from your terminal). You can't issue system commands using the cursor's execute() method and expect that to work. execute() is for executing SQL, DML, or DDL, not for doing shell stuff. Try: import os os.system(pg_dump mydata /tmp/old.dump) but I'm not versed in postgressql, so this probably won't work exactly as written. You'd need to run that code from the server hosting the postgresql database. Note: The database's size is 200 GB Well, then you may want to make sure you have enough room on the target volume before trying to dump the file! Note that the dump file could conceivably be much larger (or much smaller) than the database itself. -- pkm ~http://paulmcnett.com Are there any way to copy database without dump or any temp files ? (If there is a temp my harddisk not enough for this operation :( ) You can invoke the pg_dump on the remote machine. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Is pyparsing really a recursive descent parser?
On Fri, 02 Nov 2007 06:05:13 +, Just Another Victim of the Ambient Morality wrote: Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: from pyparsing import * grammar = OneOrMore(Word(alphas)) + Literal('end') grammar.parseString('First Second Third end') Amazingly enough, this will fail to parse! Now, maybe I have no idea what I'm talking about but shouldn't a recursive descent parser recursively descend through all possible rule combinations to discover one that works? Why does pyparsing fail to parse this? Pyparsing is no recursive descent parser. It doesn't go back in the input stream. The ``OneOrMore(Word(alphas))`` part eats the 'end' and when it can't get more, the parser moves to the ``Literal('end')`` part which fails because the 'end' is already gone. Is there a way to get pyparsing to parse a grammar like this? Negative lookahead maybe: grammar = (OneOrMore(NotAny(Literal('end')) + Word(alphas)) + Literal('end')) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some help...
Gabriel Genellina wrote: En Thu, 01 Nov 2007 20:12:52 -0300, Ricardo Aráoz [EMAIL PROTECTED] escribió: def sumToOneDigit(num) : if num 10 : return num else : return sumToOneDigit(sum(int(i) for i in str(num))) def sumToOneDigit(num): return num % 9 or 9 Valid when num=1, which is guaranteed by the OP context. Beautiful. Much better than mine. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python 3000 Question
Steven D'Aprano [EMAIL PROTECTED] writes: Seriously? You didn't know that $#x in perl returns the length of the array @x, minus 1? I don't speak Perl. You know there are million of us who have managed to avoid it. I used to use perl (though I was never an expert) and I didn't know that $#x returns yada yada. Lucky me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding GNU Readline after installation?
[EMAIL PROTECTED] wrote: I compiled Python from source on a bunch of my development machines without enabling the readline modules. Is it possible to add readline support after installation? I really just want to get my up arrow history working... No. You have to uncomment readline support in Modules/Setup, call make again and do a reinstall. Uwe -- http://mail.python.org/mailman/listinfo/python-list
Re: trapping DLL import issues without blocking pop up window
alf schrieb: Hi, there is following issue: import cx_Oracle on windows pops up a nice 'DLL missing' window in case there indeed is no CLI.DLL (or something like that). Then the exception is raised. Catching the exception is obviously not a problem, but the popup practically blocks the application and requires user intervention. There could be a legitimate case where Oracle environment is not available yet the program might want to get around it somehow. Executing this code before 'import cx_Oracle' should help: import ctypes; ctypes.windll.kernel32.SetErrorMode(1) See also http://msdn2.microsoft.com/en-us/library/ms680621.aspx Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
gert wrote: Could not one of you just say @staticmethod for once damnit :) No, since everyone's crystal balls are in repair. Regards, Björn -- BOFH excuse #256: You need to install an RTFM interface. -- http://mail.python.org/mailman/listinfo/python-list
Re: 3 number and dot..
On 31 oct, 22:21, Paul Rubin http://[EMAIL PROTECTED] wrote: def convert(n): assert type(n) in (int,long) I'd replace this line with n = int(n), more in the spirit of duck typing. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
Jim Hendricks a écrit : New to python, programming in 15 or so langs for 24 years. Couple of questions the tuts I've looked at don't explain: 1) global vars - python sets scope to the block a var is declared (1st set), I see the global keyword that allows access to global vars in a function, what I'm not clear on is does that global need to be declared in the global scope, or, when 1st set in a function where it is listed as a global, does that then declare the necessary global. Didn't you try by yourself ? Would have been faster than writing down your question... Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type help, copyright, credits or license for more information. def toto(): ... global p ... p = 42 ... p Traceback (most recent call last): File stdin, line 1, in module NameError: name 'p' is not defined toto() p 42 Anyway, remember that in Python, 'global' really means 'module level'. 2) Everything is an object. So then, why the distinction between functions/variables and fields/methods. If a module is an object, would not every function be a method of that module functions are *instance* attributes of the modules (obviously, since each module is a distinct instance of class 'module'...), and when functions are instance attributes of an object, the lookup mechanism doesn't turn them into methods. and every variable be a field of that module? There's nothing like a 'field' in Python - only attributes. And module-level (so-called 'global') vars *are* attributes of the module. So from 'the outside' (ie: from the importing code), a module is just an instance of class module, with it's own set of attributes - some of them callables (functions and classes), some other not. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: new style class
In article [EMAIL PROTECTED], Nigel Rantor [EMAIL PROTECTED] wrote: I think what Boris was being exceedingly unhelpful in saying was why should it work when you're calling methods that do not exist http://www.catb.org/~esr/faqs/smart-questions.html -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ Typing is cheap. Thinking is expensive. --Roy Smith -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing GTK UI for Python apps in XUL
Devraj == Devraj [EMAIL PROTECTED] writes: Devraj Hi everyone, Is it possible to write UI code in XUL for a Devraj GTK Python application? I found NuFox, which does the Devraj reverse (lets me write Python to generate XUL) i wrote such a system as a proof of concept, it's far from being complete. you can find the sources here: http://www.artiemestieri.tn.it/~azazel/darcs/snakegtk with it you can use python scripting inside xul files. Take a look at this http://www.artiemestieri.tn.it/~azazel/darcs/snakegtk/doc/site/ -- http://mail.python.org/mailman/listinfo/python-list
Webservices, SOAP and Python
Hello all, I'm trying to build a webserver client and I'm having quite the trouble. I ended up using ZSI (since it's the only one that I could actually install on my Linux system) but I wonder: is there any other software for this purpose? I read about SOAPpy and PyXML but since both are discontinued, what do you use? By the way, I'm having trouble connecting ZSI-using scripts to the internet. Every other script works. Why could this be happening? How can I prevent this? (I'm behind a proxy) Cheers! -- http://mail.python.org/mailman/listinfo/python-list
Re: using the filter function within class return error
On Fri, 02 Nov 2007 09:42:17 -0700, david.katkowski wrote: I'm trying to use the __builtin__ filter function within a class; however, I receive the following error: NameError: global name 'MajEthnic' is not defined The line of code is: EthMaj = filter(self.MajEthnic,flist) So, I'm trying to use the MajEthnic function to filter the list flist. Any ideas? Yes, many. The first idea is: the exception that you get tells you what's wrong. You should pay attention and define MajEthnic, just as it says. My second idea is that you're probably giving us incorrect information. I can't think of any possible way for the line of code you quote to give the NameError you say it does. I can think of how it might give a different NameError: class Parrot(object): flist = [1, 2, 3] EthMaj = filter(self.MajEthnic, flist) or possible an AttributeError: class Parrot(object): def method(self, flist): EthMaj = filter(self.MajEthnic, flist) but not the exception that you quote. My third idea is that if you want better help, you should provide better information. Please quote the entire traceback, not paraphrasing it, unless it is excessively long, in which case you can trim some of the extra stack trace (but tell us you've done so!). Please ensure you are actually quoting the correct line of code that generates the exception. My fourth idea is that your subject line is incorrect. The filter function does not RETURN an error, it RAISES an error. Using correct terminology is important. Although technically, it is just barely possible that filter actually is *returning* an exception, or at least a list containing an exception, if flist looks something like this: flist = [NameError(global name 'MajEthnic' is not defined), 0, 1, 2] Exceptions are objects like any other, and can be returned, although that would be extremely unusual, and not something that just happens -- you have to work at it! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Assertion for python scripts
Howdy ! I started using the assert() stmt and found it quite useful :-) I have only one problem: I don't know how to turn them off again. I know that -O turns off assertions in general. However, how do I pass thus parameter to python to an executable script ? I have tried the following: 1. !#/usr/bin/env python -O - Fails with this msg: /usr/bin/env: python -O: No such file or directory Also, putting it in quotes won't do it. 2. Passing the -O to the runnable script won't work either. Here is my question: How do I maintain debug / release builds that allow me to switch debug stmts, like assert, on / off ? Thanx, Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: Assertion for python scripts
On 11/2/07, matthias [EMAIL PROTECTED] wrote: Howdy ! I started using the assert() stmt and found it quite useful :-) I have only one problem: I don't know how to turn them off again. I know that -O turns off assertions in general. However, how do I pass thus parameter to python to an executable script ? I have tried the following: 1. !#/usr/bin/env python -O - Fails with this msg: /usr/bin/env: python -O: No such file or directory Also, putting it in quotes won't do it. 2. Passing the -O to the runnable script won't work either. Here is my question: How do I maintain debug / release builds that allow me to switch debug stmts, like assert, on / off ? Thanx, Matthias Use: python -O -mcompileall path That command will compile all of the files in the given path and produce .pyo files. If the .pyo file is present and up-to-date it will be used instead of the .py file. Alternatively you could do this: python -O -mpy_compile somefile.py which can be used to compile one file at a time. Many Python programs and modules include a compile step as part of their installation process. There is also a -OO option, which will strip doc-strings as well. Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: (MAC) CoreGraphics module???
David C. Ullrich wrote: On Thu, 01 Nov 2007 19:39:20 -0500, Robert Kern [EMAIL PROTECTED] wrote: David C. Ullrich wrote: [why doesn't CoreGraphics work?] That's different than the one that is referenced. The one those articles reference is only available in the Python that came with the system in /System/Library/Frameworks/Python.framework, not one that you might have installed from www.python.org into /Library/Frameworks/Python.framework. The module was made by Apple, and they have not released the source code, so it cannot be made to work with the www.python.org distribution. usenet is amazing - your reply appears to have been posted a half hour before my question! Thanks. So CoreGraphics is a builtin in Apple-Python, explaining why I didn't find the relevant CoreGraphics.py anywhere on the hard drive, eh? Okay, which version of OS X do you have? In 10.3 and 10.4 it used to be here: /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/CoreGraphics.py I notice that in 10.5, it no longer exists, though. Fine. Now what? Please feel free to bear in mind that I have very little experience with the Mac and with Unix - I'm certain that if I knew what I was doing there I wouldn't need to ask the questions below, sorry. And sorry about the length of this post - there's a second issue that maybe you could explain, that I'd really love to have an explanation for before modifying things. Anyway: Since I didn't do anything special to remove it when I installed the Python-Python, the Apple-Python should still be there, yes? Yes, in the location I mentioned. I'd appreciate any advice on how to get things set up the way I'd like. Below when I refer to the MacPython stuff I mean ApplicationLauncher (or however it's spelled, the Mac's at the office and I'm at home) and Idle; the stuff that gives convenient access to Python scripts in the GUI. Note that I don't have any particular reason to want to use the latest version of Python - I was actually getting along fine with 1.5 until very recently. I'd be perfectly happy to set things up so everything used the Apple-Python. (i) If I just uninstalled the Python-Python (how?) would everything (Terminal, the MacPython stuff) automagically find the Apple-Python instead? (ii) If not, what would I have to do to make things use the Apple-Python instead? (And if I have to do something to make that happen, would doing that still work if I just left the Python-Python sitting there?) Python-Python installed a couple of symlinks into /usr/local/bin and then put /usr/local/bin in the front of your $PATH environment variable so it gets picked up first on the terminal. For my Python-Python 2.5, I have python python2.5 pythonw pythonw2.5 python-config python2.5-config Remove these and then when you type python at the terminal, you will get /usr/bin/python, which points to the Apple-Python. OR: Is there something special I could do with CoreGraphics scripts and/or how I invoke them so that _they_ would use the Apple-Python while other scripts would just use the Python-Python as now? For scripts executed from the terminal, you could start them with a hash-bang line: #!/usr/bin/python Use chmod u+x on the script, and then you can execute it like any other program from the terminal. (A last choice would be a setup where most scripts work as they do now and I somehow make CoreGraphics work from Terminal but not in Finder...) (Hmm, a wild guess: something somewhere is an alias to Python-Python, and I just change that (how?) to an alias to Apple-Python?) I'm a little nervous about making any changes, because something very mysterious happened when I was setting things up the way they are now - since I have no idea what I did to make things work the way they are now I don't know that I could set things up the way they are now again if I had to. If you can explain the following that will be something (I've been meaning to ask about the following sometime, hasn't been important til now when I'm contemplating changing the setup): The history: I get a Mac. I discover that it includes Python, can't figure out how to execute .py files in Finder. I hear about MacPython. I install the small MacPython download, that's supposed to just add ApplicationLauncher(?), Idle, etc on top of the existing Python. Works fine _except_ that when I double-click a .py file in Finder it executes with the cwd equal to the root directory instead of the directory where the script is located. Trying to fix that I install the full MacPython, including Python itself. Doesn't help, scripts still execute in /. A few weeks later I decide to try to fix that. The plan is to edit whatever.py, the script that's supposed to run before everything else allowing customizations (always takes me a while to find the magic name in the docs - probably you know the name I mean). The
Re: marshal vs pickle
On Nov 1, 10:12 am, Aaron Watters [EMAIL PROTECTED] wrote: On Oct 31, 6:10 pm, Raymond Hettinger [EMAIL PROTECTED] wrote: Alright already. Here is the patched file you want http://nucular.sourceforge.net/kisstree_pickle.py This file has been removed. After consideration, I don't want to create the moral hazard that someone might distribute automatically executed malicious code pickled inside a nucular index. If you grabbed it, please destroy it. I'm going back to using marshal. I'd like to thank Raymond and others for motivating me to think this over. The possibilities for abuse are astounding. Honestly, if you download any package containing a pickle: delete it. -- Aaron Watters === How many mice does it take to screw in a light bulb? 2. -- http://mail.python.org/mailman/listinfo/python-list
Re: Assertion for python scripts
On Nov 2, 12:12 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 11/2/07, matthias [EMAIL PROTECTED] wrote: Howdy ! I started using the assert() stmt and found it quite useful :-) I have only one problem: I don't know how to turn them off again. I know that -O turns off assertions in general. However, how do I pass thus parameter to python to an executable script ? I have tried the following: 1. !#/usr/bin/env python -O - Fails with this msg: /usr/bin/env: python -O: No such file or directory Also, putting it in quotes won't do it. 2. Passing the -O to the runnable script won't work either. Here is my question: How do I maintain debug / release builds that allow me to switch debug stmts, like assert, on / off ? Thanx, Matthias Use: python -O -mcompileall path That command will compile all of the files in the given path and produce .pyo files. If the .pyo file is present and up-to-date it will be used instead of the .py file. Alternatively you could do this: python -O -mpy_compile somefile.py which can be used to compile one file at a time. Many Python programs and modules include a compile step as part of their installation process. There is also a -OO option, which will strip doc-strings as well. Matt Thanx for your reply , Matt ! However, I think I am missing something. Here is my example prog, assert.py, with the executable bit set: #!/usr/bin/env python assert 1 1, ASSERTTION ! Running this: # python ./assert.py Traceback (most recent call last): File assert.py, line 3, in ? assert 1 1, ASSERTTION ! AssertionError: ASSERTTION ! leads to the expected result. Now I do this as you've recommended: # python -O -mpy_compile assert.py This indeed creates a file with the name assert.pyo. That must be the optimized one. Now I try this: # ./assert.py Traceback (most recent call last): File ./assert.py, line 3, in ? assert 1 1, ASSERTTION ! AssertionError: ASSERTTION ! Ok, so it still uses the unoptimized version. Now I try this: # chmod 755 assert.pyo # ./assert.pyo bash: ./assert.pyo: cannot execute binary file Here is my problem: I want to have an optimized executable version of assert.py. I am assuming that I am thinking in an unconventional way wrt Python. If so, then how do you start your optimized python scripts ? Thanx, Matthias -- http://mail.python.org/mailman/listinfo/python-list
error ...1 value to unpack
hi everybody, i have a file: A_16_P21360207#304 A_14_P136880#783 A_16_P21360209#795 A_16_P21360210#173 A_16_P03641959#1177 A_16_P03641960#1944 A_16_P03641962#999 A_16_P41563648#-31 A_16_P03641963#3391 A_16_P41563649#3626 A_16_P03641964#180 A_16_P41563655#1216 A_16_P03641965#1170 A_16_P03641966#194 A_16_P21360229#290 A_16_P03641967#425 A_16_P21360231#1091 A_16_P03641968#1167 A_16_P03641969#421 A_16_P03641970#63 A_16_P21360234#290 A_16_P21360235#289 A_16_P03641971#398 A_16_P21360237#418 A_16_P03641972#122 A_16_P21360239#16 A_16_P03641973#2187 A_16_P41563669#2881 A_16_P03641974#1101fh = open('complete_span','r') data = fh.readline().split('#') old_probe = data[0].strip() old_value = data[1].strip() #print old_probe, old_value count = 1 while fh: current_probe, current_value = fh.readline().strip().split('#')[0:2] probe =current_probe.strip() value = current_value.strip() if old_value value: res_value='%s\t%s'%(old_value, old_probe) print res_value if count == 244000: break old_probe,old_value =probe, value fh.close() and i face this error:Traceback (most recent call last): File count_values.py, line 8, in module current_probe, current_value = fh.readline().strip().split('#')[0:2] ValueError: need more than 1 value to unpack why do i get this what is the solution for this regards shafreen A_16_P03641975#451 My script: -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterable Flattener with Depth.
On Friday 02 Nov 2007 10:43:45 pm Ian Clark wrote: thebjorn wrote: On Nov 2, 6:32 am, praddy [EMAIL PROTECTED] wrote: On Nov 1, 5:03 pm, [EMAIL PROTECTED] wrote: Pradeep Jindal: Any comments? Something with similar functionality (plus another 20 utility functions/classes or so) has probably to go into the std lib... :-) Bye, bearophile Same Here! - Pradeep Yeah, everyone has to write a flatten sooner or later :-) My version is at: http://blog.tkbe.org/archive/python-flatten/ -- bjorn And here is mine. Note that it is very similar to Michael Spencer's implementation[1]. The only difference is that this adds a depth counter. def iflat(itr, depth=0): itr = iter(itr) stack = [] cur_depth = 0 while True: try: elem = itr.next() if hasattr(elem, __iter__) and cur_depth depth: stack.append(itr) itr = iter(elem) cur_depth += 1 else: yield elem except StopIteration: if not stack: raise StopIteration cur_depth -= 1 itr = stack.pop() if __name__ == __main__: test1 = ((0, 1, 2), ((3, 4), 5), (((6, 7), 8), 9)) test2 = [1,[2,[3,4,5],'bash'],6,[7,[8,[9,10,['hi', 'hello', 11, 12] for x in (test1, test2): print print list(iflat(x)) print print list(iflat(x, 1)) print list(iflat(x, 2)) print list(iflat(x, 3)) print list(iflat(x, 4)) print iflat(x, 10) Ian [1] http://mail.python.org/pipermail/python-list/2005-March/312022.html Very nice non-recursive (iterative) implementation of the thing with required features. Yours is double faster than mine if depth is not specified, Mine is double faster than yours if depth is specified. And my main aim was the depth thingy. What do you think? - Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Re: 3 number and dot..
On 2 nov, 14:54, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Not necessarily. Something duck typing is too liberal in what it accepts. You might want convert(math.pi) to raise an exception What I meant was that the function should not reject unnecessarily non- numeric things that can be converted to a number, like a string. However, you're right: numeric things that are not integers should not be treated silently as if they were. although I'd suggestion an assert is the wrong test. A better test would be an explicit type check with raise. I completely agree. Cheers, -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: Assertion for python scripts
Friday 02 of November 2007 20:53:12 matthias napisał(a): On Nov 2, 12:12 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 11/2/07, matthias [EMAIL PROTECTED] wrote: Howdy ! I started using the assert() stmt and found it quite useful :-) I have only one problem: I don't know how to turn them off again. I know that -O turns off assertions in general. However, how do I pass thus parameter to python to an executable script ? I have tried the following: 1. !#/usr/bin/env python -O - Fails with this msg: /usr/bin/env: python -O: No such file or directory Also, putting it in quotes won't do it. 2. Passing the -O to the runnable script won't work either. Here is my question: How do I maintain debug / release builds that allow me to switch debug stmts, like assert, on / off ? Thanx, Matthias Use: python -O -mcompileall path That command will compile all of the files in the given path and produce .pyo files. If the .pyo file is present and up-to-date it will be used instead of the .py file. Alternatively you could do this: python -O -mpy_compile somefile.py which can be used to compile one file at a time. Many Python programs and modules include a compile step as part of their installation process. There is also a -OO option, which will strip doc-strings as well. Matt Thanx for your reply , Matt ! However, I think I am missing something. Here is my example prog, assert.py, with the executable bit set: #!/usr/bin/env python assert 1 1, ASSERTTION ! Running this: # python ./assert.py Traceback (most recent call last): File assert.py, line 3, in ? assert 1 1, ASSERTTION ! AssertionError: ASSERTTION ! leads to the expected result. Now I do this as you've recommended: # python -O -mpy_compile assert.py This indeed creates a file with the name assert.pyo. That must be the optimized one. Now I try this: # ./assert.py Traceback (most recent call last): File ./assert.py, line 3, in ? assert 1 1, ASSERTTION ! AssertionError: ASSERTTION ! Ok, so it still uses the unoptimized version. Now I try this: # chmod 755 assert.pyo # ./assert.pyo bash: ./assert.pyo: cannot execute binary file Here is my problem: I want to have an optimized executable version of assert.py. I am assuming that I am thinking in an unconventional way wrt Python. If so, then how do you start your optimized python scripts ? Thanx, Matthias check this: python ./assert.pyo -- http://mail.python.org/mailman/listinfo/python-list