Got questions to pose to the Python-Dev panel at PyCon?
On the first conference day of PyCon after lunch there is going to be a discussion panel for Python-Dev (see http://us.pycon.org/apps07/schedule/ for the schedule). It is going to be moderated by Steve Holden and is slated to have myself (Brett Cannon), Andrew Kuchling (AMK), Neal Norwitz, and Jeremy Hylton on the panel. But in order to make the panel a success we need some questions. We will have a portion of time open to questions from the floor, but we would also like to have some questions lined up. If you have any questions you would like to have answered by the panel, please add them to http://us.pycon.org/TX2007/PythonDevPanel . The wiki page will be considered the definitive location of collected questions so please do not leave any questions as a reply to this announcement as it will not get noticed. I do not know if there will be an audio or video recording of the panel discussion, but there is a decent chance if last year's PyCon is any indication. Plus someone in the audience might be kind enough to type up a transcript and post it online. Thanks in advance to anyone who contributes a question. -Brett C. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Next meeting of pyCologne 10.01.2007
Hello everybody, the next meeting of pyCologne, the Python User Group Köln (Cologne), takes place on: Date: 10.01.2007 Time: 18:30 h Location: Pool 0.14, computing centre (RRZK-B) of the University Cologne, Berrenrather Str. 136, 50937 Köln Detailed information can be found on our page in the German Python Wiki: http://wiki.python.de/User_Group_K%C3%B6ln#Termine We invite everybody in the area who's interested in the Python programming language to join our meetings or take part in the discussions on our mailing list. If you are planning to come to this meeting, it would be sensible, though not strictly necessary, to drop us a line on our mailing list or via private email to me (if you have not already done so), because the room we have at the university has a limited capacity. Looking forward to see many of you! Christopher Arndt -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: How to invoke parent's method?
many_years_after wrote: Hi, pythoners: My wxPython program includes a panel whose parent is a frame. The panel has a button. When I click the button , I want to let the frame destroy. How to implement it? Could the panel invoke the frame's method? Thanks. I think it could if what I read recently in: http://www.python.org/download/releases/2.2/descrintro/#cooperation Is applicable. Look at the link Cooperative methods and super Write a subclass of panel where the target method of it's parent is targX (that parent method of Frame that you want to call) class myPanel (Panel): def dadsX (self): Frame.targX(self) I think you are forced to invoke this within a method of the Class itself, as opposed to doing so with an instance. Good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin wrote: Yes I've had plenty of pointer related bugs in C programs that don't happen in GC'd languages, so GC in that sense saves my ass all the time. My experience is different, I never suffered a lot for leaking or dangling pointers in C++ programs; and on the opposite I didn't expect that fighting with object leaking in complex python applications was that difficult (I've heard of zope applications that just gave up and resorted to the reboot every now and then solution). With a GC if you just don't plan ownership and disposal carefully and everything works as expected then you're saving some thinking and code, but if something goes wrong then you're totally busted. The GC leaky abstraction requires you to be lucky to work well, but unfortunately IMO as code complexity increases one is never lucky enough. Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: How to invoke parent's method?
rweth wrote: many_years_after wrote: Hi, pythoners: My wxPython program includes a panel whose parent is a frame. The panel has a button. When I click the button , I want to let the frame destroy. How to implement it? Could the panel invoke the frame's method? Thanks. I think it could if what I read recently in: http://www.python.org/download/releases/2.2/descrintro/#cooperation Is applicable. Look at the link Cooperative methods and super Write a subclass of panel where the target method of it's parent is targX (that parent method of Frame that you want to call) class myPanel (Panel): def dadsX (self): Frame.targX(self) I think you are forced to invoke this within a method of the Class itself, as opposed to doing so with an instance. Good luck! You know I just tried a code fragment and got the parent method to work with an instance .. so maybe you don't have to subclass. Here is a transcript illustrating the idea: class DAD: ... def methodx(self): ... print DAD-methodx ... class SON(DAD): ... def methodx(self): ... print SON-methodx ... billy = SON() billy.methodx() SON-methodx DAD.methodx(billy) DAD-methodx So you can invoke the DAD.methodx via the billy instance of the object .. without subclassing. Now I wonder if this will actually work? -- http://mail.python.org/mailman/listinfo/python-list
where is python on linux?
I installed fedora core 6 and it has python installed. But the question is, where is the executable python file? I can't find it so I come here for help. I want to config pydev for eclipse and I need to know where the ececutable python file is. Thank you! -- http://mail.python.org/mailman/listinfo/python-list
Re: where is python on linux?
Frank Potter wrote: ... where is the executable python file? ... does whereis python tell you what you want to know? sebastian. -- http://mail.python.org/mailman/listinfo/python-list
Re: where is python on linux?
Frank Potter wrote: I installed fedora core 6 and it has python installed. But the question is, where is the executable python file? Find out yourself with $ which python Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
W. Watson kirjoitti: Thomas Ploch wrote: snip https://sourceforge.net/projects/pywin32/ I think this is the place to go Thomas That gets me the python program (pywin), which I got from a URL in a post above (python-win.msi). I guess these are the same or at least just the interpreter, and do not provide the IDE-debugger. I can't get pythonwin, the debugger and IDE. The link was broken last night when I tried it. Well, let me try now. Nope, it still reports Error 404: File Not Found I don't understand your difficulties. If you've got Python installed and want to install the Python for Windows extensions aka pywin32, the above link is the way to go. Clicking it gets you to a Sourceforge page, where you can click download which gets you to ap page where you can choose which version of pywin32 build 210 you want. Choose the exe that was built for the Python version (e.g. 2.5) you are using, download and run it to install pywin32. HTH, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: where is python on linux?
Thank you! which python works for me. I got it. Peter Otten wrote: Frank Potter wrote: I installed fedora core 6 and it has python installed. But the question is, where is the executable python file? Find out yourself with $ which python Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: How to invoke parent's method?
many_years_after wrote: Hi, pythoners: My wxPython program includes a panel whose parent is a frame. The panel has a button. When I click the button , I want to let the frame destroy. How to implement it? Could the panel invoke the frame's method? Thanks. Have a look at the following program - -- class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) MyPanel(self) class MyPanel(wx.Panel): def __init__(self,frame): wx.Panel.__init__(self,frame,-1) self.frame = frame b = wx.Button(self,-1,'Close') b.Bind(wx.EVT_BUTTON,self.onClose,id=b.GetId()) def onClose(self,evt): self.frame.Close() evt.Skip() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, Test) frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(0) # Create an instance of the application class app.MainLoop() # Tell it to start processing events -- The essential point is that you save a reference to the frame when you create the panel. Then when the button is clicked you can use the reference to call the frame's Close method. HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Dennis Lee Bieber [EMAIL PROTECTED] writes: __ (two leading underscores) results in name-mangling. This /may/ be used to specify private data, but is really more useful when one is designing with multiple super classes: Trouble with this is you can have two classes with the same name, perhaps because they were defined in different modules, and then the name mangling fails to tell them apart. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES256 in PyCrypto
In [EMAIL PROTECTED], mirandacascade wrote: Would the following Python code perform AES256 encryption on plainText from Crypto.Cipher import AES x = AES.new(a, AES.MODE_CBC, iv) x.encrypt(plainText) assuming: a = the key value iv = an initialization vector ? `a` must be of length 32 for AES256. And the length of `plainText` must be a multiple of 16 because it's a block cypher algorithm. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? Thanks any insight. One thing that the other posters didn't mention is that if you access data members of a class in C++ you end up with a very tight coupling with that class. If the class later changes so that the data is no longer part of the public interface, then every user of the class has to change the code and recompile. In Python, on the other hand, if I have a piece of public data that I later decide to replace with an accessor method, I can do that without changing any of the code that uses the class. So, insistence on private data in C++ is a good thing because it reduces the level of coupling between a class and its clients. In Python, this is not an issue, because the same loose coupling can be obtained with data as well as accessor methods, and therefore public data is used when possible and private data when necessary. hth Ben -- If this message helped you, consider buying an item from my wish list: http://artins.org/ben/wishlist I changed my name: http://periodic-kingdom.org/People/NameChange.php -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write code to get focuse the application which is open from server
vinthan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hi, I am new to python. I have to write test cases in python. An application is open in the desk top ( application writen in .Net) I have to write code to get focuse the application and click on the link which in the one side and it will load the map on the other and I have to check map is loaded. Any one tell me how do I use Dispatch or any other method to write a code. If you are running on Windows, look into pywinauto (http://www.openqa.org/pywinauto/). I have successfully used it to interact with a Flash animation running within an IE browser. I also had to inspect the graphics displayed by the Flash animation, for this I used PIL (http://www.pythonware.com/products/pil/). Good luck, -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
On 07 Jan 2007 02:01:44 -0800, Paul Rubin http://phr.cx@nospam.invalid wrote: Dennis Lee Bieber [EMAIL PROTECTED] writes: __ (two leading underscores) results in name-mangling. This /may/ be used to specify private data, but is really more useful when one is designing with multiple super classes: Trouble with this is you can have two classes with the same name, perhaps because they were defined in different modules, and then the name mangling fails to tell them apart. What is the chance of having to inherit from two classes from different modules but with exactly the same name *and* the same instance variable name? Of course you're being very pessimistic or extremely unlucky. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early
Stef Mientki kirjoitti: In this exercise, I don't attempt to write beautiful Python code, but the first thing is to write a simple user-interface for non-Pythians. I understand that standardization about naming conventions is important, but the purpose here is to serve the user, who has to write and unerstand this, therefore IORLW is in the domain always written in capitals, spaces here makes it lot easier to compare the different actions, in this domain we're used to 2 spaces etc. snip thanks again for all your wonderfull help, cheers, Stef Mientki I can now understand the reason for the strange-looking function names etc. and think it's reasonable. The application domain is totally alien to me, though, so further explanations won't help me because a lack of the necessary electronic knowledge. Furthermore, as became evident from your web pages, your application is quite extensive which makes your task more difficult in formulating questions because things connected to other things are hard to extract for review. Anyway, happy hacking with Python. Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Felipe Almeida Lessa [EMAIL PROTECTED] writes: What is the chance of having to inherit from two classes from different modules but with exactly the same name *and* the same instance variable name? Of course you're being very pessimistic or extremely unlucky. If you want to write bug-free code, pessimism is the name of the game. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
[EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. What is the use of private declarations, if the names themselves are not verbose about it? = You'll always search the class definition/doc to check if the member is below private or you wait for compiler errors. If you still want to override, you have to declare 'friends' and all that school boy stuff. = Its not useful and efficient for programmers but probably more fulfilled teachers lust itching disciples, when those languages where invented. Moreover, in those languages there is more or less a clash of namespaces: All globals, module globals, members, local variables and possibly 'with'-variables. This confusion mixed with private declarations will soon provide a situation where one looses overview, what variable exactly was meant. The syntax in Python with _'s and 'self.' and true modularization and minimal magic namespace behavior, but with explicit self-similiar access to objects, modules, functions and everything is overall most clear und effective. After all I don't know another language which behaves so well in this regard. Even Ruby (little positive: it has not even the 'global' variable declaration) is much more ill below the line in that modules,classes, methods/functions.. are not objects but namespaces, messages etc. - thus self-similarity is so broken, that this which will actually limit the power and scalability of this language. Robert It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? Thanks any insight. -- http://mail.python.org/mailman/listinfo/python-list
I want to learn
Hi, I have been programming in the .net environment and ide for a few years and I am looking to make the switch over to python. I have absolutely no python experience whatsoever. I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. This would not be time consuming on your end and if necessary I would pay you for this. Ideally you would have familiarity with c# asp.net visual studio ide ajax.net etc. so you would understand where I'm coming from. Sorry to interrupt the group but since all python gurus appear to be happily at work on the next level apps at google nobody responded to my craigslist ads. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin: Python certainly makes you spend more of your attention worrying about possible attribute name collisions between classes and their superclasses. And Python's name mangling scheme is leaky and bug-prone if you ever re-use class names. Trouble with this is you can have two classes with the same name, perhaps because they were defined in different modules, and then the name mangling fails to tell them apart. Without changing Python syntax at all I think this situation may be improved. Instead of Python applying name mangling to names with __ before them, it can manage them as private, a higher level kind of management. And then if it's useful a new built-in function may be invented to access such private attributes anyway. I think this may solve your problem. (This is for Py3.0). Maybe a metaclass can be invented to simulate such behavior to test and try it before modifying the language itself. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to learn
[EMAIL PROTECTED]: I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. Maybe a Python gury isn't necessary, maybe a person that know the language enough may be enough. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to learn
[EMAIL PROTECTED] schrieb: Hi, I have been programming in the .net environment and ide for a few years and I am looking to make the switch over to python. I have absolutely no python experience whatsoever. I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. So you are looking for a person (no, a guru), that stays by your side the whole day, gives you answers and helps you learning python. This is a ridiculous request. If you want to learn python, you should start with visiting http://www.diveintopython.org/ and read it. If you have previous programming experience, this is the place to start. Sorry to interrupt the group but since all python gurus appear to be happily at work on the next level apps at google nobody responded to my craigslist ads. You can always ask your questions here on the list, there are enough people that are willing to help. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to learn
Thomas Ploch wrote: [EMAIL PROTECTED] schrieb: Hi, I have been programming in the .net environment and ide for a few years and I am looking to make the switch over to python. I have absolutely no python experience whatsoever. I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. So you are looking for a person (no, a guru), that stays by your side the whole day, gives you answers and helps you learning python. This is a ridiculous request. If you want to learn python, you should start with visiting http://www.diveintopython.org/ and read it. If you have previous programming experience, this is the place to start. Sorry to interrupt the group but since all python gurus appear to be happily at work on the next level apps at google nobody responded to my craigslist ads. You can always ask your questions here on the list, there are enough people that are willing to help. Thomas Also look into the tutor mailing list. Not EXACTLY what you're asking for but, very helpful, friendly people subscribe to it. http://mail.python.org/mailman/listinfo/tutor -- http://mail.python.org/mailman/listinfo/python-list
Manually installing PIL
Hello, My host doesn't have PIL installed, and from what i can tell, they won't install it. Is there any way i can copy the needed files near my python script? I'm using Image, ImageFont, ImageDraw and ImageFilter. Thanks. -- Best regards, Ghirai. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
On 06 Jan 2007 17:38:06 -0800, Paul Rubin http wrote: BJörn Lindqvist [EMAIL PROTECTED] writes: It is given that emphasizing private data (encapsulation) leads to more internal complexity and more lines of code because you have to write getters and setters and stuff. You can have public variables in Java if you choose to. Writing private variables with public setters and getters is just a style choice. Privates with getters/setters are (as I think someone else hinted) pretty pointless. The interesting stuff is the private data that *is* private, i.e. not meant for users at all. But yes, I don't mind not having 'private:' in Python. I don't have compile-time type checking anyway. In fact, I don't always know what the attributes of my objects /are/ until runtime. And besides, this is pretty close to a compile-time check: find -name \*.py | \ xargs egrep '\._[_a-z]' | \ fgrep -v self._ /Jorgen -- // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu \X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Jorgen Grahn schrieb: On 06 Jan 2007 17:38:06 -0800, Paul Rubin http wrote: BJörn Lindqvist [EMAIL PROTECTED] writes: It is given that emphasizing private data (encapsulation) leads to more internal complexity and more lines of code because you have to write getters and setters and stuff. You can have public variables in Java if you choose to. Writing private variables with public setters and getters is just a style choice. Privates with getters/setters are (as I think someone else hinted) pretty pointless. The interesting stuff is the private data that *is* private, i.e. not meant for users at all. Not really pointless, since you can hide your data structures that you don't want to be fiddled around with (which for me is almost the only point to use it). But yes, I don't mind not having 'private:' in Python. I don't have compile-time type checking anyway. In fact, I don't always know what the attributes of my objects /are/ until runtime. Me neither, although I have to say that the '__' prefix comes pretty close to being 'private' already. It depends on the definition of private. For me, private means 'not accessible from outside the module/class'. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: program deployment
On Fri, 05 Jan 2007 15:16:09 -, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-01-05, king kikapu [EMAIL PROTECTED] wrote: Python code is normally deployed as straight source code. But isn't this a problem of its own? I mean, many people do not feel good if the know that their source code is lying around on other machines... Are they embarassed by their code? For companies, that may be one reason. For many companies, rightly so ... /Jorgen -- // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu \X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Got questions to pose to the Python-Dev panel at PyCon?
On the first conference day of PyCon after lunch there is going to be a discussion panel for Python-Dev (see http://us.pycon.org/apps07/schedule/ for the schedule). It is going to be moderated by Steve Holden and is slated to have myself (Brett Cannon), Andrew Kuchling (AMK), Neal Norwitz, and Jeremy Hylton on the panel. But in order to make the panel a success we need some questions. We will have a portion of time open to questions from the floor, but we would also like to have some questions lined up. If you have any questions you would like to have answered by the panel, please add them to http://us.pycon.org/TX2007/PythonDevPanel . The wiki page will be considered the definitive location of collected questions so please do not leave any questions as a reply to this announcement as it will not get noticed. I do not know if there will be an audio or video recording of the panel discussion, but there is a decent chance if last year's PyCon is any indication. Plus someone in the audience might be kind enough to type up a transcript and post it online. Thanks in advance to anyone who contributes a question. -Brett C. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Thomas Ploch [EMAIL PROTECTED] writes: Me neither, although I have to say that the '__' prefix comes pretty close to being 'private' already. It depends on the definition of private. For me, private means 'not accessible from outside the module/class'. class A: __x = 3 class B(A): __x = 4 # ok class C(B): __x = 5 # oops! Consider that the above three class definitions might be in separate files and you see how clumsy this gets. -- http://mail.python.org/mailman/listinfo/python-list
Re: AES256 in PyCrypto
Marc 'BlackJack' Rintsch wrote: `a` must be of length 32 for AES256. And the length of `plainText` must be a multiple of 16 because it's a block cypher algorithm. Thank you. I have some follow up questions and 1 tangential question. Follow up question: Would it be correct to infer that: a) the AES.pyd extension module (plus whatever additional files within the PyCrypto package that it uses) has the capability to perform AES256 encryption? b) the AES256 encryption happens based on the characteristics of the input to the new() method...if the first argument has a length of 32, the result will be AES256-style encryption? c) will AES256-style encryption also happen if the first argument to the new() method has a length that is a multiple of 32, e.g. 64? Tangential question: Is there functionality available (either in the PyCrypto package or some other package) that generates an initialization vector that can be used as input to the new() method? What prompts this question is that the original posting referenced a snippet of C# code; some other related snippets I saw seemed to suggest that: a) a RijndaelManaged() class gets instantiated b) that class has a GenerateIV() method which appears to populate someting in a IV property c) the application that was employing the AES256 encryption made use of the left-most 16 characters of the IV property So, I was curious whether something analgous exists in the Python world. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
low level python read's
Hi! I wanted to use python to test a simple character device (on linux) and I'm running into strange behaviour of read.. I have a short buffer inside my device and the idea is that it blocks read's when the buffer is empty. For reads that ask for more characters that the buffer holds the device should return the number of bytes actually read... In c i can write: f = open(/dev/testdevice,O_RDWR); read(f,buffer,1000); and i see in my device, that everything is ok. No I'd love to reproduce this in python.. f = open(/dev/testdevice, r+,0) # for unbuffered access f.read(1000) ..but now i see in the device log's that python issued 2 reads! One that got the whole buffer (less then 1000 chars) and after that python tries to read more! (and hangs in my device, since the buffer is empty... So how do i stop python from trying to be smart and just read *at most* 1000 chars and let it go if he(it?*) reads less? grzes. p.s *is python a he or an it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin schrieb: Thomas Ploch [EMAIL PROTECTED] writes: Me neither, although I have to say that the '__' prefix comes pretty close to being 'private' already. It depends on the definition of private. For me, private means 'not accessible from outside the module/class'. class A: __x = 3 class B(A): __x = 4 # ok class C(B): __x = 5 # oops! Consider that the above three class definitions might be in separate files and you see how clumsy this gets. I don't understand why this should be oops, even if they are in different files. a = A() print a._A__x 3 b = B() print b._B__x 4 c = C() print c._C__x 5 dir(c) ['_A__x', '_B__x', '_C__x', '__doc__', '__module__'] print c._A__x 3 print c._B__x 4 -- http://mail.python.org/mailman/listinfo/python-list
Re: Pausing for Python Interpreter error messages...
Thanks Bruno. I'll get the 2.5 python install, and I'm checking out the unit testing module that you mentioned. Scott Huey Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : I've written a few classes that I have been testing in IDLE. However, every time I make a change to the classes based on the testing I have to walk through all he steps of preparing the classes for testing again. So I wrote a script that does all the set-up work for me. You may want to have a look at the unittest module then: http://docs.python.org/lib/module-unittest.html The only problem is when I run this script using the Python interpreter I can't get the command prompt to stay up long enough for me to read the message. How do I get the command prompt to stay up? first open the command prompt, then launch your script from the command prompt. Is there a way to run my script and view the error message in IDLE? menu run-run module, or just hit the F5 key. Thanks for the help. Scott Huey P.S. - I'm using Windows XP with the latest Python 2.3. Python 2.3 is years old. Latest is 2.5. -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
Jussi Salmela wrote: W. Watson kirjoitti: Thomas Ploch wrote: snip https://sourceforge.net/projects/pywin32/ I think this is the place to go Thomas That gets me the python program (pywin), which I got from a URL in a post above (python-win.msi). I guess these are the same or at least just the interpreter, and do not provide the IDE-debugger. I can't get pythonwin, the debugger and IDE. The link was broken last night when I tried it. Well, let me try now. Nope, it still reports Error 404: File Not Found I don't understand your difficulties. If you've got Python installed and want to install the Python for Windows extensions aka pywin32, the above link is the way to go. Clicking it gets you to a Sourceforge page, where you can click download which gets you to ap page where you can choose which version of pywin32 build 210 you want. Choose the exe that was built for the Python version (e.g. 2.5) you are using, download and run it to install pywin32. HTH, Jussi As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet I do not fear death. I had been dead for billions and billions of years before I was born, and had not suffered the slightest inconvenience from it. -- Mark Twain (a nod to evolution) -- Web Page: home.earthlink.net/~mtnviews -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
W. Watson schrieb: As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. This is the python interpreter for windows: http://www.python.org/ftp/python/2.5/python-2.5.msi Here you can check for editors: http://wiki.python.org/moin/PythonEditors Here you will get the pywin32 package (also including the Win32 API, COM support, and Pythonwin): http://sourceforge.net/projects/pywin32/ I am not sure if you actually read any of our posts, because there is no 404 whatsoever. On none of the posted links in the whole thread. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: How to invoke parent's method?
On 7 Jan 2007 01:33:32 -0800, Frank Millman [EMAIL PROTECTED] wrote: The essential point is that you save a reference to the frame when you create the panel. Then when the button is clicked you can use the reference to call the frame's Close method. Or you could look into Dabo. This is one of those common needs that has been built into the framework. Any object on a form (a wx.Frame) can simple reference 'self.Form' to get a reference to the containing frame. Controls that are contained within other controls (such as inside panels or notebook pages) can always reference that container with 'self.Parent'. -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
[EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. But if you are that stupid, should you be programming in any language? The most widely used language is still C, and there is no concept of private data in C either, nor is it needed. As mentioned in other replies, it is not rocket science to access a class private data. In C++ you can cast to void*, in Java and C# you can use reflection. C++ is said to be an unsafe language because programmers can, using a few tricks, mess with the vtables. But how many really do that? In Python variables are kept in strict namespaces. You can ask the compiler to name mangle a variable by prepending underscores. The variable then becomes just as 'private' as a C++ private variable, because as previously mentioned, 'private' variables in C++ can be accessed through a cast to void*. -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to learn
Thanks for the links guys!! Dive into Python is great and I am subscribing to tutor as well. Thomas Ploch wrote: [EMAIL PROTECTED] schrieb: Hi, I have been programming in the .net environment and ide for a few years and I am looking to make the switch over to python. I have absolutely no python experience whatsoever. I am looking for a python guru who has instant messenger or gtalk or whatever who can meet me online in the mornings, give me some direction for the day and then answer some questions here and there online throughout the day. So you are looking for a person (no, a guru), that stays by your side the whole day, gives you answers and helps you learning python. This is a ridiculous request. If you want to learn python, you should start with visiting http://www.diveintopython.org/ and read it. If you have previous programming experience, this is the place to start. Sorry to interrupt the group but since all python gurus appear to be happily at work on the next level apps at google nobody responded to my craigslist ads. You can always ask your questions here on the list, there are enough people that are willing to help. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: where is python on linux?
on linux type: whereis python You should get a list of directories where all of python lives. jim-on-linux http:\\www.inqvista.com On Sunday 07 January 2007 04:05, Frank Potter wrote: I installed fedora core 6 and it has python installed. But the question is, where is the executable python file? I can't find it so I come here for help. I want to config pydev for eclipse and I need to know where the ececutable python file is. Thank you! -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin wrote: class A: __x = 3 class B(A): __x = 4 # ok class C(B): __x = 5 # oops! Consider that the above three class definitions might be in separate files and you see how clumsy this gets. What are you trying to show with the above? The principal benefit of using private attributes set on either the class or the instance is to preserve access, via self, to those attributes defined in association with (or within) a particular class in the inheritance hierarchy, as opposed to providing access to the most overriding definition of an attribute. This is demonstrated more effectively with a method on class A: class A: __x = 3 def f(self): print self.__x # should always refer to A.__x class B(A): __x = 4 class C(B): __x = 5 Here, instances of A, B and C will always print the value of A.__x when the f method is invoked on them. Were a non-private attribute to be used instead, instances of A, B and C would print the overridden value of the attribute when the f method is invoked on them. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
sturlamolden schrieb: [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. But if you are that stupid, should you be programming in any language? The most widely used language is still C, and there is no concept of private data in C either, nor is it needed. There is a kind of this concept in C with 'static' declarations. As mentioned in other replies, it is not rocket science to access a class private data. In C++ you can cast to void*, in Java and C# you can use reflection. C++ is said to be an unsafe language because programmers can, using a few tricks, mess with the vtables. But how many really do that? Exactly, if they were available, a lot more would do that. I think this is the point. Programmers who can do that normally are sensible towards that people who have designed this or that knew what they were doing. But there are enough people that don't have a clue and _will_ fiddle around and then flame all kind of mailing lists with requests for help cause they did it wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: c# application calling Scipy
[EMAIL PROTECTED] wrote: Hi, Novice here. :) I'm building a c# application and I want to call functions in SciPy from that application. What's the best way to call SciPy methods from a C# program? You need to: 1. Embed a Python interpreter in your C# app. That is, importing from a DLL with a Python interpreter and defining a few structs. 2. Define a NumPy ndarray as a C# struct. Or: 1. Write a proxy DLL in C and embed Python in that. This is the preferred way, as I see it. You are relieved of having to redefine Python and NumPy's C structs in C#. 2. Import your proxy in C# and marshal a C# array to a IntPtr. That will allow you to map a C# array to a NumPy ndarray C struct in your proxy. The latter method is less hassle. In any case you also need to make sure you are using a .NET runtime that are linked to the same CRT as Python (.NET 1.1 should work). Using IronPython will not work, as neither NumPy nor SciPy is ported to IronPython (and porting is not trivial either; but if you take the task upon yourself, many will be happy if you succeeed.) -- http://mail.python.org/mailman/listinfo/python-list
Re:[OT] (newbie) Is there a way to prevent name redundancy in OOP ?
Martin Miller a écrit : (snip) Oh, contrair. I guess you mean au contraire ?-) (snip) -- http://mail.python.org/mailman/listinfo/python-list
Re: low level python read's
In [EMAIL PROTECTED], gz wrote: So how do i stop python from trying to be smart and just read *at most* 1000 chars and let it go if he(it?*) reads less? For low level file stuff use the functions in the `os` module, i.e. `os.read()`. p.s *is python a he or an it? I'd say it. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Andrea Griffini a écrit : Paul Rubin wrote: Yes I've had plenty of pointer related bugs in C programs that don't happen in GC'd languages, so GC in that sense saves my ass all the time. My experience is different, I never suffered a lot for leaking or dangling pointers in C++ programs; and on the opposite I didn't expect that fighting with object leaking in complex python applications was that difficult (I've heard of zope applications that just gave up and resorted to the reboot every now and then solution). Zope is a special case here, since it relies on an object database... -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Paul Rubin a écrit : Felipe Almeida Lessa [EMAIL PROTECTED] writes: What is the chance of having to inherit from two classes from different modules but with exactly the same name *and* the same instance variable name? Of course you're being very pessimistic or extremely unlucky. If you want to write bug-free code, pessimism is the name of the game. Not to pretend my own code is always totally bug-free, but I found that, with languages like Python, I usually got better results starting with the simplest possible implementation, and only then adding some 'defensive' boilerplate where it makes sens (that is mostly resources acquisition/release) - an approach that I would certainly not advocate when it comes to coding in C... -- http://mail.python.org/mailman/listinfo/python-list
Re: still struggling, howto use a list-element as a name ? Sory, hit send button to early
Stef Mientki ha escrito: class LED (device): pinlist ={ # pinname type init-value other-parameters 1: ('Cathode', _DIG_IN, [], _par2), 2: ('Anode', _DIG_OUT, [], _par33) } Status = {True:('On'), False:('Off')} def execute (self): old = self.On self.On = (~self.Cathode.Value self.Anode.Value) 0 if self.On old : print self.Name, self.Status[self.On] I don't know of what type are those values (certainly the're not [] because ~[] won't work). But note that using ~ with apparently logical values doesn't work as expected. The operators ,|,^,~ are meant to be used on integers, and work bit by bit. The operators and, or, xor, not operate on logical, or boolean, values. py value = True py negvalue = ~value py if negvalue: print oops! ... oops! py bool(negvalue) True If you want to express the condition The led is ON when the value of Anode is 0 and the value of Cathode is 0 that would be self.On = self.Anode.Value0 and self.Cathode.Value0 but since I don't know the types of values involved I'm not sure if this expression is right. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
Mark Elston ha escrito: If you have a Python installation you should be able to find the Whats New section of the docs. List comprehensions are described pretty well in the What's new in Python 2.0? section. This gives some simple examples as well as the rationale behind them. Where do you find the What's new for previous releases? I have to read them online. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: AES256 in PyCrypto
[ [EMAIL PROTECTED] [EMAIL PROTECTED] ] Marc 'BlackJack' Rintsch wrote: `a` must be of length 32 for AES256. And the length of `plainText` must be a multiple of 16 because it's a block cypher algorithm. Thank you. I have some follow up questions and 1 tangential question. Follow up question: Would it be correct to infer that: a) the AES.pyd extension module (plus whatever additional files within the PyCrypto package that it uses) has the capability to perform AES256 encryption? b) the AES256 encryption happens based on the characteristics of the input to the new() method...if the first argument has a length of 32, the result will be AES256-style encryption? Since you are apparently unable to read to docstrings of this module, I will give you a short hint: yes, pycrypto supports AES with 256 bit keys. c) will AES256-style encryption also happen if the first argument to the new() method has a length that is a multiple of 32, e.g. 64? Why didn't you try this? It would have answered your question: [12]-- AES.new(os.urandom(64), AES.MODE_CBC, os.urandom(16)) --- exceptions.ValueErrorTraceback (most recent call last) /home/lunar/ipython console ValueError: AES key must be either 16, 24, or 32 bytes long Tangential question: Is there functionality available (either in the PyCrypto package or some other package) that generates an initialization vector that can be used as input to the new() method? What prompts this question is that the original posting referenced a snippet of C# code; some other related snippets I saw seemed to suggest that: a) a RijndaelManaged() class gets instantiated b) that class has a GenerateIV() method which appears to populate someting in a IV property c) the application that was employing the AES256 encryption made use of the left-most 16 characters of the IV property So, I was curious whether something analgous exists in the Python world. os.urandom will be your friend... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
[ Thomas Ploch [EMAIL PROTECTED] ] sturlamolden schrieb: [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. But if you are that stupid, should you be programming in any language? The most widely used language is still C, and there is no concept of private data in C either, nor is it needed. There is a kind of this concept in C with 'static' declarations. As mentioned in other replies, it is not rocket science to access a class private data. In C++ you can cast to void*, in Java and C# you can use reflection. C++ is said to be an unsafe language because programmers can, using a few tricks, mess with the vtables. But how many really do that? Exactly, if they were available, a lot more would do that. I think this is the point. Programmers who can do that normally are sensible towards that people who have designed this or that knew what they were doing. But there are enough people that don't have a clue and _will_ fiddle around and then flame all kind of mailing lists with requests for help cause they did it wrong. Those people deserve to fail for being just extraordinary stupid... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
On 7 ene, 13:22, W. Watson [EMAIL PROTECTED] wrote: https://sourceforge.net/projects/pywin32/ As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. The above link should work. Follow the instructions in a previous post. Note that in the last step, you have to choose a mirror for downloading; that mirrow might be down or out-of-sync so you might get an error there. Choose another mirrorr... Note that you dont *need* PythonWin in order to use Python on Windows. The standard Python distribution works fine. Even includes a Python editor (IDLE) but you can use whichever editor you like to write your code (even Notepad...) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Sebastian 'lunar' Wiesner schrieb: Those people deserve to fail for being just extraordinary stupid... Yes, but there are a lot of them around... Thomas P.S.: I don't mean they are around here. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie XML SAX Parsing: How do I ignore an invalid token?
Thanks, I'll work with the file on the file system, then parse it with SAX. Is there a Pythonic way to read the file and identify any illegal XML characters so I can strip them out? this would keep my program more flexible - if the vendor is going to allow one illegal character in their document, there's no way of knowing if another one will pop up later. Thanks! Martin v. Löwis wrote: [EMAIL PROTECTED] schrieb: My original posting has a funky line break character (it appears as an ascii square) that blows up my program, but it may or may not show up when you view my message. Looking at your document, it seems that this funky line break character is character \x1E, which, in latin-1, means record separator. It's indeed ill-formed to use it in XML. Is there a way to account for the invalid token in the error handler? Not with a standard XML parser, no. The error you describe is a fatal error, and that's not something parsing can recover from. I recommend that you filter this character out before passing it to the XML parser. You can use the IncrementalParser interface to do so. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Recommended way to force a thread context switch?
On 6 ene, 20:01, Lloyd Zusman [EMAIL PROTECTED] wrote: It seems that the original writer of the app had set this interval to a high value in a part of the code that I overlooked until you mentioned this right now. [...] once one of the big number-crunching threads gets control, it starves out the monitoring threads, which is not a good thing for my app ... or at least it did so with the original large checkinterval. This is why such settings should be in a configuration file or in a prominent place in the application... I had a program where, deep in an unknown function, the original coder changed the process priority - with no valid reason, and in any case, that should be an application-level setting. It was hard to find why, after doing such and such things, the system responsiveness were so slow. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
sturlamolden wrote: [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. If you're not clear on encapsulation issues, you probably haven't done extensive maintenance programming on code written by others. Finding out who can mess with a variable when debugging the code of others is not fun. Because Python doesn't have explicit declarations, scope of variables is a touchy issue. If you write x = 1 within a function, that will create a local x if x doesn't exist, or alter a global x if x was previously created in the global context. But at least global variables are local to the namespace; we don't have clashes across files. So it's not too bad. JavaScript has the convention that newly created variables are global by default. Big mistake. The underscore thing makes sense. Single underscore variables are protected in the C++ sense, and double underscore variables are private, not visible from inherited classes. It's hard to misuse such variables by accident. I'd be tempted to prohibit access to underscore variables other than via self._x forms, so they'd be inaccessable outside the object. It's undesirable from a maintenance standpoint to have an unenforced convention like a lead underscore. The maintenance programmer can't trust its meaning. As Python grows up, and larger systems are written in it, these issues become more important. John Nagle Animats -- http://mail.python.org/mailman/listinfo/python-list
urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5
urllib.quote chokes on unicode in 2.4.4. print sys.version 2.4.4 (#1, Oct 18 2006, 10:34:39) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] urllib.quote(u\xe9) Traceback (most recent call last): File stdin, line 1, in ? File /Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py, line 1117, in quote res = map(safe_map.__getitem__, s) KeyError: u'\xe9' but it seems to work in Python 2.3.5 Python 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type help, copyright, credits or license for more information. import sys, urllib print sys.version 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] urllib.quote(u'\xe9') '%E9' Is this a known bug? What's the workaround? Thanks, nyenyec -- http://mail.python.org/mailman/listinfo/python-list
Re: find a .py path
On 5 ene, 13:33, Laszlo Nagy [EMAIL PROTECTED] wrote: Be aware with this. It is different when you do /usr/bin/python prog.py and ./prog.py In the first case, sys.argv[0] will be /usr/bin/python! No, sys.argv[0] is always the running script, and sys.argv[1] the first argument after the script, and so on. It doesn't matter if you call python implicitely, or with other options. Try this: /usr/bin/python -i -u -O prog.py -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: A problem in embedding Python in a plug-in
On 6 ene, 15:29, Koichi [EMAIL PROTECTED] wrote: Hi, I'm now making a plug-in for a CG software. I embed Python in a plugin and it works. The problem is that it conflicts with other plugins that also embeds Python because it runs in the same thread. I don't know when Py_Initialize() and Given all those constraints, I think the only safe option is to run Python in another process. You write a very simple plugin (NOT in Python, maybe C code) that spawns another process (the actual Python code) and forwards all requests to that other process, using some form of IPC. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
OpenBSD, Apache and Python
Hi! I'm wanting to use openbsd to run a webserver because of its high security. The website is written in python. Before I was using linux with apache 2 and mod_python and this worked well. My problem is that mod_python 3.x does not work on apache 1 which is what comes with openbsd (and has been hardened buy the openbsd guys). One option is to use mod_python 2.x, but this has not seen any development since 2004. I'm now looking at using fastcgi to run my python. This looks like it's going to work fine, though I will be using a fcgi interface such as http://jonpy.sourceforge.net/. There does not seem to be any official fastcgi module for python. Should I be worried about the stability and security of the python fcgi interfaces? Is there something better (more mature / battle tested)? Are there any other options available to me - considering that security is very important? Thanks for any help, Geoff -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
Gabriel Genellina wrote: On 7 ene, 13:22, W. Watson [EMAIL PROTECTED] wrote: https://sourceforge.net/projects/pywin32/ As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. The above link should work. Follow the instructions in a previous post. Note that in the last step, you have to choose a mirror for downloading; that mirrow might be down or out-of-sync so you might get an error there. Choose another mirrorr... Note that you dont *need* PythonWin in order to use Python on Windows. The standard Python distribution works fine. Even includes a Python editor (IDLE) but you can use whichever editor you like to write your code (even Notepad...) We seem to be looping. I have the Python interpreter. I would like the pythonwin editor. The download link doesn't work on SourceForge. Where can I get it? If not there, where? If it can't be obtained, then I'll go to the default editor built into python-2.5.msi. Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet I do not fear death. I had been dead for billions and billions of years before I was born, and had not suffered the slightest inconvenience from it. -- Mark Twain (a nod to evolution) -- Web Page: home.earthlink.net/~mtnviews -- http://mail.python.org/mailman/listinfo/python-list
Re: urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5
encode seems to solve my problem: urllib.quote(u'\xe9'.encode('utf-8')) '%C3%A9' Cheers, nyenyec nyenyec wrote: urllib.quote chokes on unicode in 2.4.4. print sys.version 2.4.4 (#1, Oct 18 2006, 10:34:39) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] urllib.quote(u\xe9) Traceback (most recent call last): File stdin, line 1, in ? File /Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py, line 1117, in quote res = map(safe_map.__getitem__, s) KeyError: u'\xe9' but it seems to work in Python 2.3.5 Python 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type help, copyright, credits or license for more information. import sys, urllib print sys.version 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] urllib.quote(u'\xe9') '%E9' Is this a known bug? What's the workaround? Thanks, nyenyec -- http://mail.python.org/mailman/listinfo/python-list
Re: Python re expr from Perl to Python
Michael M. [EMAIL PROTECTED] wrote: In Perl, it was: ## Example: Abc | def | ghi | jkl ## - Abc ghi jkl ## Take only the text betewwn the 2nd pipe (=cut the text in the 1st pipe). $na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g; ## -- remove [ and ] in text $na =~ s/\[//g; $na =~ s/\]//g; # print DEB: \$na\\n; # input string na=Abc | def | ghi | jkl [gugu] # output na=Abc ghi jkl gugu How is it done in Python? import re na=Abc | def | ghi | jkl [gugu] m=re.match(r'(\w+ )\| (\w+ )\| (\w+ )\| (\w+ )\[(\w+)\]', na) na=m.expand(r'\1\2\3\5') na 'Abc def ghi gugu' Florian -- http://www.florian-diesch.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5
On 7 ene, 15:48, nyenyec [EMAIL PROTECTED] wrote: urllib.quote chokes on unicode in 2.4.4. urllib.quote(u\xe9) KeyError: u'\xe9' but it seems to work in Python 2.3.5 Is this a known bug? See some recent posts about urllib.unquote and unicode -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
On 7 ene, 16:20, W. Watson [EMAIL PROTECTED] wrote: We seem to be looping. I have the Python interpreter. I would like the pythonwin editor. The download link doesn't work on SourceForge. Where can I get it? If not there, where? If it can't be obtained, then I'll go to the default editor built into python-2.5.msi. It *does* work for me. Try https://sourceforge.net/project/showfiles.php?group_id=78018package_id=79063 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie XML SAX Parsing: How do I ignore an invalid token?
[EMAIL PROTECTED] schrieb: Is there a Pythonic way to read the file and identify any illegal XML characters so I can strip them out? this would keep my program more flexible - if the vendor is going to allow one illegal character in their document, there's no way of knowing if another one will pop up later. Notice that you are talking about bytes here, not characters. It is inherently difficult to determine invalid bytes - you first have to determine the encoding, then (mentally) decode, and then find out whether there are any invalid characters. The invalid XML characters can be found in http://www.w3.org/TR/2006/REC-xml-20060816/#charsets So invalid characters are #x0 .. #x8, #xB, #xC, #xE .. #x1F, #xD800 .. #xDFFF, #xFFFE, #x. If you restrict attention to only the invalid characters below #x20 (i.e. control characters), and also restrict attention to encodings that are strict ASCII supersets (ASCII, ISO-8859-x, UTF-8), you can filter out the invalid characters on the byte level. Otherwise, you have to decode, filter out on the character level, and then encode again. Neither approach will deal with bytes that are invalid wrt. the encoding. To filter out these bytes, I recommend to use str.translate. Make an identity table for the substitution, and put the bytes you want deleted into the delete table. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5
nyenyec [EMAIL PROTECTED] wrote: but it seems to work in Python 2.3.5 Python 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin Type help, copyright, credits or license for more information. import sys, urllib print sys.version 2.3.5 (#1, Aug 19 2006, 21:31:42) [GCC 4.0.1 (Apple Computer, Inc. build 5363)] urllib.quote(u'\xe9') '%E9' 'seems to' is correct: it should *probably* have given you '%C3%E9'. Is this a known bug? What's the workaround? UTF-8 encode the url before quoting it. *Some* web servers may not expect utf-8 encoding. utf-8 is the recommended encoding, but unfortunately it isn't actually required, so a few (mostly old) servers may expect something else. If so, use the appropriate encoding for the server. -- http://mail.python.org/mailman/listinfo/python-list
Capturing stderr and stdout of a subprocess as a single stream
Hello all, Before I ask the question a couple of notes : * This question is for implementing a script inside the Wing IDE. For some reason using the subprocess module doesn't work so I need a solution that doesn't use this module. * The platform is Windows and I'm happy with a Windoze only solution. :-) I would like to execute subprocesses asynchronously and capture stdout / stderr as a single stream. If I use os.popen3(executable) it gives me separate pipes for stdout and stderr, but reads from them are blocking. The output on stdout and stderr may be interleaved and I would like to display them *as* they arrive. That means I can't just read from them and output the results. The only solution I can think of is to read from both a character at a time on two separate threads, putting the data into a queue. A separate thread could pull characters off the queue and display them. (I don't need to differentiate between stdout and stderr when I display.) Can anyone think of a better solution ? My current code works, but *doesn't* capture stderr : from threading import Thread pipe = os.popen(executable) def DisplayOutput(): while True: output = pipe.read(1) if not output: break display(output) Thread(target=DisplayOutput).start() All the best, Fuzzyman http://www.voidspace.org.uk/python/articles.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Bruno Desthuilliers wrote: ... and on the opposite I didn't expect that fighting with object leaking in complex python applications was that difficult (I've heard of zope applications that just gave up and resorted to the reboot every now and then solution). Zope is a special case here, since it relies on an object database... Just to clarify my post... I found by being punched myself in the nose what does it mean to have a complex python application that suffers from object leaking; it's not something I only read about zope programs. But why zope applications would be a special case ? Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
Gabriel Where do you find the What's new for previous releases? I Gabriel have to read them online. Google for what's new site:python.org Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Traceback of hanged process
On 6 ene, 19:45, Hynek Hanke [EMAIL PROTECTED] wrote: please, how do I create a pythonic traceback from a python process that hangs and is not running in an interpreter that I executed manually or it is but doesn't react on CTRL-C etc? I'm trying to debug a server implemented in Python, so I need some analog of 'gdb attach' for C. On Windows, Pythonwin has an option Break into running code. Try starting the script with python -i, and send it a signal.. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Python re expr from Perl to Python
Florian Diesch schrieb: Michael M. [EMAIL PROTECTED] wrote: In Perl, it was: ## Example: Abc | def | ghi | jkl ## - Abc ghi jkl ## Take only the text betewwn the 2nd pipe (=cut the text in the 1st pipe). $na =~ s/\ \|(.*?)\ \|(.*?)\ \|/$2/g; ## -- remove [ and ] in text $na =~ s/\[//g; $na =~ s/\]//g; # print DEB: \$na\\n; # input string na=Abc | def | ghi | jkl [gugu] # output na=Abc ghi jkl gugu How is it done in Python? import re na=Abc | def | ghi | jkl [gugu] m=re.match(r'(\w+ )\| (\w+ )\| (\w+ )\| (\w+ )\[(\w+)\]', na) na=m.expand(r'\1\2\3\5') na 'Abc def ghi gugu' I'd rather have the groups grouped without the whitespaces import re na=Abc | def | ghi | jkl [gugu] m=re.match(r'(\w+) \| (\w+) \| (\w+) \| (\w+) \[(\w+)\]', na) na=m.expand(r'\1 \3 \4 \5') na 'Abc ghi jkl gugu' Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
On 7 ene, 16:34, [EMAIL PROTECTED] wrote: Gabriel Where do you find the What's new for previous releases? I Gabriel have to read them online. Google for what's new site:python.org That's what I do. But this post: If you have a Python installation you should be able to find the Whats New section of the docs. List comprehensions are described pretty well in the What's new in Python 2.0? section. suggested that one could find that info inside the Python installation, and I was asking *where*, because I can't find it, and I suspect it actually isn't there. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
Gabriel Where do you find the What's new for previous releases? I Gabriel have to read them online. Google for what's new site:python.org Sorry, I took I have to read them online to mean that you needed to read them online because (perhaps) you don't have a source distribution on your computer. My 2.5 source (Subversion sandbox) has 2.0 through 2.5 What's New source in Doc/whatsnew. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Just Getting Started with Python on MS XP Pro
W. Watson kirjoitti: Gabriel Genellina wrote: On 7 ene, 13:22, W. Watson [EMAIL PROTECTED] wrote: https://sourceforge.net/projects/pywin32/ As I understand it, there are two files I'm after: 1. python interpreter, and 2. a python editor. It's #2 that I'm having trouble downloading. The link is broken. The above link should work. Follow the instructions in a previous post. Note that in the last step, you have to choose a mirror for downloading; that mirrow might be down or out-of-sync so you might get an error there. Choose another mirrorr... Note that you dont *need* PythonWin in order to use Python on Windows. The standard Python distribution works fine. Even includes a Python editor (IDLE) but you can use whichever editor you like to write your code (even Notepad...) We seem to be looping. I have the Python interpreter. I would like the pythonwin editor. The download link doesn't work on SourceForge. Where can I get it? If not there, where? If it can't be obtained, then I'll go to the default editor built into python-2.5.msi. Wayne T. Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet I do not fear death. I had been dead for billions and billions of years before I was born, and had not suffered the slightest inconvenience from it. -- Mark Twain (a nod to evolution) Trying to break the loop: The above link works for me. I've tried it numerous times during this looping. Clicking the link pops up a security warning informing that the browser is going to enter https mode. Do you get that pop-up? When I accept the pop-up, I get a page containing a green rectangle button. When I click it, I get another page in which I have to click download to go to the actual download page. If this doesn't work for you there must be something wrong with your configuration. HTH, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing stderr and stdout of a subprocess as a single stream
On 7 ene, 16:33, Fuzzyman [EMAIL PROTECTED] wrote: Hello all, Before I ask the question a couple of notes : * This question is for implementing a script inside the Wing IDE. For some reason using the subprocess module doesn't work so I need a solution that doesn't use this module. * The platform is Windows and I'm happy with a Windoze only solution. :-) I would like to execute subprocesses asynchronously and capture stdout / stderr as a single stream. If I use os.popen3(executable) it gives me separate pipes for stdout and stderr, but reads from them are blocking. The output on stdout and stderr may be interleaved and I would like to display them *as* they arrive. That means I can't just read from them and output the results. The only solution I can think of is to read from both a character at a time on two separate threads, putting the data into a queue. A separate thread could pull characters off the queue and display them. (I don't need to differentiate between stdout and stderr when I display.) Can anyone think of a better solution ? My current code works, but *doesn't* capture stderr : from threading import Thread pipe = os.popen(executable) def DisplayOutput(): while True: output = pipe.read(1) if not output: break display(output) Thread(target=DisplayOutput).start() All the best, Fuzzymanhttp://www.voidspace.org.uk/python/articles.shtml Try using popen4 instead. But since you already have a thread, it may be better to use popen2 and two threads to read from stdout and stderr to avoid a potential deadlock; they can put read lines into a Queue, and DisplayOutput just get these lines in order. (See the warnings in the popen2 module documentation). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Thomas Ploch a écrit : sturlamolden schrieb: (snip) As mentioned in other replies, it is not rocket science to access a class private data. In C++ you can cast to void*, in Java and C# you can use reflection. C++ is said to be an unsafe language because programmers can, using a few tricks, mess with the vtables. But how many really do that? Exactly, if they were available, a lot more would do that. Do you have any concrete evidence ? FWIW, I've seen a *lot* of Python code, and very very few uses of _implementation stuff - most of them being legitimate. I think this is the point. Programmers who can do that normally are sensible towards that people who have designed this or that knew what they were doing. But there are enough people that don't have a clue and _will_ fiddle around and then flame all kind of mailing lists with requests for help cause they did it wrong. The fact is that there's no cure for stupidity. If you want a language explicitly designed to protect dummies from themselves, you know where to find it. Why should normally intelligent peoples have to suffer from this ? Are you going to forbid hammers because dummies could smash their fingers then complain ? -- http://mail.python.org/mailman/listinfo/python-list
Re: where is python on linux?
Frank Potter a écrit : I installed fedora core 6 and it has python installed. But the question is, where is the executable python file? I can't find it so I come here for help. man which -- http://mail.python.org/mailman/listinfo/python-list
Re: OpenBSD, Apache and Python
Geoff schrieb: I'm now looking at using fastcgi to run my python. This looks like it's going to work fine, though I will be using a fcgi interface such as http://jonpy.sourceforge.net/. There does not seem to be any official fastcgi module for python. Should I be worried about the stability and security of the python fcgi interfaces? Is there something better (more mature / battle tested)? Certainly: CGI. Performance does not seem to be an issue, so CGI should work just fine. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
On 7 ene, 16:13, John Nagle [EMAIL PROTECTED] wrote: Because Python doesn't have explicit declarations, scope of variables is a touchy issue. If you write x = 1 within a function, that will create a local x if x doesn't exist, or alter a global x if x was previously created in the global context. But at least global variables are local to the namespace; we don't have clashes across files. No, `x=1` always uses a local variable x, unless an (explicit!) global statement was in effect in the same block. This, and the explicit self, make very clear which x you are referring to. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing stderr and stdout of a subprocess as a single stream
Gabriel Genellina wrote: On 7 ene, 16:33, Fuzzyman [EMAIL PROTECTED] wrote: [snip..] My current code works, but *doesn't* capture stderr : from threading import Thread pipe = os.popen(executable) def DisplayOutput(): while True: output = pipe.read(1) if not output: break display(output) Thread(target=DisplayOutput).start() All the best, Fuzzyman http://www.voidspace.org.uk/python/articles.shtml Try using popen4 instead. But since you already have a thread, it may be better to use popen2 and two threads to read from stdout and stderr to avoid a potential deadlock; they can put read lines into a Queue, and DisplayOutput just get these lines in order. (See the warnings in the popen2 module documentation). popen4 works great, I didn't even know it existed. Two threads and a queue sounds horrible. Thanks Fuzzyman http://www.voidspace.org.uk/python/articles.shtml -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
Andrea Griffini a écrit : Bruno Desthuilliers wrote: ... and on the opposite I didn't expect that fighting with object leaking in complex python applications was that difficult (I've heard of zope applications that just gave up and resorted to the reboot every now and then solution). Zope is a special case here, since it relies on an object database... Just to clarify my post... I found by being punched myself in the nose what does it mean to have a complex python application that suffers from object leaking; it's not something I only read about zope programs. But why zope applications would be a special case ? 1/ because of how Zope and the ZODB work 2/ because Zope is an unusually complex Python application. FWIW, I've never had any memory problem with other Python applications and/or frameworks I've used so far (ie: in the past seven years) - most of them being somewhat 'simpler' than if they had been implemented in C or C++... -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing stderr and stdout of a subprocess as a single stream
On 7 ene, 17:37, Fuzzyman [EMAIL PROTECTED] wrote: Two threads and a queue sounds horrible. But unfortunately it's the only way if you don't control how the child process behaves. (It's not s ugly afterwards... certainly would be worse if you had to syncronize both reading threads and the display thread using semaphores by hand.) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
audio video streaming communications
Hello, I am looking for a good audio/video conferencing library. Ideally it should work with wxPython (or have some means of making it work there). So far my main difficulty in my attempt at searching for such a package is that there is so much stuff out there on downloading music and videos. I am not interested in download torrents, etc. I'm just looking video conferencing, and live video broadcasts, etc. Any recommendations? Thanks, - Ken -- http://mail.python.org/mailman/listinfo/python-list
Python cheatsheets
Curious if anyone has a python cheatsheet* published? I'm looking for something that summarizes all commands/functions/attributes. Having these printed on a 8 x 11 double-sided laminated paper is pretty cool. * cheatsheet probably isn't the right word, but you get the idea. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Re:[OT] (newbie) Is there a way to prevent name redundancy in OOP ?
Bruno Desthuilliers wrote: Martin Miller a écrit : (snip) Oh, contrair. I guess you mean au contraire ?-) (snip) FWIW contrair is how it's spelled in the Oxford English dictionary (I actually did look it up before posting because it seemed like there ought be an 'e' on the end). The dictionary also says it's chiefly Scottish but the etymology indicates from the Old French contraire. Technically I suppose I should have written Oh, *on* contrair or better yet just On the contrary. ;-) -Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python cheatsheets
gonzlobo kirjoitti: Curious if anyone has a python cheatsheet* published? I'm looking for something that summarizes all commands/functions/attributes. Having these printed on a 8 x 11 double-sided laminated paper is pretty cool. * cheatsheet probably isn't the right word, but you get the idea. :) http://rgruet.free.fr/ HTH, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: AES256 in PyCrypto
Sebastian 'lunar' Wiesner wrote: Since you are apparently unable to read to docstrings of this module, I will give you a short hint: yes, pycrypto supports AES with 256 bit keys. Thank you for the information. The material I consulted was: a) the PyCrypto manual: http://www.amk.ca/python/writing/pycrypt/ b) the .py files that shipped with the PyCrypto package Is a docstring is the text between the three consecutive quote characters in a .py file? The reason for the question is that I looked at the .py files that shipped with PyCrypto. Of the various .py files that shipped with PyCrypto, there were two files (both __init__.py) that contained information seemed to pertain to AES. The stuff between the 3 consecutive quote chars in: Crypto.__init__.py Crypto.Cipher.__init__.py make reference to AES, but I wasn't able to determine from what I read if that was AES256. Which .py file contain the docstrings that flesh out the information summarized in the short hint? Can docstrings be embedded within the .pyd extension modules as well? Does the AES.pyd extension module have docstrings? How does one view the docstrings in a .pyd file? When I reference AES from the interactive of Pythonwin: from Crypto.Cipher import AES x = AES.new( As soon as I type the '(' character, the IDE displays: new(key, [mode], [IV]): Return a new AES encryption object then when x gets instantiated, and the encrypt method gets called... x.encrypt( As soon as I type the '(' character, the IDE displays: Encrypt the provided string of binary data I'm guessing that what the IDE is displaying is the first line of what may be multiple-line docstring that is embedded within the .pyd extension module? Might there be more lines in the docstring? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python cheatsheets
gonzlobo wrote: Curious if anyone has a python cheatsheet* published? I'm looking for something that summarizes all commands/functions/attributes. Having these printed on a 8 x 11 double-sided laminated paper is pretty cool. * cheatsheet probably isn't the right word, but you get the idea. :) Richard Gruet publishes an excellent Quick Reference in multiple formats, available from http://rgruet.free.fr. -Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
Michael M. schrieb: How to find the longst element list of lists? I think, there should be an easier way then this: s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] if len(s1) = len(s2) and len(s1) = len(s3): sx1=s1 ## s1 ist längster if len(s2) = len(s3): sx2=s2 sx3=s3 else: sx2=s3 sx3=s2 if len(s2) = len(s3) and len(s2) = len(s1): sx1=s2 ## s2 ist längster if len(s3) = len(s1): sx2=s3 sx3=s1 else: sx2=s1 sx3=s3 if len(s3) = len(s1) and len(s3) = len(s2): sx1=s3 ## s3 ist längster if len(s1) = len(s2): sx2=s1 sx3=s2 else: sx2=s2 sx3=s1 After, the list ist sorted: sx1 = [a, b, c, d] sx2 = [q, e, d] sx3 = [a, b] I don't really get that. You have three lists, you want to sort them after their length. You should put them into one list. I think you should rather implement this as: list = [a1, s2, s3] list.sort(lambda x,y: cmp(len(y), len(x))) list [['a', 'b', 'c', 'd'], ['q', 'e', 'd'], ['a', 'b']] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
On 1/7/07, Michael M. [EMAIL PROTECTED] wrote: How to find the longst element list of lists? s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] s = [s1, s2, s3] s.sort(key=len, reverse=True) print s[0] is s3 print s[1] is s1 print s[2] is s2 sx1, sx2, sx3 = s print 'sx1:', sx1 print 'sx2:', sx2 print 'sx3:', sx3 -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python cheatsheets
gonzlobo wrote: Curious if anyone has a python cheatsheet* published? I'm looking for something that summarizes all commands/functions/attributes. Having these printed on a 8 x 11 double-sided laminated paper is pretty cool. * cheatsheet probably isn't the right word, but you get the idea. :) search: python quick reference e.g.: http://www.benyoonline.com/pqr/pqr24/PQR2.4.html Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Why less emphasis on private data?
John Nagle a écrit : sturlamolden wrote: [EMAIL PROTECTED] wrote: Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that if an object's 'internal' variables or states cannot be kept private, programmers get an irresistible temptation to mess with them in malicious ways. If you're not clear on encapsulation issues, encapsulation != data hiding you probably haven't done extensive maintenance programming on code written by others. I did. Finding out who can mess with a variable when debugging the code of others is not fun. # before class Toto(object): def __init__(self, x): self._x = x # after class Toto(object): def __init__(self, x): self._x = x @apply def _x(): def fget(self): return self._real_x def fset(self, value): import pdb; pdb.set_trace() self._real_x = value return property(**locals) This is of course a braindead implementation - a better one would use either the inspect module of the sys._getframe() hack to retrieve useful debug infos (left as an excercice to the reader...) Because Python doesn't have explicit declarations, scope of variables is a touchy issue. ??? If you write x = 1 within a function, that will create a local x if x doesn't exist, or alter a global x if x was previously created in the global context. Err... May I suggest you to read these two pages: http://docs.python.org/ref/assignment.html http://docs.python.org/ref/global.html#l2h-563 But at least global variables are local to the namespace; we don't have clashes across files. So it's not too bad. JavaScript has the convention that newly created variables are global by default. Unless preceded by the 'var' keyword... Big mistake. Mmm... which one ? The underscore thing makes sense. Single underscore variables are protected in the C++ sense, and double underscore variables are private, not visible from inherited classes. It's hard to misuse such variables by accident. I'd be tempted to prohibit access to underscore variables other than via self._x forms, so they'd be inaccessable outside the object. # foo.py class Foo(object): def __init__(self, x): self._x = x def __repr__(self): return Foo %s % self._x # bar.py def bar(self): self.y = self._x # baaz.py from foo import Foo from bar import bar Foo.bar = bar f = Foo([42]) f.bar() f.y.append('gotcha') print f It's undesirable from a maintenance standpoint to have an unenforced convention If it's a convention, it doesn't have to be inforced. If it's inforced, it's not a convention anymore. While we're at it, I've found it very valuable to be able to mess with implementation when doing maintenance on somewhat large (and somewhat messy) Python systems... like a lead underscore. The maintenance programmer can't trust its meaning. As Python grows up, and larger systems are written in it, these issues become more important. If you go that way, then you'll also want to introduce declarative static typing and remove all possibility to dynamically modify classes or add/replace attributes and/or methods on a per-instance basis. If you want Java, you know where to find it. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
Michael M. kirjoitti: How to find the longst element list of lists? I think, there should be an easier way then this: s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] snip After, the list ist sorted: sx1 = [a, b, c, d] sx2 = [q, e, d] sx3 = [a, b] s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] ss = ((len(s1), s1), (len(s2), s2), (len(s3), s3)) sx = [y for (x, y) in sorted(ss)[::-1]] print sx sx1, sx2, sx3 = sx print sx1, sx2, sx3 Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
how to find the longst element list of lists
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] if len(s1) = len(s2) and len(s1) = len(s3): sx1=s1 ## s1 ist längster if len(s2) = len(s3): sx2=s2 sx3=s3 else: sx2=s3 sx3=s2 if len(s2) = len(s3) and len(s2) = len(s1): sx1=s2 ## s2 ist längster if len(s3) = len(s1): sx2=s3 sx3=s1 else: sx2=s1 sx3=s3 if len(s3) = len(s1) and len(s3) = len(s2): sx1=s3 ## s3 ist längster if len(s1) = len(s2): sx2=s1 sx3=s2 else: sx2=s2 sx3=s1 After, the list ist sorted: sx1 = [a, b, c, d] sx2 = [q, e, d] sx3 = [a, b] -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
[EMAIL PROTECTED] writes: Gabriel Where do you find the What's new for previous releases? I Gabriel have to read them online. Google for what's new site:python.org Sorry, I took I have to read them online to mean that you needed to read them online because (perhaps) you don't have a source distribution on your computer. My 2.5 source (Subversion sandbox) has 2.0 through 2.5 What's New source in Doc/whatsnew. My SuSE installation has it as /usr/share/doc/packages/python/Misc/NEWS -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] (newbie) Is there a way to prevent name redundancy in OOP ?
Martin Miller a écrit : Bruno Desthuilliers wrote: Martin Miller a écrit : (snip) Oh, contrair. I guess you mean au contraire ?-) (snip) FWIW contrair is how it's spelled in the Oxford English dictionary (I actually did look it up before posting because it seemed like there ought be an 'e' on the end). The dictionary also says it's chiefly Scottish but the etymology indicates from the Old French contraire. Not that 'old' !-) It's still a common French word. au contraire is French for on the contrary, and au is prononced 'o' - hence my mistake. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange for loop construct
Mark Elston wrote: * Gabriel Genellina wrote (on 1/5/2007 12:49 PM): At Friday 5/1/2007 17:39, [EMAIL PROTECTED] wrote: wordfreq = [wordlist.count(p) for p in wordlist] I would expect for p in wordlist: wordfreq.append(wordlist.count(p)) I didn't know you could have an expression in the same line. That's known as a list comprehension and is roughly equivalent to your code. Section 5 of the tutorial covers them. http://docs.python.org/tut/node7.html If you have a Python installation you should be able to find the Whats New section of the docs. List comprehensions are described pretty well in the What's new in Python 2.0? section. This gives some simple examples as well as the rationale behind them. Shouldn't that same page be found on the python website? http://www.python.org/doc/2.0/ Any clue as to why it isn't? Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: how to find the longst element list of lists
Michael M. a écrit : How to find the longst element list of lists? For what definition of find ? You want the lenght of the longest sublist, it's index, or a reference to it ? I think, there should be an easier way then this: s1 = [q, e, d] s2 = [a, b] s3 = [a, b, c, d] Err... this makes three distinct lists, not a list of lists. if len(s1) = len(s2) and len(s1) = len(s3): sx1=s1 ## s1 ist längster if len(s2) = len(s3): sx2=s2 sx3=s3 else: sx2=s3 sx3=s2 (snip repeated code) Looks like it would be time to learn how to factor out repetitions... After, the list ist sorted: sx1 = [a, b, c, d] sx2 = [q, e, d] sx3 = [a, b] This is still not a list of lists. Now for the answer, sorted() is your friend: print sorted([s1, s2, s3], key=list.__len__, reverse=True) = [['a', 'b', 'c', 'd'], ['q', 'e', 'd'], ['a', 'b']] # Or if you really want sx1, sx2 and sx3: sx1, sx2, sx3 = sorted([s1, s2, s3], key=list.__len__, reverse=True) Is that easier enough ?-) -- http://mail.python.org/mailman/listinfo/python-list
Working with Excel inside Python
I have a .plt file (which is a tab delimited ASCII file) and I want to format it to get a .dbf with data in rows and columns, detele some rows/columns and substitute decimal '.' with ','. All this using Python (I'm using Pythonwin). The .plt file looks like this: * ISCST3 (02035): Tersa * MODELING OPTIONS USED: * CONCURBAN ELEV DFAULT * PLOT FILE OF ANNUAL VALUES FOR SOURCE GROUP: ALL * FOR A TOTAL OF 400 RECEPTORS. * FORMAT: (3(1X,F13.5),1X,F8.2,2X,A6,2X,A8,2X,I8.8,2X,A8) *X Y AVERAGE CONC ZELEV * ___ ___ ___ __ 430342.0 4580537.0 0.2542619.28 430842.0 4580537.0 0.2723314.72 431342.0 4580537.0 0.30566 2.84 431842.0 4580537.0 0.30379 0.21 432342.0 4580537.0 0.27413 1.13 432842.0 4580537.0 0.25462 0.00 433342.0 4580537.0 0.25114 0.00 433842.0 4580537.0 0.28779 0.00 434342.0 4580537.0 0.29707 0.00 434842.0 4580537.0 0.31067 0.00 I recorded a macro in Excel with the whole process, but when trying to translate it into Python I get syntax errors which I don't know how to solve. This is my python code: ## -- import win32com.client excel = win32com.client.Dispatch(Excel.Application) excel.Visible = 0 workbook=excel.Workbooks.Open('D:\AN00GALL.plt') excel.Columns(A:A).Select excel.Selection.Replace What:=., Replacement:=,, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False excel.Columns(A:A).Select excel.Selection.TextToColumns Destination:=Range(A1), DataType:=xlFixedWidth, _ FieldInfo:=Array(Array(0, 1), Array(2, 1), Array(14, 1), Array(29, 1), Array(42, 1), _ Array(53, 1), Array(59, 1), Array(71, 1), Array(79, 1)), ThousandsSeparator:= , _ TrailingMinusNumbers:=True excel.Selection.Delete Shift:=xlToLeft excel.Rows(1:6).Select excel.Selection.Delete Shift:=xlUp excel.Rows(2:2).Select excel.Selection.Delete Shift:=xlUp excel.Columns(A:C).Select excel.Selection.NumberFormat = 0.0 excel.Columns(D:D).Select excel.Selection.NumberFormat = 0.00 excel.ActiveWorkbook.SaveAs Filename:= _ D:\AN00GALL.dbf, FileFormat:= _ xlDBF4, CreateBackup:=False excel.Quit() ## -- Any ideas on what am I doing wrong? Thank you. -- http://mail.python.org/mailman/listinfo/python-list