self extracting zipefile (windows) and (standard module) zipefile
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. >>> fName = r"C:\tmp\mySelfExtratingFile.exe" >>> import zipfile >>> zipefile.is_zipfile(fName)) False Is there a wrapper or has some one experience with other libaries to extract those files? Thanks in advance Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: self extracting zipefile (windows) and (standard module) zipefile
On 29 Aug., 15:23, [EMAIL PROTECTED] wrote: > On Aug 29, 6:53 am, Werner <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > > I try to read (and extract) some "self extracting" zipefiles on a > > Windows system. The standard module zipefile seems not to be able to > > handle this. > > > >>> fName = r"C:\tmp\mySelfExtratingFile.exe" > > >>> import zipfile > > >>> zipefile.is_zipfile(fName)) > > > False > > > Is there a wrapper or has some one experience with other libaries to > > extract those files? > > > Thanks in advance > > Werner > > Since it's an executable, why not just use the subprocess module? > > I did find this set of scripts, but I don't know if they will > help:http://www.example-code.com/python/zip.asp > > I did find how to extract via the command line, which you could use in > conjunction with the subprocess > module:http://help.globalscape.com/help/cutezip2/Creating_and_extracting_arc... > > Mike- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - thank you for answer. I found, that WinZip aund 7-ZIP may handle my files (I'm not shure, if it's really zip...) So, I thing I try the 7- zip command line tool (but I'd prefered a Python buildin version) Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: self extracting zipefile (windows) and (standard module) zipefile
On 30 Aug., 06:26, Scott David Daniels <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: > > ... > > > Another option is to search through the file from the beginning > > looking for whatever signature matches the beginning of a > > "normal" zip file. The self-extracting zipfiles that I've > > dissected are just an executable image concatenated with a > > "normal" zipfile. If you just start searching from the > > beginning of the file, it's simple to find the actual zip data > > and copy it into a separate file which then can be unzipped > > like any other plain zipfile. > > Actually, the zip format is defined from the _end_ rather than > the _beginning_ of the file. Some random file with a zip file > concatenated on the end will have the same contents as the zip > file. You can even point Python itself at such files and get > data via: > import zipfile > zf = zipfile.ZipFile('something.exe') > ... > > -Scott David Daniels > [EMAIL PROTECTED] I hoped, this would work, but I got ": File is not a zip file"... WinZip and 7-ZIP may handle this file, so I take the command line version of 7-Zip (but I'd prefered a Python only version) Thanks Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: setuptools for 2.6 and windows?
On Nov 14, 2:22 am, Allan <[EMAIL PROTECTED]> wrote: > "Werner F. Bruhin" <[EMAIL PROTECTED]> writes: > > > I would like to start looking into Python 2.6 and do some testing. > > > First hurdle I run into is that I can not find a 2.6 installer for > > Windows for setuptools-0.6.9c, only Py2.4 and Py2.5 seem to be > > available on pypi. > > > Is there such a thing yet? If yes can someone provide me a link to > > it. > > What is currently available is the `egg' file which can be copied into the > same directory with the "setup.py" script for the package. Look for > "setuptools-0.6c9-py2.6.egg". I am trying to install Sphinx so that I > can build the Windows help files with the MS HTML Help tool. > > -- > Allan Thanks for the info Werner -- http://mail.python.org/mailman/listinfo/python-list
Newbie getting desperate with for
I have a trivially simple piece of code called timewaster.py: while True: i = 0 for i in range(10): break _ It runs fine with Eric but when I try to run it from shell... > ./timewaster.py ./timewaster.py: line 4: syntax error near unexpected token `(' ./timewaster.py: line 4: `for i in range(10):' I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python version 2.6.5, both show the above. Before I tear out my hair any more (only 3 left) I thought I'd ask here what I am doing wrong. Best Regards Werner Dahn -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie getting desperate with for
On 17/02/11 16:39, Chris Rebert wrote: > On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: >> I have a trivially simple piece of code called timewaster.py: >> >> >> while True: >>i = 0 >>for i in range(10): >>break >> _ >> >> It runs fine with Eric but when I try to run it from shell... >>> ./timewaster.py >> ./timewaster.py: line 4: syntax error near unexpected token `(' >> ./timewaster.py: line 4: `for i in range(10):' >> >> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python >> version 2.6.5, both show the above. >> >> Before I tear out my hair any more (only 3 left) I thought I'd ask here >> what I am doing wrong. > > Looks like it's being run as a shell script rather than through the > Python interpreter (hence why the error is not in the form of an > exception with a traceback). > > Try adding: > > #!/usr/bin/env python > > as the first line in your file. This tells the shell to run the script > using Python. > > Or alternatively, instead of: > > ./timewaster.py > > use: > > python timewaster.py > > which likewise explicitly invokes the Python interpreter. > > Cheers, > Chris > -- > http://blog.rebertia.com Yes, that was it. AYAA! Thank you very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie getting desperate with for
On 18/02/11 02:40, Alister Ware wrote: > On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: > >> On 17/02/11 16:39, Chris Rebert wrote: >>> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: >>>> I have a trivially simple piece of code called timewaster.py: >>>> >>>> >>>> while True: >>>>i = 0 >>>>for i in range(10): >>>>break >>>> _ >>>> >>>> It runs fine with Eric but when I try to run it from shell... >>>>> ./timewaster.py >>>> ./timewaster.py: line 4: syntax error near unexpected token `(' >>>> ./timewaster.py: line 4: `for i in range(10):' >>>> >>>> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python >>>> version 2.6.5, both show the above. >>>> >>>> Before I tear out my hair any more (only 3 left) I thought I'd ask >>>> here what I am doing wrong. >>> >>> Looks like it's being run as a shell script rather than through the >>> Python interpreter (hence why the error is not in the form of an >>> exception with a traceback). >>> >>> Try adding: >>> >>> #!/usr/bin/env python >>> >>> as the first line in your file. This tells the shell to run the script >>> using Python. >>> >>> Or alternatively, instead of: >>> >>> ./timewaster.py >>> >>> use: >>> >>> python timewaster.py >>> >>> which likewise explicitly invokes the Python interpreter. >>> >>> Cheers, >>> Chris >>> -- >>> http://blog.rebertia.com >> >> Yes, that was it. AYAA! >> >> Thank you very much. > > may I ask what is the purpose of this code segment, it does not look like > it would achieve much? > > > > It is meant to put load on a CPU, RAM and disk (swap). The code now looks like this: #!/usr/bin/python while True: i = 0 for i in range(2000): break I needed this to get an idea how virtual machines inside a host perform when you run a few instances of it. The objective was at what point responsiveness gets severely degraded by load. To measure that I used __ #!/usr/bin/python import time def time_it(threshold , period): t0 = time.time()# daytime at start of period time.sleep(period) t1 = time.time()# daytime at end of period t2 = t1-t0 # calculate actual lenght of period # subtract how long it should have been t3 =(t2 - period) *1000 if t3>=threshold: # if the differnce is too high report it print time.strftime('%Y/%m/%d %H:%M:%S ') , round(t3, 2), "ms" while True: time_it(5.0, 0.1) ___ Not very sophisticated but it gave me a few clues of what I'm interested in. Regards Werner Dahn -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie getting desperate with for
On 18/02/11 07:29, Cameron Simpson wrote: > On 18Feb2011 08:40, I wrote: > | On 17Feb2011 18:40, Alister Ware wrote: > | | On Thu, 17 Feb 2011 16:42:05 +0800, Werner wrote: > | | > On 17/02/11 16:39, Chris Rebert wrote: > | | >> On Thu, Feb 17, 2011 at 12:27 AM, Werner wrote: > | | >>> I have a trivially simple piece of code called timewaster.py: > | | >>> > | | >>> while True: > | [...] > | | may I ask what is the purpose of this code segment, it does not look like > | | it would achieve much? > [... long shebang description...] > > Hmm, looks like maybe you meant the original python snippet. > If so, my apologies for the long misanswer. It was't a misanswer, you were laying a finger on the wound and explained how things are. I am very grateful for that. This is my first contact with this newsgroup and I thank you all for being patient and understanding with a newbie. Best Regards Werner Dahn -- http://mail.python.org/mailman/listinfo/python-list
Re: object.enable() anti-pattern
On Wed, 8 May 2013, Steven D'Aprano wrote: I'm looking for some help in finding a term, it's not Python-specific but does apply to some Python code. This is an anti-pattern to avoid. The idea is that creating a resource ought to be the same as "turning it on", or enabling it, or similar. For example, we don't do this in Python: I'm not entirely sure what the name of it is, but the basic concept is that you should never partially create, or create a class that can be in an unstable state. Which isn't to say you should prevent invalid input, only that with every valid input or single operation (including construction) your class should be valid. Ah, that's it - the problem is that it introduces /Temporal Coupling/ to one's code: http://blog.ploeh.dk/2011/05/24/DesignSmellTemporalCoupling/ You don't ever want a class that has functions that need to be called in a certain order to *not* crash. That's fine if you have to call them in a certain sequence in order to get the correct data - that's what programming is all about, after all. But if you provide me a class with a constructor you better make sure that when I do this: thing = YourSuperAwesomeClass() thing.do_stuff() that I don't get some horrid stack trace ending with InvalidStateError: initialize() needs to be called before do_stuff() Or something worse. HTH, Wayne p.s. I'm interested in reading whatever is evenually written on the topic -- http://mail.python.org/mailman/listinfo/python-list
Re: object.enable() anti-pattern
On Fri, 10 May 2013, Robert Kern wrote: On 2013-05-10 12:00, Steven D'Aprano wrote: But either way, that's fine. You've found an object where it does make sense to have an explicit "make it go" method: first one entity has permission to construct the object, but not to open the underlying file. Another entity has permission to open the underlying file, but not to create the object. I have no idea whether this is a reasonable security design or not, it actually sounds a bit rubbish to me but what do I know? So let's treat it as a reasonable design. As I've said, repeatedly, that's not what I'm talking about. When you DON'T have useful things that can be done with the object before calling "enable", then it is an anti-pattern to require a separate call to "enable" method, and the enable functionality should be moved into the object constructor. If you DO have useful things that can be done, like pass the object to another entity, for security, then that's a whole 'nuther story. I'd be curious to see in-the-wild instances of the anti-pattern that you are talking about, then. I think everyone agrees that entirely unmotivated "enable" methods should be avoided, but I have my doubts that they come up very often. Do programmers have a natural tendency to make an extra, completely unnecessary method? I would think that they have a natural tendency to the opposite. In my experience, everyone has a reason in mind when they follow a pattern/anti-pattern. It is pretty rare that someone just does some specific, nameable thing for no reason at all. There is no need to call out an anti-pattern for which no one has a reason to do it. But there is a continuum of reasons. Some reasons are better than others. Some reasons only apply in a small set of circumstances but seem like they would apply more generally, at least to novice programmers. Programmers can be wrong about what they think the (anti-)pattern actually achieves. The whole point of naming an anti-pattern is to discuss those reasons, show where they are misapplied, where YAGNI, why novices overuse it, other patterns that should be used instead, and also the circumstances where it is actually a good pattern instead. I'll share the anti-pattern that I've seen many times (not actually in Python) class CoolPresenter: def __init__(self): self.view = None self.some_property = None self.other_property = None def initialize(self): self.view.disable() data = self.load_data() self.view.data = data self.view.enable() def reload(self): if self.view is None: raise NotInitializedError("Error: Please setup class") self.view.disable() data = self.load_data() self.view.data = data self.view.enable() Then you would see code like this: presenter = CoolPresenter() presenter.view = CoolView() This is just plain silly for a few reasons: - It's ambiguous. I don't know what's required for the CoolPresenter to function properly. - The temporal coupling mentioned earlier. I can create an instance of a class and then call a function (say `reload`) and then boom! My program crashes. There is *no possible* use case of this class where you can use it without a view. The motivation behind this anti-pattern that I've seen is the desire to not have a constructor that "does too much". So you end out with an empty constructor and temporal coupling, and a terrible API that doesn't clearly explain the requirements of the class. Your class constructor should *require* everything that is necessary to have a stable state when the class is created (i.e. you should be able to properly call any function, set any property without an exception happening) Why? Less bugs, easier to comprehend, change/update your code. Easier to use the class. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: object.enable() anti-pattern
On Fri, 10 May 2013, Gregory Ewing wrote: Wayne Werner wrote: You don't ever want a class that has functions that need to be called in a certain order to *not* crash. That seems like an overly broad statement. What do you think the following should do? f = open("myfile.dat") f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with *valid input* in order to not crash. Exactly what does happen - a ValueError is raised because you're(*) passing self into the file.read() function, and that input is invalid input - specifically: ValueError: I/O operation on closed file *where you actually means python, because when you call `your_instance.method()`, it works effectively like a call to `YourClass.method(your_instance)` -W -- http://mail.python.org/mailman/listinfo/python-list
Re: object.enable() anti-pattern
On Mon, 13 May 2013, Greg Ewing wrote: Wayne Werner wrote: On Fri, 10 May 2013, Gregory Ewing wrote: f = open("myfile.dat") f.close() data = f.read() To clarify - you don't want a class that has functions that need to be called in a certain order with *valid input* in order to not crash. Exactly what does happen - a ValueError is raised because you're(*) passing self into the file.read() function, and that input is invalid The same argument can be applied to: foo = Foo() foo.do_something() foo.enable() # should have done this first You're passing an invalid input to Foo.do_something, namely a Foo that hasn't been enabled yet. That is the crux of the argument - as designer of the class *you* need to ensure that when your constructor is done, your class is in a stable state. And that every other state transition (with valid input) results in your class then being in a stable state. If anything, the stronger argument is that `file.close()` is not a well designed function because it leaves your object in an unstable state. Which I would be inclined to agree with, but I couldn't give you the answer for what makes it better. Because the answer is the best one you can get in computer science: It depends. The reason that it depends, is because it depends on what you want to do. Do you want a program that seems purely functional? Do you want a program that's easy to maintain? Do you want a program that more accurately models the "real world"? Personally, I think the file object API in Python is about as good as it can get - but that's because it's working with "physical" things (i.e. files - bits on a platter, or flash/SSD drive...) which necessarily have a temporal nature. And it's much less badness to blow up on a call to `read` than it is to remove the `read` function and die with a NameError when the underlying file is in a closed state. At least in my opinion ;) -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Determine actually given command line arguments
On Wed, 15 May 2013, Henry Leyh wrote: Yes, I was trying that and it sort of works with strings if I use something sufficiently improbable like "__UNSELECTED__" as default. But it gets difficult with boolean or even number arguments where you just may not have valid "improbable" defaults. You could now say, so what, it's the default anyway. But in my program I would like to distinguish between given and not given arguments rather than between default and non-default. Have you looked into docopt? It's pretty awesome, and might really help in this case. HTH, -W -- http://mail.python.org/mailman/listinfo/python-list
Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.
On Fri, 28 Jun 2013, 8 Dihedral wrote: KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING WAS ASSIMULATED BY THE PYTHON COMMUNITY. OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES, OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS. Best. Post. EVER. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.
On Fri, 28 Jun 2013, Joel Goldstick wrote: On Fri, Jun 28, 2013 at 2:52 PM, Wayne Werner wrote: On Fri, 28 Jun 2013, 8 Dihedral wrote: KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING WAS ASSIMULATED BY THE PYTHON COMMUNITY. OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES, OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS. Best. Post. EVER. In the 'general' category? or by a 'bot'? I think generally - because Dihedral is a bot. I don't think it would be nearly as awesome if it were a person. -W-- http://mail.python.org/mailman/listinfo/python-list
Re: DOS or not? [was Re: How to tell Script to use pythonw.exe ?]
On Wed, 3 Jul 2013, Dennis Lee Bieber wrote: Consider that the Powershell default is to /prevent/ execution of script files unless some security settings have been changed; even local script files need to be "signed" to be executed. Protip: No they don't - wrap it in a cmd/bat file and have it launch powershell[1]: powershell -ExecutionPolicy Bypass -File ... \o/ Microsoft "security" at it again! (reminds me a bit of just pushing "Cancel" to log into windows 98, I think it was) -W [1]: http://stackoverflow.com/q/728143/344286 -- http://mail.python.org/mailman/listinfo/python-list
Re: Default scope of variables
On Thu, 4 Jul 2013, Steven D'Aprano wrote: [1] Based on empirical evidence that Python supports names with length at least up to one million characters long, and assuming that each character can be an ASCII letter, digit or underscore. The specification *does* state unlimited length: http://docs.python.org/release/2.5.2/ref/identifiers.html Though practicality beats purity. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Default scope of variables
On Fri, 5 Jul 2013, Chris Angelico wrote: Oh. Uhm... ahh... it would have helped to mention that it also has a commit() method! But yes, that's correct; if the object expires (this is C++, so it's guaranteed to call the destructor at that close brace - none of the Python vagueness about when __del__ is called) without commit() being called, then the transaction will be rolled back. If one wants to duplicate this kind of behavior in Python, that's what context managers are for combined with a `with` block, which does guarantee that the __exit__ method will be called - in this case it could be something as simple as: from contextlib import contextmanager @contextmanager def new_transaction(conn): tran = conn.begin_transaction() yield tran if not tran.committed: tran.rollback() Which you would then use like: conn = create_conn() with new_transaction(conn) as tran: rows_affected = do_query_stuff(tran) if rows_affected == 42: tran.commit() And then you get the desired constructor/destructor behavior of having guaranteed that code will be executed at the start and at the end. You can wrap things in try/catch for some error handling, or write your own context manager class. HTH, Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
On Thu, 4 Jul 2013, Νίκος Γκρ33κ wrote: Στις 4/7/2013 6:10 μμ, ο/η MRAB έγραψε: What do you mean "I don't know how to catch the exception with OSError"? You've tried "except socket.gaierror" and "except socket.herror", well just write "except OSError" instead! try: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] except OSError: host = "UnResolved" produces also an internal server error. Are you sure is just except OSError ? Have you ensured that 'REMOTE_ADDR' is actually a key in os.environ? I highly recommend using the logging module to help diagnose what the actual exception is. HTH, -W-- http://mail.python.org/mailman/listinfo/python-list
UTF-EBCDIC encoding?
Is anyone aware of a UTF-EBCDIC[1] decoder? While Python does have a few EBCDIC dialects in the codecs, it does not have the (relatively new?) UTF-EBCDIC one. Additionally, if anyone is aware of a Python tool that can unpack a mainframe PDS file, that would also be worthwhile. Thanks, Wayne [1]: https://en.wikipedia.org/wiki/UTF-EBCDIC -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On Sat, 13 Jul 2013, Νικόλας wrote: But it works for me, How can it be impossible and worked for me at the same time? 2 + 2 = 4 2 + 6 = 8??? Why can't I make 2 and 6 equal 4? It worked for 2, so I know it's not impossible! I don't care what everyone says, I was able to make one case work so obviously I juat need to figure out how to make it work! Allegorically, W-- http://mail.python.org/mailman/listinfo/python-list
Re: Ideal way to separate GUI and logic?
On Sat, 13 Jul 2013, fronag...@gmail.com wrote: Well, I'm a newcome to Python, but I'm developing a program with a GUI in tkinter, and I'm wondering what is the best, 'most pythonic' way of doing this? I could, obviously, write a monolithic block of code. True, you could, but don't do that. You should investigate strategies like model view presenter, and test or behavior driven development. My recommendation echos the other advice you've been given. Basically you think of your application in terms of two problems or domains. One is the what that you want no do. What information do you need? The other problem is how do you get that information from the user and retun to them information than they need? Regardless of which side you have driving, UI or Presenter, having a design such as this allows for much cleaner code. HTH -W -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On Sat, 13 Jul 2013, Νικόλας wrote: But then how do you explain the fact that http://www.maxmind.com/en/geoip_demo pinpointed Thessaloníki and not Athens and for 2 friends of mine that use the same ISP as me but live in different cities also accurately identified their locations too? If you bothered doing something as simple as read the Wikipedia article on Geolocation, you could answer this question yourself: Evidently you, and your friends have things like cookies, or some other helps that identify your location, which is why your addresses are close. -W-- http://mail.python.org/mailman/listinfo/python-list
Re: Dihedral
On Mon, 15 Jul 2013, Devyn Collier Johnson wrote: On 07/15/2013 08:36 AM, Steven D'Aprano wrote: On Mon, 15 Jul 2013 06:06:06 -0400, Devyn Collier Johnson wrote: On 07/14/2013 02:17 PM, 8 Dihedral wrote: [...] Do we want volunteers to speed up search operations in the string module in Python? It would be nice if someone could speed it up. Devyn, 8 Dihedral is our resident bot, not a human being. Nobody knows who controls it, and why they are running it, but we are pretty certain that it is a bot responding mechanically to keywords in people's posts. It's a very clever bot, but still a bot. About one post in four is meaningless jargon, the other three are relevant enough to fool people into thinking that maybe it is a human being. It had me fooled for a long time. Wow! Our mailing list has a pet bot. I bet other mailing lists are so jealous of us. Who ever created Dihedral is a genius! Artificial Intelligence developers put chatbots on mailing lists so that the program can learn. I use Python3 to program AI applications. If you see my Launchpad account, you will see my two AI projects - Neobot and Novabot. (https://launchpad.net/neobot Neo and Nova are still unstable) AI developers let their bots loose on the Internet to learn from people. Dihedral is learning from us. Dihedral only responses when it feels it has sufficient knowledge on the topic. Chatbots want to appear human. That is their goal. We should feel honored that Dihedral's botmaster feels that this mailinglist would benefit the development of Dihedral's knowledge. Are *you* a bot? ~_^ That post felt surprisingly like Dihedral... -W -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF-EBCDIC encoding?
On Mon, 15 Jul 2013, Kev Dwyer wrote: Joel Goldstick wrote: On Fri, Jul 12, 2013 at 3:12 PM, Skip Montanaro wrote: I can't help you. I'm astonished. Trying to imagine the work environment where this technology would be necessary http://www.iseriespython.com/app/ispMain.py/Start?job=Home Skip I remember the AS400 series.. although I never worked with one. What kind of business still use that stuff? Is it for large corporation accounting, MIS stuff? Some banks still run legacy systems on AS/400s, and I've seen them used for airline booking systems and retail POS. Sadly there are many larger corporations that have oodles of legacy code on the Mainframe. We run z/OS and IBM DB2 here. In my off time I fiddle around with Python in an attempt to make life more enjoyable - and one of these forays has led me to attempt to unpack some packed data. Which is also an interesting (if not terribly useful) project. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: Python 3 and web applications?
On Fri, 26 Jul 2013, Rui Maciel wrote: I'm currently learning Python, and I've been focusing on Python3. To try to kill two birds with one stone, I would also like to learn the basics of writing small web applications. These web applications don't need to do much more than provide an interface to a small database, and they may not even be required to be accessible outside of a LAN. Does anyone have any tips on what's the best way to start off this adventure? Take a look at the Python3 branch of Flask: https://github.com/mitsuhiko/flask.git And the werkzeug webserver: https://github.com/mitsuhiko/werkzeug.git If you download these you can install them with: python setup.py install (werkzeug first, then flask) Here's the most basic webserver you can create that way: from flask import Flask app = Flask(__name__) @app.route("/") def main(): return "Hello, Web!" if __name__ == "__main__": app.run() And yet flask is highly extensible with a lot of plugins. HTH, W -- http://mail.python.org/mailman/listinfo/python-list
Re: Async client for PostgreSQL?
On 8/31/12 7:17 PM, Laszlo Nagy wrote: Is there any extension for Python that can do async I/O for PostgreSQL with tornadoweb's ioloop? Something like: class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): pg_connection.(long_taking_query_sql,params,callback=self.on_query_opened) def on_query_opened(self, query): self.write(process_rows(query)) self.finish() What would be an alternative? The theoretical problem: suppose there are 100 clients (web browsers) connected to the server with keep alive connections. They are doing long-polls and they are also sending/receiving events (with short response times). Each web browser has an associated state stored on the server side, in the memory (as an object tree). The state is bound to the client with a session id. Most requests will have to be responded with small amounts of data, calculated from the session state, or queried from the database. Most database queries are simple, running for about 100msec. But a few of them will run for 1sec or more. Number of requests ending in database queries is relatively low (10/sec). Other requests can be responded must faster. but they are much more frequent (100/sec, that is. 1 request/sec/client). There is a big global cache full of (Python) objects. Their purpose is to reduce the number of database queries. These objects in the global cache are emitting events to other objects found in the client sessions. Generally, it is not possible to tell what request will end in a database query. Multi-threading is not an option because number of clients is too high (running 100 threads is not good). This is why I decided to use anyc I/O. Tornadoweb looks good for most requirements: async i/o, store session state in objects etc. The biggest problem is that psycopg is not compatible with this model. If I use blocking I/O calls inside a request handler, then they will block all other requests most of the time, resulting in slow response times. What would be a good solution for this? Thanks, Laszlo Hi does running on tornado imply that you would not consider twisted http://twistedmatrix.com ? If not, twisted has exactly this capability hiding long running queries on whatever db's behind deferToThread(). Brute force I would pack the db access into a twisted run web-service, forking work out in twisted either with deferToThread() or if you want to take advantage of using processes instead of threads thus being able to tap all cores, then have a look at ampoule at https://launchpad.net/ampoule - be aware though that ampoule has a 64k limit on what can be passed around. Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Async client for PostgreSQL?
On 9/1/12 9:28 AM, Laszlo Nagy wrote: Hi does running on tornado imply that you would not consider twisted http://twistedmatrix.com ? If not, twisted has exactly this capability hiding long running queries on whatever db's behind deferToThread(). All right, I was reading its documentation http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.threads.deferToThread.html It doesn't tell too much about it: "Run a function in a thread and return the result as a Deferred.". Run a function but in what thread? Does it create a new thread for every invocation? In that case, I don't want to use this. My example case: 10% from 100 requests/second deal with a database. But it does not mean that one db-related request will do a single db API call only. They will almost always do more: start transaction, parse and open query, fetch with cursor, close query, open another query etc. then commit transaction. 8 API calls to do a quick fetch + update (usually under 100msec, but it might be blocked by another transaction for a while...) So we are talking about 80 database API calls per seconds at least. It would be insane to initialize a new thread for each invocation. And wrapping these API calls into a single closure function is not useful either, because that function would not be able to safely access the state that is stored in the main thread. Unless you protet it with locks. But it is whole point of async I/O server: to avoid using slow locks, expensive threads and context switching. Maybe, deferToThread uses a thread pool? But it doesn't say much about it. (Am I reading the wrong documentation?) BTW I could try a version that uses a thread pool. It is sad, by the way. We have async I/O servers for Python that can be used for large number of clients, but most external modules/extensions do not support their I/O loops. Including the extension modules of the most popular databases. So yes, you can use Twisted or torandoweb until you do not want to call *some* API functions that are blocking. (By *some* I mean: much less blocking than non-blocking, but quite a few.) We also have synchronous Python servers, but we cannot get rid of the GIL, Python threads are expensive and slow, so they cannot be used for a large number of clients. And finally, we have messaging services/IPC like zeromq. They are probably the most expensive, but they scale very well. But you need more money to operate the underlying hardware. I'm starting to think that I did not get a quick answer because my use case (100 clients) fall into to the "heavy weight" category, and the solution is to invest more in the hardware. :-) Thanks, Laszlo Laszlo: Hmm, I was suggesting that you could replace the whole DB driver with a webservice implemented with twisted, if you rule out threads then with ampoule doing it with a process pool and consume this webservice with the tornado side asynchronously. production level example thread pool based DB API: Just to give you some ballpark figures, I'm running a game server with a daily peak of about 1500 parallel permanent connections and 50k games played every day (avg game duration 13min, peak request frequency close to 100req/sec) with a lot of statistics going into a MySQL DB on US$2k worth of hardware. Twisted as basis sitting atop FreeBSD, started the latest version in March, its running since then, no restarts, no reboots, no problems. production level example process pool based PDF production: Or for another implementation I'm running a webservice based PDF production (probably as blocking as services can come) for a Java based business app with twisted/ampoule, this is as stable as the game server. HTH, Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Problem on WIndows py3
On 9/4/12 9:49 AM, jimmyli1...@gmail.com wrote: I have a main program and a 3rd party module. Trying to import colorama, where colorama is a folder with files in it, returns an ImportError: No module named colorama. How should I import folders? Do you have a (empty) __init__.py file present in this particular directory? Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Algorithms using Python?
On Fri, 21 Sep 2012, Dennis Lee Bieber wrote: On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe declaimed the following in gmane.comp.python.general: Is there a good book on foundational as well as advanced algorithms using Python? Depends on what you mean by "foundational"... Since Python has dynamic lists and dictionaries, I suspect you won't find any textbook focusing on linked-list or hashed lookup algorithms using Python. You can probably implement them, but they're not going to be very efficient. (And never "remove" an element from the linked-list implementation because Python would shift all the other elements, hence your "links" become invalid). It's quite inefficient, but it would be fairly trivial to create a LL implementation like this: class Link: def __init__(self): self.next = None self.value = None class LinkedList: def __init__(self): self.head = None def add(self, value): node = Link() node.value = value self.append(node) def append(self, node): # Write some code It's fairly easy to use reference types as one would use pointers in . But it might actually require understanding pointers and such in the first place... I'm not really aware of any algorithm that's impossible/harder to implement in Python - Python just makes most things a lot easier so you never have to deal with the lower level algorithms. Which makes *me* happy :) -Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: One of my joomla webpages has been hacked. Please help.
On Sat, 22 Sep 2012, Νίκος Γκρεεκ wrote: Okey i'll ask this to the officila joomla forum, one last thing though. Is there a way to somehow embed(or utilize) python code, for example my python counter code script you have seen last week inside my Joomla/WordPress cms sites? For example: http://superhost.gr/ is my main website utilizing python counter script. http://superhost.gr/html/?show=log is my own way(i prefer it over awstats - don't ask why) for viewing my visitors. in my other sites which are CMS sites, like http://varsa.gr and http://thessalonik.wordpress.com/ is there a possible way to embed(if thats the term) my python counter script there too? so i can keep track of visitors info for each page i have there? Sure, but why create a counter (ugh) when you can use something like Google Analytics for free and get much more interesting and useful metrics? -Wayne-- http://mail.python.org/mailman/listinfo/python-list
Re: One of my joomla webpages has been hacked. Please help.
On Sun, 23 Sep 2012, Dwight Hutto wrote: We're the borg. Oh, so you *are* a robot. That does explain your posts ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Who's laughing at my responses, and who's not?
On Tue, 25 Sep 2012, Dwight Hutto wrote: It sounds pretentious, but over the past several days, I've been slammed on every post almost. All because of an argument over me not posting a little context in a conversation, that seemed short and chatty. Your being slammed has nothing to do with your lack of context, and everything to do with the fact that the way you responded to it was through ad hominem attacks, and the fact that most of your responses read like a transcript from kids I remember in junior high. It's annoying to most people - the same way pretentious teenage nitwits annoy most people who are interested in talking about Python code, and not who did what to who. -Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Article on the future of Python
On 9/27/2012 9:05 PM, Jason Friedman wrote: Fair enough, but it's the M in the LAMP stack I object to. I'd much rather have P. +1 I know this isn't the list for database discussions, but I've never gotten a decent answer. I don't know much about either, so I'm kind of curious why postgresql over mysql? I'll try not to get too OT... I had previously just used MySQL (and SQLite), but have been reaading some PostGres stuff lately. I took a look around and basically... you and I won't know or notice a difference probably ever. There's all sorts of crazy tweaks you can get for reliability, speed, and backups depending on what you use. So the only advice I can give on that is just learn to use both. And even better yet, just use SQLAlchemy if you're ever touching a database from Python because it handles all the mucky SQL for you - you just define the ORM. (Hey look! A Python module!) My $0.02 -Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: print or write on a text file ?
On Fri, 28 Sep 2012, Franck Ditter wrote: Hi ! Here is Python 3.3 Is it better in any way to use print(x,x,x,file='out') or out.write(x) ? Any reason to prefer any of them ? There should be a printlines, like readlines ? Thanks, The print function automatically appends newlines to the end of what it prints. So if you had text = 'Hello!' and you did: print(text, file=outfile) then outfile would contain 'Hello!\n' In contrast, outfile.write(text) would only write 'Hello!'. No newline. There are lots of other handy things you can do with the print function: values = [1,2,3,4] print(*values, sep='\n', file=outfile) I'll leave it to you to experiment. HTH, Wayne -- http://mail.python.org/mailman/listinfo/python-list
Posix call (execve) breaks mercurial?
So... this is certainly the deepest I've got to dig into any source code. I'm experimenting with Review Board for code reviews, and trying to get it set up/working here at work. When using post-review, however, I started getting issues with untrusted users - even though they were set to trusted in my ~/.hgrc and things worked fine otherwise. So here's where things got weird. I could call `subprocess.check_output(['hg', 'root'])`, and things worked just fine. But when I added the env parameter, I got the untrusted issues. So if I did: import os, subprocess # Works just fine subprocess.check_output(['hg', 'root']) # Gives untrusted issues subprocess.check_output(['hg', 'root'], env=os.environ) Long story short, I dug around the source code and ended up at the POSIX execve function. I've been reading the manpages, but nothing seems to pop out at me as "hey, this should/shouldn't work!". Does anyone know what's going on here, or where I should go for more help? Thanks, Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Posix call (execve) breaks mercurial?
On Thu, 11 Oct 2012, Wayne Werner wrote: So here's where things got weird. I could call `subprocess.check_output(['hg', 'root'])`, and things worked just fine. But when I added the env parameter, I got the untrusted issues. So if I did: import os, subprocess # Works just fine subprocess.check_output(['hg', 'root']) # Gives untrusted issues subprocess.check_output(['hg', 'root'], env=os.environ) So... curiouser and curiouser - it looks like it's not *actually* execve's fault after all. I just compiled the code from the man page, tweaked it to run 'hg root', and passed it a new environment. No problems. Well, then I manually called the posix one from Python and thing worked fine. *Then* I actually tried the above code, and *it* worked fine. However I *still* get problems with the post-review code. So it looks like when I get back to work on Monday I'll be looking to see what the difference in environment is there. -Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Why Doesn't This MySQL Statement Execute?
On Tue, 18 Dec 2012, Tom Borkin wrote: Hi; I have this test code: if i_id == "1186": sql = 'insert into interactions values(Null, %s, "Call Back", "%s")' % (i_id, date_plus_2) cursor.execute(sql) db.commit() print sql It prints the sql statement, but it doesn't execute. If I copy and paste the sql into the mysql command line it does execute without warnings or errors. What gives? Does date_plus_2 contain "Robert"); DROP TABLE interactions; -- By any chance? -W-- http://mail.python.org/mailman/listinfo/python-list
Re: context aware execution
On Thu, 20 Dec 2012, Chris Angelico wrote: On Thu, Dec 20, 2012 at 2:57 AM, Bart Thate wrote: I want in a function or method determine the context of my caller and adapt the functionality accordingly. First off, please don't! Your code will be *extremely* confusing. Usually, the best way to adapt to your caller's environment is to be passed a parameter that specifies the change. Or assume that the caller is smart enough to determine which one of the functions to call, and provide them, with good names. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
On Wed, 2 Jan 2013, Michael Torrie wrote: On 01/01/2013 11:43 AM, Mitya Sirenef wrote: Therefore, deleting 3 WORDs is 3daW (mnemonic: del a WORD 3 times). Interesting. I typically use just d3w. 3daW seems to delete 3 lines for me, the same result as d3. Another favorite command is d or c followed by a number and then the right arrow key, for manipulating letters instead of words. Right arrow and not l? Surely you jest! ;) In any case, I can be way more productive with just a few commands (maybe 3 or 4 commands or concepts) in Vim than in almost any GUI editor. In my experience, Vim users almost always find this to be true for them as well. Vim really hits the sweet spot for productivity and usability. The only thing about Vim that I find clunky is how code folding macros work, and also code completion hacks (which I have never needed anyway). Yep. That's how I feel. I had used ViEmu in Visual Studio for coding in .NET at work - but I found that the buffers & macros were more powerful. So now I do most of my programming in Vim, and only head to VS if I need autocomplete or some of it's auto-generation tools. (I'm even writing this email in Vim as my external editor from alpine ;) -W -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
On Tue, 1 Jan 2013, Mitya Sirenef wrote: On 01/01/2013 02:02 PM, Roy Smith wrote: That's true with Vim, as well, especially when I'm making a custom mapping and I can NEVER remember what some combination does, even though if I actually needed to use it, it pops right out, so to find out, I have to try it and then I say, "of course, dammit, I use this command 50 times every single day!"; so it's a curious case of one-directional memory. I've found writing macros helps me a lot in this regard. I do qaq"aP fairly frequently. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
On Tue, 1 Jan 2013, Ramchandra Apte wrote: On Friday, 28 December 2012 01:31:16 UTC+5:30, mogul wrote: 'Aloha! I'm new to python, got 10-20 years perl and C experience, all gained on unix alike machines hacking happily in vi, and later on in vim. Now it's python, and currently mainly on my kubuntu desktop. Do I really need a real IDE, as the windows guys around me say I do, or will vim, git, make and other standalone tools make it the next 20 years too for me? Oh, by the way, after 7 days I'm completely in love with this python thing. I should have made the switch much earlier! /mogul %-) I use Eclipse only because it has PEP 8 and Pylint integration. Ezio Melotti, core Python developer, said in personal chat, that he uses Kate. IDEs aren't that useful when coding in Python. I concur. I think it's because with a language that has 43(?) keywords and I believe it's 12 different statement types, you can easily fit it all in your head. What you can't fit in your head is found in the docstrings of whatever you're using. Give me an interactive interpreter, vim, and a web browser, and I'm more than fine. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
On Fri, 4 Jan 2013, Roy Smith wrote: In article , Cameron Simpson wrote: On 01/04/13 01:34, Anssi Saari wrote: | Just curious since I read the same thing in a programming book recently | (21st century C). So what's the greatness that terminal multiplexors | offer over tabbed terminals? Especially for software development? There's no doubt that you need access to multiple terminal sessions. Whether you achieve that with multiple terminal windows on your desktop, multiple desktops, tabbed terminals, or something like screen is entirely personal preference. +1 I use a tiling WM (awesomewm), but I still find that tmux has its place. Usually I'll have a terminal per box that I'm working on, and a tmux session within that. This allows me to detach and reattach from any system I'm on. In addition, if I lose my connection, I don't have to figure out which processes I had in bg. There's also the neat ability (at least with tmux - I haven't used screen for a while now) to work across sessions - so I might have a personal session (with things like alpine and irssi), a dev session (with Vim, a python prompt, and a shell) - and I can either keep them separate if I need to focus, or join the windows if I need some help. One thing that I've noticed that tmux does poorly is handle the mouse for selecting. And as I haven't yet written or found a cross-platform/machine clipboard manager, using the tmux copy or xclip doesn't really help that much :P I'd say the main benefit (aside from tiling) is the attach/detach. Unless your machine powers off or you kill tmux/screen, your sessions will stay around. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On Thu, 24 Jan 2013, Tim Chase wrote: On 01/24/13 13:34, Leonard, Arah wrote: All true (especially the holy wars bit!). OP didn't (as far as I can see) even say which OS he is using. Anyway, my suggestion is generally that people use the editor with which they are already comfortable. Sound advice. [snip] Whatever works is what works. It's just a text file after all. So even "ed" or "edlin" or even "cat" would do ;-) ? -tkc ? wq ed *is* the standard editor. Also, I see what you did there ;) -w . wq -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel programming in Python
For such tasks my choice would be twisted combined with ampoule. Let's you spread out work to whatever amount of processes you desire, maxing out whatever iron you're sitting on.. HTH, Werner http://twistedmatrix.com/trac/ https://launchpad.net/ampoule On 29.05.2012 16:43, Jabba Laci wrote: Hehe, I just asked this question a few days ago but I didn't become much cleverer: http://www.gossamer-threads.com/lists/python/python/985701 Best, Laszlo On Thu, May 10, 2012 at 2:14 PM, Jabba Laci wrote: Hi, I would like to do some parallel programming with Python but I don't know how to start. There are several ways to go but I don't know what the differences are between them: threads, multiprocessing, gevent, etc. I want to use a single machine with several cores. I want to solve problems like this: iterate over a loop (with millions of steps) and do some work at each step. The steps are independent, so here I would like to process several steps in parallel. I want to store the results in a global list (which should be "synchronised"). Typical use case: crawl webpages, extract images and collect the images in a list. What's the best way? Thanks, Laszlo <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Does anyone know of a python tapi module
On 7/1/11 11:15 AM, Alister Ware wrote: The subject probably say is all but to elaborate. I am looking for a way to communicate with a tapi driver for a PBX so I can experiment with creating some CTI (Computer Telephony Integration) software. I used TAPI since its inception for quite a few projects, but am not aware of anything pythonic. Attempting to cough up an interface layer I would resort to using Chris Sells tfx wrapper fro TAPI, which helps a lot keeping things in check and becoming overly complex. HTH, Werner http://books.google.com/books?id=3M_mIvtdGqUC&pg=PA82&lpg=PA82&dq=chris+sell+tfx&source=bl&ots=5UhAxbFTym&sig=7hRn0oUbyZsm_yyDvASKD-AT1jo&hl=en&ei=w2UOTsPlBJOisAP57JyrDg&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBkQ6AEwAA -- http://mail.python.org/mailman/listinfo/python-list
Re: I am not able to open IDLE in python on Vista.
Ever tried to run it as Administrator (right click, Run as Administrator...) Werner Am 01.03.2011 17:12, schrieb Jayneil Dalal: This is the error message I get when I try to run Pyhon on Vista: unable to create user config directory C:\Users\Jayneil\.idlerc Check path and permissions. Exiting! So please help me out!. Thank you. <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Python CPU
You probably heard of the infamous FORTH chips like the Harris RTX2000, or ShhBoom, which implemented a stack oriented very low power design before there were FPGAs in silicon. To my knowledge the RTX2000 is still used for space hardened application and if I search long enough I might fine the one I had sitting in my cellar. The chip was at that time so insanely fast that it could produce video signals with FORTH programs driving the IO pins. Chuck Moore, father of FORTH developed the chip on silicon in FORTH itself. Due to the fact, that the instruction sets of a FORTH machine, being a very general stack based von Neumann system, I believe that starting with an RTX2000 (which should be available in VHDL) one could quite fast be at a point where things make sense, meaning not going for the 'fastest' ever CPU but for the advantage of having a decent CPU programmable in Python sitting on a chip with a lot of hardware available. Another thing worth to mention in this context is for sure the work available on http://www.myhdl.org/doku.php. Werner On 4/3/11 3:46 AM, Dan Stromberg wrote: On Sat, Apr 2, 2011 at 5:10 PM, Gregory Ewing mailto:greg.ew...@canterbury.ac.nz>> wrote: Brad wrote: I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL or Verilog? Not that I know of. I've had thoughts about designing one, just for the exercise. It's doubtful whether such a thing would ever be of practical use. Without as much money as Intel has to throw at CPU development, it's likely that a Python chip would always be slower and more expensive than an off-the-shelf CPU running a tightly-coded interpreter. It could be fun to speculate on what a Python CPU might look like, though. One with the time and inclination could probably do a Python VM in an FPGA, no? Though last I heard, FPGA's weren't expected to increase in performance as fast as general-purpose CPU's. -- http://mail.python.org/mailman/listinfo/python-list
Re: nntplib: abstraction of threads
Rakesh schrieb: > What I want is to *group the messages belonging to each thread* . Hello Why not sort with Message-ID and References? Attention - it is a Newbie-Solution. import nntplib hamster = nntplib.NNTP('127.0.0.1', 119, 'user', 'pass') resp, count, first, last, name = hamster.group('comp.lang.python') resp, items = hamster.xover(first,last) start_dic = {} re_dic = {} numb = 1 for id,subject,author,date,message_id,references,size,lines in items: if 'Re:' not in subject: start_dic[subject] = (author, message_id) else: re_dic[numb] = (subject, author, references) numb += 1 resp = hamster.quit() for a in start_dic: print a print start_dic[a][0] for b in re_dic: if start_dic[a][1] in re_dic[b][2]: print '|' print ' ->', re_dic[b][0] print ' ', re_dic[b][1] print -- Werner Amann -- http://mail.python.org/mailman/listinfo/python-list
PythonWin, AutoDoc and german keyboards...
Hallo, PythonWin is really great and like to use it all the time. But, I use to an us keyboard and get support strings (.__doc__). On the other side, most of my colleges use German keyboards and the do not get these strings at all. We are using: - Python 2.4 - PyWin32 203 Here is an example: --- When we enter range with us keyboard we get: >>> range( [range([start,] stop[, step]) -> list of integers] When we do this with German keyboard we get... nothing, except we enter: >>> range) [range([start,] stop[, step]) -> list of integers] You see, if we press ")" on German KB, which is "(" on us KB we get the help... BTW: Changes to Python24\Lib\site-packages\pythonwin\pywin\default.cfg didn't help. Is this a known issue? And is there a work around? Or do we have to take an other IDE like SPE? Thank you in advance Werner Merkl -- http://mail.python.org/mailman/listinfo/python-list
Try to install PythonCard-0.8.1 on Python2.4
Hi, I like to switch from Python 2.3.4 to 2.4. So I tried to reinstall all apps I need. Most works fine When I start PythonCard I get following error: --- Setup PythonCard-0.8.1: PythonCard-0.8.1.win32.exe - Application Error --- The instruction at "0x77f69ecd" referenced memory at "0x0010". The memory could not be "written". Click on OK to terminate the program Click on CANCEL to debug the program --- OK Cancel --- Anybody any idea? BTW: WxPython is not available for Python2.4 and I didn't manage to compile it... Could this be the reason? Thanks in advance Werner -- http://mail.python.org/mailman/listinfo/python-list
Has Python 2.4.1 changed implementation for __init__.py???
Hallo, I just downloaded http://www.python.org/pypi/xexpr/0.02, installed if (python setup.py install) and tried the example in the README file. Than I got following error: AttributeError: 'module' object has no attribute 'Read' This is same behavior for all module using empty __init__.pr files, like venster, Pyrex or libxmlmods... Is there a change in the implementation, so that every module needs an explicit list for exchanged modules? Or is there a switch or an environment variable to change? Thanks a lot Werner EXAMPLE Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import xexpr >>> example = 'Blah' >>> xexpr.Read.to_xexpr(example) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'Read' >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Has Python 2.4.1 changed implementation for __init__.py???
Fredrik Lundh wrote: Werner Merkl wrote: I just downloaded http://www.python.org/pypi/xexpr/0.02, installed if (python setup.py install) and tried the example in the README file. Than I got following error: AttributeError: 'module' object has no attribute 'Read' This is same behavior for all module using empty __init__.pr files, like venster, Pyrex or libxmlmods... if "xexpr" is a package with an empty __init__.py file, the behaviour you're seeing is the expected behaviour. importing a toplevel module doesn't auto- matically import any submodules. Oh, I see. I have to write: import xexpr.Read Now it works... Is there a change in the implementation, so that every module needs an explicit list for exchanged modules? what's an "exchanged module"? Oops! This should say "every module"... Thanx a lot Werner EXAMPLE Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. import xexpr example = 'Blah' xexpr.Read.to_xexpr(example) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'Read' does it work better if you type import xexpr.Read before you call the to_xexpr function? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Scalability TCP Server + Background Game
On Sat, 18 Jan 2014 13:19:24 +, Mark Lawrence wrote: > On 18/01/2014 12:40, phi...@gmail.com wrote: > > [snip the stuff I can't help with] > > Here's the link you need to sort the problem with double spacing from > google groups https://wiki.python.org/moin/GoogleGroupsPython Thanks for the link. I've, hopefully, solved the issue by switching to Pan instead of using google groups. :) Regards, Philip -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Scalability TCP Server + Background Game
> Looking a lot more normal and readable now. Thanks! > > Note that some people have experienced odd issues with Pan, possibly > relating to having multiple instances running simultaneously. You may > want to take care not to let it open up a duplicate copy of itself. > > ChrisA Thanks for the heads up. It is buggy to say the least. Any other program on linux you may suggest? Regards, Philip -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP8 79 char max
On Wed, 31 Jul 2013, Joshua Landau wrote: To explain, I tend to take the "HTML" form of alignment by wrapping: open stuff stuff stuff close to open stuff stuff stuff close Depending on how much 'stuff' I have, I, for one, prefer a third: open stuff stuff stuff close Which then makes it 1) fairly easy to read, 2) fairly easy to extend. Of course it could just be that I'm used to that style - our brains are wired weird. -W-- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On Thu, 1 Aug 2013, Gilles wrote: On Wed, 24 Jul 2013 10:38:52 -0400, Kevin Walzer wrote: Thanks. hMailServer was one of the apps I checked, and I was just making sure there weren't something simpler, considering my needs, ideally something like Mongoose MTA. Have you checked Kenneth Rietz's inbox.py[1]? It's fairly simple to use/extend and might fit your modest needs. -W [1]:https://crate.io/packages/inbox/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python 'enable' poke and hope programming?
On Thu, 1 Aug 2013, CM wrote: (My subject line is meant to be tongue and cheek inflammatory) I've been thinking about why programming for me often feels like ice skating uphill. I think part of the problem, maybe the biggest part, is what now strikes me as a Very Bad Habit, which is "poke and hope" (trial and error) programming (of several names this page provided, I kind of like that one): http://en.wikipedia.org/wiki/Programming_by_permutation It seems that if I can make a change to the code and then immediately test it by running the Python interpreter and finding out, in a few seconds, if it worked, I am going to be *much* more likely to use this trial-and-error approach than if I had to use a compiled language, since compiling takes so long. E.g. "Oh, that doesn't work? Maybe if I add this...no. OK, what about if I increment that? No...OK, wait, maybe this...AH! That worked." (obviously it is not quite that uninformed all the time). Instead, with a compiled language, because of the pain of having to wait for the newest version to compile, one would be encouraged to get the mechanism of how something works *clear* and robustly represented in one's mind (or on scrap paper/notes document) prior to testing through compiling and running. Basically this amounts to: with an interpreted language (so of course this is not really just about Python--I just think in terms of Python), it's easier to be mentally lazy. But, ironically, being lazy winds up creating *way* more work ultimately, since one winds up programming in this terribly inefficient way, and progress proceeds at an, at times, evolutionary (slow!) pace. And of course I am not really blaming it on Python or any interpreted language; I am blaming it fully on my own lame habits and attitude. I'm sick of this in my own work, and want to avoid this trap as much as I can from now on. Thoughts? I see that many others have had thoughts already - but rather than take the time to read their responses and either find out that they said the same thing (oops, sorry!) or become influenced by their arguments, I feel like I should respond to this with a clean slate. I don't think that Python enables the "poke and hope" style programming (I like the name!) any more than a compiled language does - if you're doing it right. Example: My brother had a kid in his C++ class that would go about randomly flipping >, <, <=, >= signs until he got the behavior that he wanted. There was no mental effort of thinking about the problem or applying the scientific method - i.e. form a hypothesis, test the hypothesis, check results. My experience is that people who go throughout their programming careers without this attitude will do it whether it requires several seconds (or minutes) of compile time or not. Whether or not it's a conscious choice I don't know - at least in your case you seem to desire to make a conscious choice in the direction of "wait a minute, this is a stupid way to program". Though "poke and hope" is headed in the right direction, I think it's a bit naive and misses the very essential nature of the better (best?) method - formulation of a /real/ hypothesis. For instance "I think my program will work" is a hypothesis of exactly the same quality of, "When I turn on my water faucet, it will rain." Of course the smaller the application, the more valid the original hypothesis. For instance, the "poke and hope" programmer might write this program: x = 3 if x > 3: print "x is less than 3" else: print "x is greater than 3" And then of course make the weak hypothesis "if I change my > to < then maybe my program will work" - or "if I change my x to 5 then maybe my program will work". The problem is that these are really just random guesses - flips of the coin that eventually might produce a correct result - but only because of the monkeys[1]. What you really want is to actually understand cause and effect at a more fundamental level (in programming) than what you may currently enjoy. And this is in fact something that, while makes it easier for the "poke and hope", also provides a much more enjoyable laboratory experience for the initiated. And when you combine that with the REPL (interactive interpreter) you get an embarassingly powerful laboratory in which to experiment to your heart's delight. For instance, say you want to really understand the previous example. You could do something like so: >>> x = 3 >>> x > 3 False >>> x < 3 False >>> x >= 3 True >>> x <= 3 True >>> x == 3 True And *this* type of "poke and hope" *is* actually valuable. This is where understanding is formed, and high-quality developers are forged. At your fingertips you begin to see "A hah! so *that's what this does!" You are free to explore and play and understand the rules of the system. And you can build on the previous experiments: >>> if x > 3: ... print("
Re: Logging help
On Thu, 1 Aug 2013, Joseph L. Casale wrote: I have a couple handlers applied to a logger for a file and console destination. Default levels have been set for each, INFO+ to console and anything to file. How does one prevent logging.exception from going to a specific handler when it falls within the desired levels? There is probably a better way, I'm not too familiar with the more advanced logging, but off the top of my head I'd suggest subclassing the Handler classes that you're interested in and overriding the Handle method (I think - you can check the source to be sure) and if the type of message is exception then just skip handling it. Alternatively, you could simply create a different logger, e.g. exc_logger = logging.getLogger('mything.exceptions') And use that to log exceptions. Oh hai - as I was reading the documentation, look what I found: http://docs.python.org/2/library/logging.html#filter Methinks that should do exactly what you want. HTH, W -- http://mail.python.org/mailman/listinfo/python-list
Re: Python performance
On Fri, 2 Aug 2013, Schneider wrote: Hi list, I have to write a small SMTP-Relay script (+ some statistic infos) and I'm wondering, if this can be done in python (in terms of performance, of course not in terms of possibility ;) ). It has to handle around 2000 mails per hour for at least 8hours a day (which does not mean, that it is allowed not to respond the rest of the day. Can this be done? or should I better use some other programming language? My second choice would be erlang. Check out Kenneth Rietz's inbox.py[1] "It's quite quick. One instance should handle over one thousand emails per second." So it should be able to handle your hour's load in oh, say 2 seconds? ;) HTH, W [1]: https://crate.io/packages/inbox/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving to Python for web
On Thu, 29 Aug 2013, Andreas Ecaz wrote: I've decided to go with Flask! It's now running on UWSGI with NGINX. Hopefully I can get some stuff done :) @Chris “Kwpolska” Warrick I just don't like the big frameworks, for me there is too much magic going on. I'm a huge fan of Flask - I also find that when you start to learn more and more about Flask you can see how Django would be super useful, if you need all the bells and whistles. -W-- https://mail.python.org/mailman/listinfo/python-list
Re: print function and unwanted trailing space
On Sat, 31 Aug 2013, candide wrote: # - for i in range(5): print(i, end=' ') # <- The last ' ' is unwanted print() # - Then why not define end='' instead? -W -- https://mail.python.org/mailman/listinfo/python-list
Re: Language design
On Tue, 10 Sep 2013, Ben Finney wrote: The sooner we replace the erroneous “text is ASCII” in the common wisdom with “text is Unicode”, the better. I'd actually argue that it's better to replace the common wisdom with "text is binary data, and we should normally look at that text through Unicode eyes". A little less catchy, but more accurate ;) -W-- https://mail.python.org/mailman/listinfo/python-list
Re: better and user friendly IDE recommended?
On Thu, 12 Sep 2013, Ben Finney wrote: Better to learn these once, in a single powerful tool that can be maintained independent of any one vendor for as long as its community is interested. And if you're a developer, even a community of one is enough ;) -W -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Tuesday, October 1, 2013 5:06:38 PM UTC-5, Ben Finney wrote: > This is an unmoderated forum, so we have occasional spates of persistent > > nuisances, and those who respond with the maturity level and impulse > > control of an average six-year-old. Hey! That's so degrading! I don't know many six-year-olds (and certainly not mine, but maybe they're just not average) who would continue to respond in the same fashion that the OP of *this* thread did! ;-) -W -- https://mail.python.org/mailman/listinfo/python-list
Re: JUST GOT HACKED
On Wednesday, October 2, 2013 5:43:32 AM UTC-5, Ferrous Cranus wrote: > > I only re-ask the same thing if: > > > 1. Di not understood what was provided or proposed to me as being a solution > > 2. Still feel that that the solution provided to me doesn't meet my > needs and should have been re-written in a different way. Nevertheless > we are all improving, especially the newbies, by seeing alternative way, > best methods and wise practices of writing code for the specific problem > and pick the one that does the job best. > If you feel that the provided solution doesn't meet your needs then the *most likely* answer is that you have asked the wrong question. Rather than, say, posting a new thread (unless your new question is clearly different and mostly unrelated), the appropriate course of action is to say something like, "Hey, apparently I'm asking the wrong question, because all these answers are about frobnosticating, but I really wanted to foo the baz." If you don't acknowledge that you goofed up, you come across as arrogant or ignorant (or both). -W -- https://mail.python.org/mailman/listinfo/python-list
Re: Script to extract text from PDF files
On Tuesday, September 25, 2007 at 1:41:56 PM UTC-4, brad wrote: > I have a very crude Python script that extracts text from some (and I > emphasize some) PDF documents. On many PDF docs, I cannot extract text, > but this is because I'm doing something wrong. The PDF spec is large and > complex and there are various ways in which to store and encode text. I > wanted to post here and ask if anyone is interested in helping make the > script better which means it should accurately extract text from most > any pdf file... not just some. > > I know the topic of reading/extracting the text from a PDF document > natively in Python comes up every now and then on comp.lang.python... > I've posted about it in the past myself. After searching for other > solutions, I've resorted to attempting this on my own in my spare time. > Using apps external to Python (pdftotext, etc.) is not really an option > for me. If someone knows of a free native Python app that does this now, > let me know and I'll use that instead! > > So, if other more experienced programmer are interested in helping make > the script better, please let me know. I can host a website and the > latest revision and do all of the grunt work. > > Thanks, > > Brad As mentioned before, extracting plain text from a PDF document can be hit or miss. I have tried all the following applications (free/open source) on Arch Linux. Note, I would execute the commands with subprocess and capture stdout or read plain text file created by the application. * textract (uses pdftotext) - https://github.com/deanmalmgren/textract * pdftotext - http://poppler.freedesktop.org/ - cmd: pdftotext -layout "/path/to/document.pdf" - - cmd: pdftotext "/path/to/document.pdf" - * Calibre - http://calibre-ebook.com/ - cmd: ebook-convert "/path/to/document.pdf" "/path/to/plain.txt" --no-chapters-in-toc * AbiWord - http://www.abiword.org/ - cmd: abiword --to-name=fd://1 --to-TXT "/path/to/document.pdf" * Apache Tika - https://tika.apache.org/ - cmd: "/usr/bin/java" -jar "/path/to/standalone/tika-app-1.10.jar" --text-main "/path/to/document.pdf" For my application, I saw the best results using Apache Tika. However, I do still encounter strange encoding or extraction issues, e.g. S P A C E D O U T H E A D E R S" and "\nBroken \nHeader\n". I ended up writing a lot of repairing/cleaning methods. I welcome an improved solution that has some intelligence like comparing the extract plain text order to a snapshot of the pdf page using OCR. -- https://mail.python.org/mailman/listinfo/python-list
Re: Jinja2 installation help
On Fri, 8 Feb 2013, Robert Iulian wrote: Hello, I recently started learning Python. Just finished learning the basis of it, and now I think I'm ready to start working on a simple website but I am having some difficulties installing Jinja2. Can anyone post a dummy guide on how to install it, and what to do step by step? I am using the lastest Python version 3.3 . Do you have easy_install or pip installed? If you do, $ pip install jinja2 And that's it! HTH, Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: "Daemonizing" an application.
Hi Might be an overkill, but have a look at twisted, http://www.twistedmatrix.com I usually use the spread package for structured communication between partners via localhost What are the best practices to do this ? Examples in a well known Pyhon app I could hack ? Is it possible with standard packages only ? Have fun, Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted or Tornado?
Hi On 3/1/13 1:39 AM, Michael Torrie wrote: On 02/28/2013 05:28 PM, Jake Angulo wrote: My requirements for this framework in descending order: 1) Easy to use API 2) Widely available documentation / Examples / Community contributions 3) Feature-wise - kinda most that you commonly need is there I'm happy with twisted programming browser based multi-player games for several years now. I wouldn't say that the learning curve was steep, rather the opposite, but the gain from a clean async programming model as it is implemented in twisted really makes the difference for me, not only in writing games, but even more in maintaining them long term. It's also interesting to see, that this clean async model of twisted and its host of already provided protocols allowed me to implement solutions in notoriously problematic areas like overall stability, fault tolerance, load induced behavior, server analysis, multicore/multimachine capabilities and hot deployment with ease. Cheers, Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: "monty" < "python"
On Thu, 21 Mar 2013, Roy Smith wrote: In article , Terry Reedy wrote: On 3/20/2013 10:03 AM, franzferdinand wrote: Ok, thanks everybody! Threads are like the Sorcerer's Apprentice. You can start 'em, but you cannot stop 'em ;-) Of course you can stop threads. Just call _exit(). No more threads! Thank you for making me laugh this morning - I found that extremely amusing. -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with sockets and threads
On Thu, 11 Apr 2013, Dexter Deejay wrote: When i try to run this code and to connect to server (server is written in java that part of code is ok) everything stalls. Thread that i created here occupies processor all the time and GUI freezes. It's supposed to be waiting for message from server. (asynchronous one) Is there something that i did wrong here, or is there better way to do this? from tkinter import * from threading import * Everything I've read or used suggests to me that threading+tkinter is a dangerous combination. Mainly because tkinter already has an event loop, so when you start mixing threads things tend to go sideways. Instead what you'll want to do is put processing in the .after or .after_idle callbacks - just make sure that whatever is doing is quick (or can do a portion of the activity quickly). HTH, -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with sockets and threads
On Thu, 11 Apr 2013, Dexter Deejay wrote: Yeah, that seems to be problem. Waiting for message is in theory infinite. But why doesn't this separate thread leave processor while it is sleeping? As far as I've been able to tell? Magic ;) But I haven't really dug into it. If you're really doing some waiting stuff you might want to look into some other type of message passing mechanism, e.g. launch a subprocess to do ths listening and then writing to a file and checking that from within Tkinter. I expect there are other possibilities that more advanced people may be able to recommend and are probably better. But that seems like it would work. HTH, -W -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic forms generation
On Tue, 16 Apr 2013, andrea crotti wrote: This is not really scalable, and we want to make the whole thing more generic. So ideally there could be a DSL (YAML or something else) that we could define to then generate the forms, but the problem is that I'm quite sure that this DSL would soon become too complex and inadeguate, so I'm not sure if it's worth since noone should write forms by hands anyway. Between the things that we should be able to do there are: - dependent fields - validation (both server and client side, better if client-side auto-generated) - following DRY as much as possible Any suggestions of possible designs or things I can look at? I would highly recommend a look at Flask, and Flask-WTF in particular. It's fairly easy to write forms, and with only a bit of setup you can end out with some fairly generic systems. I don't think that by default it does any client-side validation generation, but as the HTML for the forms are completely generated, extending the form and adding validation logic to the output wouldn't be too difficult. Example: # form.py from flask.ext.wtf import Form, TextField, Required class MyBasicForm(Form): some_text = TextField("Put some text here:", validators=[Required()]) # View/HTML {% extends 'base.html' %} {{ form.some_text.label() }}{{ form.some_text(size=40) }} # Server code @app.route("/basic_form", methods=['GET', 'POST']) def basic(): form = MyBasicForm() if form.validate_on_submit(): do_the_needful(form.some_text.data) return redirect(url_for('main')) return render_template('basic_form.html', form=form) Obviously a really basic example. Check out Flask here: http://flask.pocoo.org/ And Flask WTF here: http://pythonhosted.org/Flask-WTF/ HTH, Wayne-- http://mail.python.org/mailman/listinfo/python-list
Re: anyone know pandas ? Don't understand error: NotImplementedError...
On Wed, 17 Apr 2013, someone wrote: File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in rule_code raise NotImplementedError NotImplementedError Can anyone tell why this error appears and how to fix it? I don't know anything about pandas, but my recommendation? $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py (or nano or emacs - whatever editor you're comfortable with). Go to line 214, and take a look-see at what you find. My guess is it will be something like: def rule_code(): raise NotImplementedError() Which is terribly unhelpful. HTH, Wayne -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding NaN in JSON
On Wed, 17 Apr 2013, Miki Tebeka wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. Why not use `null` instead? It seems to be semantically more similar... -W -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding NaN in JSON
On Sat, 20 Apr 2013, Chris “Kwpolska” Warrick wrote: On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards wrote: The OP asked for a string, and I thought you were proposing the string 'null'. If one is to use a string, then 'NaN' makes the most sense, since it can be converted back into a floating point NaN object. I infer that you were proposing a JSON null value and not the string 'null'? Not me, Wayne Werner proposed to use the JSON null value. I parsed the backticks (`) used by him as a way to delimit it from text and not as a string. That was, in fact, my intention. Though it seems to me that you'll have to suffer between some sort of ambiguity - in Chrome, at least, `Number(null)` evaluates to `0` instead of NaN. But `Number('Whatever')` evaluates to NaN. However, a JSON parser obviously wouldn't be able to make the semantic distinction, so I think you'll be left with whichever API makes the most sense to you: NaN maps to null or NaN maps to "NaN" (or any other string, really) Obviously you're not limited to these particular choices, but they're probably the easiest to implement and communicate. HTH, -W-- http://mail.python.org/mailman/listinfo/python-list
Re: Windows PE and Python 2.6 (Side-by-Side error)
Martin v. Löwis schrieb: Has anyone an idea? You should not install "for all users" before copying it, but "just for me". Regards, Martin This works! Thank you very much! (Sorry for the delay. I had been on a conference, than I was ill and than, there were more urgent things...) But now PyScripter may not use Python 2.6 internally. E. g., if I load a python-dll (import bz2) I receise an Runtime ERROR! R6034... Again, thanx a lot Werner -- http://mail.python.org/mailman/listinfo/python-list
Windows PE and Python 2.6 (Side-by-Side error)
Hallo, I like Python 2.6 and I like to use it anywhere, even within Windows PE. In former version of Python (<= 2.5.x) it was easy to bring it to a Windows PE system: Install Python to Windows XP or Vista and (robo-) copy the whole directory off Python (and all sub directories) to the Windows PE system, adapt the path and it works. With Python 2.6 I receive errors in the kind of '''Error: The Side-by-Side configuration information in "d:\4_debug\python26\PYTHON.EXE" contains errors. The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail (14001). Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.''' What I did: I copied all DLLs which DEPWALK found to C:\Python26, but the error remained... Has anyone an idea? Thank you in advance Werner -- http://mail.python.org/mailman/listinfo/python-list
Announce: pcp-0.1
Name:pcp-0.1 Description: Python Interface to SGI's Performance Co-Pilot client API License: GNU LGPL Download:ftp://oss.sgi.com/www/projects/pcp/download/python- pcp-0.1.tar.gz Web: http://oss.sgi.com/projects/pcp/ Author: Michael Werner Email: mtw at protomagic dot com Description of this Python Extension - This python extension, called pcp, provides an interface to the client C API for SGI's open source Performance Co-Pilot. This is a very early release and some core functionality is missing, namely reading and writing archive files. A set of convenience classes is provided, which build upon the base functionality of SGI's library. These convenience classes may change in future releases, as use-cases evolve and feedback suggests. A sample program is included. Description of SGI's Performance Co-Pilot - Performance Co-Pilot is a distributed mechanism for measuring and recording the performance and activity of computers, networks, applications, and servers. PCP also includes an inference engine that can trigger responses to measured conditions or events. Several hundred different operational parameters can be measured from target machines, their operating systems, MySQL, Apache, Sendmail, VMWare, KVM, etc. There is a server-side library available for writing additional plug-in modules to measure any custom target application or server. There is a client-side library for writing custom applications to collect and utilize measurements. This python extension wraps that client-side C library, libpcp. Performance Co-Pilot is known to run on Windows and many Unix/Linux variants. Example Application - To see an example prototype application that uses these python extensions to visualize system activity, visit ... http://blenderartists.org/forum/showthread.php?t=157085 Python.org site URL - http://oss.sgi.com/projects/pcp/";>pcp 0.1 - Python Interface to SGI's Performance Co-Pilot client API (22-May-09) - -- http://mail.python.org/mailman/listinfo/python-list
Re: To Thread or not to Thread....?
Hi I see quite a few alleys to go down when stuck with such types of problems, but instead of listing and discussing them have a look at a quite complete discussion and comparison of the various async programming options available at http://syncless.googlecode.com Also have a look at the presentation at http://syncless.googlecode.com/svn/trunk/doc/slides_2010-11-29/pts_coro_2010-11-29.html If I were in your shoes I would solve the problem in stackless, if exchanging the python interpreter is not possible then Twisted would be my second choice, having done a lot of work with it (see the NMEA classes for serial ports). I don't know if syncless handles other types of fd's like serial ports, I've never played with it. The monkey patching of syncless might pose other problems in your case. HTH, Werner Am 01.12.2010 14:48, schrieb James Mills: Surely I2C is just a serial-like interface and one should be able to do async I/O on it ? The use of threads is not necessary here and the GIL doesn't become a problem in async I/O anyway. I only use threads for operating that might block (not for I/O). cheers James On Wed, Dec 1, 2010 at 7:24 PM, Antoine Pitrou wrote: On Wed, 1 Dec 2010 02:45:50 + Jack Keegan wrote: Hi there, I'm currently writing an application to control and take measurements during an experiments. This is to be done on an embedded computer running XPe so I am happy to have python available, although I am pretty new to it. The application basically runs as a state machine, which transitions through it's states based on inputs read in from a set of general purpose input/output (GPIO) lines. So when a certain line is pulled low/high, do something and move to another state. All good so far and since I get through main loop pretty quickly, I can just do a read of the GPIO lines on each pass through the loop and respond accordingly. However, in one of the states I have to start reading in, and storing frames from a camera. In another, I have to start reading accelerometer data from an I2C bus (which operates at 400kHz). I haven't implemented either yet but I would imagine that, in the case of the camera data, reading a frame would take a large amount of time as compared to other operations. Therefore, if I just tried to read one (or one set of) frames on each pass through the loop then I would hold up the rest of the application. Conversely, as the I2C bus will need to be read at such a high rate, I may not be able to get the required data rate I need even without the camera data. This naturally leads me to think I need to use threads. As I am no expert in either I2C, cameras, python or threading I thought I would chance asking for some advice on the subject. Do you think I need threads here or would I be better off using some other method. I was previously toying with the idea of using generators to create weightless threads (as detailed in http://www.ibm.com/developerworks/library/l-pythrd.html) for reading the GPIOs. Do you think this would work in this situation? The main question IMO: the I2C bus operates at 400kHz, but how much received data can it buffer? That will give you a hint as to how much latency you can tolerate. I don't think soft threads would work at all, since they wouldn't allow overlapping between frame reading and other ops. If frame reading releases the GIL (as any properly implemented IO primitive in Python should), then at least you can try using OS threads. Then, depending on the tolerable latency for I2C operation, you can try to run it as an OS thread, or a separate process (if running as a separate process, make sure it cannot block while sending IO to the master process). Regards Antoine. -- http://mail.python.org/mailman/listinfo/python-list <>-- http://mail.python.org/mailman/listinfo/python-list
Re: python ide for ubuntu
Eclipse with pydev (great debugging) does the trick nicely, free of charge and throws in some other goodies (JScript/HTML/XML editing) too. I use the EE for Java developer version http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/heliosr Install pydev from Menu Help/Software Updates After ten years of Python coding and suffering thru most of the commercial products like VisualPython, Komodo, Wings, asf I heartily recommend Eclipse nowadays. If you want to stay as pythonesque as possible you could go with SPE which uses wxPython and integrates with Blender, although this project seems to be stalled. Werner On 12.08.2010 04:15, Bhanu Kumar wrote: Hi All, Is there any good free python IDE available in Ubuntu? thanks, -Bhanu <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Deferring a function call
For me nothing beats using twisted ( http://www.twistedmatrix.com ) with its clean implementation of deferreds and a host of other useful things for simulations besides being the 'Swiss Army Knife' of networking in Python. If you throw in stackless ( http://www.stackless.com ) simulations with extremely high counts of participants and/or fine granularity distributed across multiple machines are fun to write, operate and maintain. Werner On 10/18/10 6:21 PM, TomF wrote: I'm writing a simple simulator, and I want to schedule an action to occur at a later time. Basically, at some later point I want to call a function f(a, b, c). But the values of a, b and c are determined at the current time. One way way to do this is to keep a list of entries of the form [[TIME, FN, ARGS]...] and at simulated time TIME do: apply(FN, ARGS) Aside from the fact that apply is deprecated, it seems like there should be a cleaner (possibly more Pythonic) way to do this. Ideas? -Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Python 2.5.6 Release Candidate 1
On 04/17/2011 11:57 PM, "Martin v. Löwis" wrote: http://www.python.org/2.5.6 Just FYI, getting a 404 error on the above. I can see a 2.5.6c1 listes on "http://www.python.org/download/releases/2.5/highlights/"; which goes to "http://www.python.org/download/releases/2.5.6/"; Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Magic function
Well as I understand your problem now, you would not like all instances of an specific object that are still alive, but all references to an object (created somewhere, sometimes) in an local context (stack frame), that are accessible from 'that' context ( but also from many others). However in python a stack frame does not 'contain' an object. It only contains a reference to an object. You may delete this reference whithin this frame, but the object may still be alive. So you can do following: def run(att): for k, v in att.iteritems(): if isinstance(v, dict): print k, v, id(v) def foo(bar): x = list() y = object() run(locals()) del bar run(locals()) bazz = dict() print "bazz has id ", id(bazz) foo(bazz) print "bazz has id ", id(bazz) >pythonw -u "console_play.py" bazz has id 11068592 bar {} 11068592 bazz has id 11068592 >Exit code: 0 Note that bar {} is printed only once, since the reference 'bar' defined in foo has been deleted. The object itself is still alive because the referece 'bazz' still exists. You should consider, that inspecting the stack will not tell you if an object is alive or not. It also doesn't tell you that an object can't be used by your users. If you come from an C++ background, then consider that python is different. Creating an object in an local context will not destroy this object if you leafe this context. There is no such thing like a 'destructor' in python. You should also consider, that frame objects are not destroyed if used by an generator or if there is still a reference to them. A frame object may life forever. Read the manual about the inspect module! Inspecting the stack may give you wrong and difficult to debug results. I just wouldn't do that. Keeping track of instances isn't that difficult. However if you need instances (not references to them!) that have been created within a specific stack frame you may use my example below. It will extend the weakref with the id of the stackframe that created it. However the instance may still live while the frame had been destroyed long ago! Remember: Inspecting the stack will not tell you weather a user can use an specific object nor will it tell you, if the object is alive or not. from weakref import ref from inspect import getouterframes, currentframe class ExtendedRef(ref): def __init__(self, ob, callback=None, **annotations): super(ExtendedRef, self).__init__(ob, callback) self.__id = 0 class WeakSet(set): def add(self, value, id=0): wr = ExtendedRef(value, self.remove) wr.__id = id set.add(self, wr) def get(self, id): return [ _() for _ in self if _.__id == id] class bigobject(WeakSet): def run(self): outer_frame = id(getouterframes( currentframe())[1][0]) for obj in self.get(outer_frame): # process object's print obj.value class foo(object): __instances__ = bigobject() def __init__(self, value): outer_frame = id(getouterframes( currentframe())[1][0]) foo.__instances__.add(self, outer_frame) self.value = value def main( depth ): obj1 = foo("obj1 at depth %s" % depth) obj2 = foo("obj2 at depth %s" % depth) foo.__instances__.run() print "processed objects created at %s" % id(currentframe()) if depth == 0: return else: main(depth-1) if __name__ == "__main__": obj1 = foo("obj1 at depth root") main(3) foo.__instances__.run() print "processed objects created at %s" % id(currentframe()) >pythonw -u "test12.py" obj1 at depth 3 obj2 at depth 3 processed objects created at 11519672 obj2 at depth 2 obj1 at depth 2 processed objects created at 11496496 obj2 at depth 1 obj1 at depth 1 processed objects created at 11813904 obj2 at depth 0 obj1 at depth 0 processed objects created at 11814272 obj1 at depth root processed objects created at 11443120 >Exit code: 0 -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen on Windows
I am trying to use subprocess - it basically works but. command = 'ping ' + '-n '+ str(count) + ' -l ' + str(size) + ' ' + str(node) print command p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) pout = p.stdout.read() This works for me but I see the Windows command window, is there a way to call subprocess without a command window showing? I am trying to replace: fdout, fdin = popen2.popen4('ping -n '+ str(count)+ ' -l '+ str(size) +' '+node) Which did not show the command window. I did quit a bit of googling bug so far did not find an answer to my problem. Appreciate any hints on how this can be accomplished. Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen on Windows
Werner F. Bruhin wrote: I am trying to use subprocess - it basically works but. command = 'ping ' + '-n '+ str(count) + ' -l ' + str(size) + ' ' + str(node) print command p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) pout = p.stdout.read() This works for me but I see the Windows command window, is there a way to call subprocess without a command window showing? I am trying to replace: fdout, fdin = popen2.popen4('ping -n '+ str(count)+ ' -l '+ str(size) +' '+node) Which did not show the command window. I did quit a bit of googling bug so far did not find an answer to my problem. Appreciate any hints on how this can be accomplished. A little while after I sent this I found the answer with google on activestate. http://code.activestate.com/recipes/409002/ Werner -- http://mail.python.org/mailman/listinfo/python-list
logging module
I am starting to use the logging module. Simple log to file and/or console work very nicely. Even managed to get TimedRotatingFileHandler to work. The problem I am trying to solve. 1. I would like to have a "log viewer" a wxPython based app to be able to look at a log generated by another script. Did a little test for this. - log_testing.py attached is generating the log entries - log_viewerConsole.py is trying to attach to the same logger (would convert/change this to a wxPython app) The log_viewerConsole script only sees the logs it generates. Does this script have to be started by the first one to get the same logger? Any hints on how to solve my problem would be very appreciated. Werner [formatters] keys=simple [handlers] keys=consoleHandler,fileRollOver,ntEventLog [loggers] keys=root,frollover [formatter_simple] format=%(name)s:%(levelname)s %(module)s: %(lineno)d: %(asctime)s: %(message)s [handler_consoleHandler] class=StreamHandler args=[] formatter=simple [handler_fileRollOver] class=handlers.TimedRotatingFileHandler args=['./logs/pyg_log.txt', 'M', 30, 5] formatter=simple [handler_ntEventLog] class=handlers.SysLogHandler args=[("localhost",handlers.SYSLOG_UDP_PORT),handlers.SysLogHandler.LOG_USER] formatter=simple [logger_root] level=DEBUG handlers=ntEventLog [logger_frollover] level=DEBUG handlers=fileRollOver qualname=loggerFRO import logging, logging.config, logging.handlers import time # setup logging logging.config.fileConfig('pyg_log.cfg') # create logger logger = logging.getLogger("loggerFRO") while 1: #"application" code logger.debug("debug message") logger.info("info message") logger.warn("warn message") logger.error("error message") logger.critical("critical message") try: x = 1 / 0 except: logger.exception('exception') logger.info("sleeping") time.sleep(5) logger.info("done sleeping")import logging, logging.config import time logging.config.fileConfig('pyg_log.cfg') # create logger logger = logging.getLogger("loggerFRO") # handler streamHandler = logging.StreamHandler() # formater formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s") streamHandler.setFormatter(formatter) logger.addHandler(streamHandler) logger.info('just a test message') while 1: time.sleep(1) logger.info('slept 1') -- http://mail.python.org/mailman/listinfo/python-list
Why is indexing into an numpy array that slow?
Hello! Out of curiosity and to learn a little bit about the numpy package i've tryed to implement a vectorised version of the 'Sieve of Zakiya'. While the code itself works fine it is astounding for me that the numpy Version is almost 7 times slower than the pure python version. I tryed to find out if i am doing something wrong but wasn't able to find any answer. Some experimentation showed that indexing into an numpy array is the bottleneck that slows down my code. However i don't understand why. So i am looking for any explaination why the numpy version is that slow (i expected it to be at least as fast as the pure python version). Thank you in advance >pythonw -u "PrimeSieve.py" 5 Erat: 0.00 ZakijaP5: 0.00 VZakijaP5: 0.00 105 Erat: 0.219000 ZakijaP5: 0.219000 VZakijaP5: 1.578000 205 Erat: 0.468000 ZakijaP5: 0.469000 VZakijaP5: 3.297000 305 Erat: 0.719000 ZakijaP5: 0.703000 VZakijaP5: 5.00 405 Erat: 0.937000 ZakijaP5: 0.985000 VZakijaP5: 6.734000 505 Erat: 1.219000 ZakijaP5: 1.218000 VZakijaP5: 8.172000 605 Erat: 1.50 ZakijaP5: 1.531000 VZakijaP5: 9.829000 705 Erat: 1.781000 ZakijaP5: 1.813000 VZakijaP5: 11.50 805 Erat: 2.047000 ZakijaP5: 2.094000 VZakijaP5: 13.187000 905 Erat: 2.312000 ZakijaP5: 2.391000 VZakijaP5: 14.891000 1005 Erat: 2.578000 ZakijaP5: 2.672000 VZakijaP5: 16.641000 1105 Erat: 2.891000 ZakijaP5: 2.953000 VZakijaP5: 18.203000 1205 Erat: 3.11 ZakijaP5: 3.297000 VZakijaP5: 19.937000 #-- Prime_Sieves.py-- from math import sqrt def sieveOfErat(end): if end < 2: return [] lng = (end-1)>>1 sieve = [True]*(lng+1) for i in xrange(int(sqrt(end)) >> 1): if not sieve[i]: continue for j in xrange( (i*(i + 3) << 1) + 3, lng, (i << 1) + 3): sieve[j] = False primes = [2] primes.extend([(i << 1) + 3 for i in xrange(lng) if sieve[i]]) return primes def SoZP5(val): if val < 3 : return [2] if val < 5 : return [2,3] lndx = (val-1)/2 sieve = [0]*(lndx+15) sieve[0:14] = 0 , 1 , 2, 0, 4, 5, 0, 7, 8, 0, 10, 0, 0, 13 for _i in xrange(14, lndx , 15): sieve[_i:_i+15] = _i -1, 0, 0, _i + 2 , 0, _i + 4, _i + 5, 0, _i +7, _i + 8, 0, _i + 10, 0, 0, _i + 13 for i in xrange(2, (int(sqrt(val))-3/2)+1): if not sieve[i]: continue k = 30*i+45 p1 = 7*i+9 # 7 (2i+3) p2 = 11*i+15 # 11 (2i+3) p3 = 13*i+18 # 13 (2i+3) p4 = 17*i+24 # 17 (2i+3) p5 = 19*i+27 # 19 (2i+3) p6 = 23*i+33 # 23 (2i+3) p7 = 29*i+42 # 29 (2i+3) p8 = 31*i+45 # 31 (2i+3) for _i in xrange(0, lndx, k): try: sieve[_i+p1] = 0 sieve[_i+p2] = 0 sieve[_i+p3] = 0 sieve[_i+p4] = 0 sieve[_i+p5] = 0 sieve[_i+p6] = 0 sieve[_i+p7] = 0 sieve[_i+p8] = 0 except (IndexError, ): break primes = [(i*2)+3 for i in xrange(2, lndx) if sieve[i]] primes[0:0] = [2,3,5] return primes from numpy import array, zeros def VSoZP5(val): """ Vectorised Version of Sieve of Zakia""" if val < 3 : return [2] if val < 5 : return [2,3] lndx = (val-1)/2 sieve = zeros(lndx+15,dtype="int32") #<-- Offending line: Indexing a numpy array is slow sieve[0:14] = 0 , 1 , 2, 0, 4, 5, 0, 7, 8, 0, 10, 0, 0, 13 for _i in xrange(14, lndx , 15): sieve[_i:_i+15] = _i -1, 0, 0, _i + 2 , 0, _i + 4, _i + 5, 0, _i +7, _i + 8, 0, _i + 10, 0, 0, _i + 13 om = array([9, 15, 18, 24, 27, 33, 42, 45], dtype="int32") bm = array([7, 11, 13, 17, 19, 23, 29, 31], dtype="int32") for i in xrange(2, (int(sqrt(val))-3/2)+1): if not sieve[i]: continue k = 30*i+45 rm = (bm * i) + om for _i in xrange(0, lndx/k + 1): try: sieve[rm] = 0 #<-- Offending line: Indexing a numpy array is slow rm += k except (IndexError,): break # primes = [(i*2)+3 for i in xrange(2, lndx) if sieve[i]] primes[0:0] = [2,3,5] return primes if __name__ == '__main__': import time for j in range(5, 2007, 100): print j, a = time.time() soe = sieveOfErat(j) print "Erat: %2f" % (time.time() -a,), a = time.time() soz5 = SoZP5(j) print "ZakijaP5: %2f" % (time.time() -a), a = time.time() sovz5 = VSoZP5(j) print "VZakijaP5: %2f" % (time.time() -a) assert soe == soz5 == sovz5 #-- Prime_Sieves.py-- -- http://mail.python.org/mailman/listinfo/python-list
setuptools for 2.6 and windows?
I would like to start looking into Python 2.6 and do some testing. First hurdle I run into is that I can not find a 2.6 installer for Windows for setuptools-0.6.9c, only Py2.4 and Py2.5 seem to be available on pypi. Is there such a thing yet? If yes can someone provide me a link to it. Thanks Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Packaging Survey
Tarek Ziadé wrote: The Python Langage Summit is coming up. To prepare this event, I have put online a survey you can take to tell us a bit more about you and how you package your Python applications. * Who should take the survey : any Python developer that packages and distributes his code, no matter how. * Take the survey: http://tinyurl.com/package-survey Get the following error on this link: Secure Connection Failed mdp.cti.depaul.edu uses an invalid security certificate. The certificate is not trusted because it is self signed. The certificate is only valid for Massimo Di Pierro The certificate expired on 01/03/2009 07:56. (Error code: sec_error_expired_issuer_certificate) Werner -- http://mail.python.org/mailman/listinfo/python-list
logging - string formating problems
I see the following exception with a string formating problem. TypeError: not all arguments converted during string formatting Traceback (most recent call last): File "/usr/lib/python2.5/logging/__init__.py", line 744, in emit msg = self.format(record) File "/usr/lib/python2.5/logging/__init__.py", line 630, in format return fmt.format(record) File "/usr/lib/python2.5/logging/__init__.py", line 418, in format record.message = record.getMessage() File "/usr/lib/python2.5/logging/__init__.py", line 288, in getMessage msg = msg % self.args The exception does not give any information on where the problem is coming from. I am using Python 2.5.4 but I see that in 2.6 the code is still the same. Any chance that getMessage could catch this exception and provide better debugging information (i.e. content of msg and self.args). Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: logging - string formating problems
Werner F. Bruhin wrote: I see the following exception with a string formating problem. TypeError: not all arguments converted during string formatting Traceback (most recent call last): File "/usr/lib/python2.5/logging/__init__.py", line 744, in emit msg = self.format(record) File "/usr/lib/python2.5/logging/__init__.py", line 630, in format return fmt.format(record) File "/usr/lib/python2.5/logging/__init__.py", line 418, in format record.message = record.getMessage() File "/usr/lib/python2.5/logging/__init__.py", line 288, in getMessage msg = msg % self.args The exception does not give any information on where the problem is coming from. I am using Python 2.5.4 but I see that in 2.6 the code is still the same. Any chance that getMessage could catch this exception and provide better debugging information (i.e. content of msg and self.args). I understand that my problem is that the arguments don't match the format. But currently the traceback is not of any help in figuring out where this in my code this is. So, I suggest that line 288 in getMessage is changed from: msg = msg % self.args To something along these lines: if self.args: try: msg = msg % self.args except: print 'msg: %s' % msg print 'args: %s' % self.args traceback.print_exception(ei[0], ei[1], ei[2]) return msg Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: logging - string formating problems
I am fully aware that the problem is in my code, however as getMessage in logging.__init__.py does not catch the exception it is pretty difficult to find the problem without manually inspecting any logging.something statements. My hack of logging.py is really a hack and I know that this can not be used a patch but I hope that someone with more know how then me knows how to improve the situation. BTW, using the below hack was enough for me to mind the bad code in my stuff, but it shouldn't have been this difficult. Traceback (most recent call last): File "C:\Python25\lib\logging\__init__.py", line 750, in emit msg = self.format(record) File "C:\Python25\lib\logging\__init__.py", line 636, in format return fmt.format(record) File "C:\Python25\lib\logging\__init__.py", line 424, in format record.message = record.getMessage() File "C:\Python25\lib\logging\__init__.py", line 288, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting Then I hack logging.py and change line 288 in getMessage from: msg = msg % self.args to: try: msg = msg % self.args except: print 'msg: %s' % msg print 'args: %s' % self.args print traceback.format_exc() I get the following which helps a lot more in finding were in my code I have the problem: msg: ping_min: 1 args: replace Traceback (most recent call last): File "C:\Python25\lib\logging\__init__.py", line 290, in getMessage msg = msg % self.args TypeError: not all arguments converted during string formatting As mentioned above, I know the above code is not good enough at all, but I hope that maybe Vinay Sajip or someone else with more know how then I have can come up with a patch which will make this type of situation easier. Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: installer for py2exe files?
Hi Gabriel, Gabriel Rossetti wrote: Hello everyone, I am wanting to create an installer for my project. I first use py2exe to create win32 executables and then would like to have an easy to use (for the end user) installer. I use InnoSetup - link already given by David. I would need the installer to launch a script (a python script also turned into an exec) after the install is done, or even better yet, incorperate the script's tasks in the installation process (configure files, check for open ports, etc.). Does anyone have an idea, recommendation or has had a similar situation before? If you install on e.g. Vista then the installer is running as admin, be careful when you want to set configuration info. You might set it for the admin instead of for the real user. IIRC, you should only set HKCR and HKLM keys in the registry, do not set HKCU unless you want to set something for the admin. You also have to watch out that you application folder is read-only, i.e. do not store configuration files in your application program folder if they might get changed by the user. If you do and user changes them then they will be written to a folder under the users home folder and this might cause strange errors and/or confusion. There are some more tips and more details about all this on the InnoSetup site. Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting Math Problem
"BEES INC" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] ... Problem: Star Ratings People can rate cheeseburgers on my website with a star rating of 0-5 stars (whole stars only), 5 being mighty tasty and 0 being disgusting. I would like to show the average of everyone's ratings of a particular cheeseburger to the nearest half star. I have already calculated the average rating as a float (star_sum) and the total number of people that rated the particular cheeseburger (num_raters). The result should be stored as a float in a variable named "stars." My Solution (in Python): Well seems this is a typical half even rounding problem. See http://mail.python.org/pipermail/python-list/2008-April/485889.html for a long discussion However since your problem looks like a typical homework problem i made my example buggy by intention. However the result should be correct. have fun! def myround(x): d, m = divmod(x, 2) return 2*d + round(m - 1) + 1 num = 1.5 for _i in xrange(30): print num, ' -> ', myround(num * 2)/2 num -= 0.1 >pythonw -u "test18.py" 1.5 -> 1.5 1.4 -> 1.5 1.3 -> 1.5 1.2 -> 1.0 1.1 -> 1.0 1.0 -> 1.0 0.9 -> 1.0 0.8 -> 1.0 0.7 -> 0.5 0.6 -> 0.5 0.5 -> 0.5 0.4 -> 0.5 0.3 -> 0.5 0.2 -> 0.0 0.1 -> 0.0 -1.94289029309e-016 -> 0.0< --- hint for bug -0.1 -> 0.0 -0.2 -> 0.0 -0.3 -> -0.5 -0.4 -> -0.5 -0.5 -> -0.5 -0.6 -> -0.5 -0.7 -> -0.5 -0.8 -> -1.0 -0.9 -> -1.0 -1.0 -> -1.0 -1.1 -> -1.0 -1.2 -> -1.0 -1.3 -> -1.5 -1.4 -> -1.5 >Exit code: 0 to avoid the bug have a look at: http://mail.python.org/pipermail/python-list/2008-April/485934.html and try this example: num = 3 for _i in xrange(num * 10,-num *10, -1): if myround(float(_i)/10) != myround(num): print num, " -> ", myround(num ), " --- ", myround(float(_i)/10) print "-" num -= 0.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python base distribution come with a validating XML parser?
> Hi, > > Basic XML questions, > > I have a .xml file I want to validate against a .xsd file... > > Does the Python base distribution come with a validating XML parser? > > I want to make sure the elements in my xml file vs. the elements > defined in my xsd are a match. > > I could parse both XML and xsd elements to lists and compare the > lists, but I imagine the validation process can do this too... > > Some of this is basic stuff - just a link to a site or doc is > sufficient. > > Thanks. I think you are looking for lxmlhttp://codespeak.net/lxml/ -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe bug with email.MIMEText
Hi Marcus, Marcus.CM wrote: There is a bug with py2exe when (at least under windows) when importing email # example testmime.py import email msg = email.MIMEText.MIMEText("dsafdafdasfA") print "ok" 1. Save the text above and setup as testmime.py 2. Run it and u can see "ok" 3. Create setup.py and run : python setup.py py2exe 4. Run the testmime.exe and u will get error "Import error : No module name text" # Example setup.py from distutils.core import setup import py2exe setup(console=['testmime.py']) Anyone knows the fix for this? I see that you did find a solution for your problem. An alternative solution is to force py2exe to include all of the email package. packages = ['matplotlib.numerix', 'pytz.zoneinfo.UTC', 'email', 'encodings', ... etc] Werner -- http://mail.python.org/mailman/listinfo/python-list
Re: help with parsing email
Ahmed, Shakir wrote: Thanks everyone who tried to help me to parse incoming email from an exchange server: Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve this error and extract emails from an exchange server. First I tried: mailserver = 'EXCHVS01.my.org' mailuser = 'myname' mailpasswd = 'mypass' mailserver = poplib.POP3(mailserver) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\poplib.py", line 96, in __init__ raise socket.error, msg error: (10061, 'Connection refused') The other way: mailserver = 'pop.EXCHVS01.ad.my.org' mailuser = '[EMAIL PROTECTED]' mailpasswd = 'mypass' mailserver = poplib.POP3(mailserver) Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\poplib.py", line 84, in __init__ for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): gaierror: (11001, 'getaddrinfo failed') Haven't used poplib myself, but was intrigued. Did you see this: http://www.python.org/doc/lib/pop3-example.html To me it looks like you are not setting the user/password. So, maybe something like: M = poplib.POP3(mailserver) M.user(mailuser) M.pass_(mailpasswd) Werner -- http://mail.python.org/mailman/listinfo/python-list
Upgrade Python 2.6.4 to 2.6.5
Just upgraded on my Windows 7 machine my copy of 2.6.4 to 2.6.5. However doing sys.version still shows 2.6.4 even so python.exe is dated 19. March 2010 with a size of 26.624 bytes. Is this a known issue? Or did I do something wrong? If I install to a new folder all is well, but I would have to install all my other stuff again (kinterbasdb, matplotlib, sphinx etc etc). Werner -- http://mail.python.org/mailman/listinfo/python-list