ANN: Einführung in die Programmierung mit Python parts 5 and 6 (2 German ShowMeDo videos)
Summary: Lucas Holland and Marius Meinert continue their introductory German Python series, in this instalment they have released their 5th and 6th videos. German video descriptions: Operatoren und Datentypen In dieser Episode geht es um Operatoren und Datentypen, die eine Grundlage für die weiteren Episoden bilden. http://showmedo.com/videos/video?name=pythonHollandIntroToPython5_germanfromSeriesID=44 Objektorientierte Programmierung (OOP) In dieser Episode behandeln wir das Paradigma der objektorientierten Programmierung, auf welchem Python basiert. http://showmedo.com/videos/video?name=pythonHollandIntroToPython6_germanfromSeriesID=44 About Lucas Holland and Marius Meinert: This is Lucas and Marius' first ShowMeDo series and the have made our first non-English series. If you like their videos, please leave some words of encouragement and thanks for their efforts. About ShowMeDo.com: Free videos (we call them ShowMeDos) showing you how to do things. The videos are made by us and our users, for everyone. 72 of our 145 videos are for Python, with more to come. We'd love to have more contributions - would you share what you know? The founders, Ian Ozsvald, Kyran Dale http://ShowMeDo.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: 'IF' Syntax For Alternative Conditions
Gabriel Genellina [EMAIL PROTECTED] wrote: Note that most (if not all) Python keywords are lowercase. All keywords are lower case. and del from not while aselif globalorwith assertelse ifpass yield break exceptimportprint class exec inraise continue finally isreturn def for lambdatry 'None' is not entirely lowercase, and you cannot assign to it, but technically it isn't a keyword. -- http://mail.python.org/mailman/listinfo/python-list
Referencing vars, methods and classes by name
Greetings, Sorry for a newbiw question: what is a most elegant and/or effective way to reference vars, methods and classes by their names in Python? To illustrate, PHP code: $a = ''b'; $$a = $something; // assign to $b $$a($p1); // call function b($p1) $obj-$a(); // call method b() of the instance $obj What is the Python way of performing the same indirections? References to online docs/articles related to the subject are very welcome. Thank you! Konstantin -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
Quite forgot to add the obvious example (in PHP): $a = 'b'; $obj = new $a(); // instantiating class b() -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
Sagari [EMAIL PROTECTED] writes: $a = ''b'; $$a = $something; // assign to $b $$a($p1); // call function b($p1) $obj-$a(); // call method b() of the instance $obj What is the Python way of performing the same indirections? We would not do that. We don't (usually) use the interpreter symbol table as a dictionary (what in perl would be called a hash). Instead we use an actual dictionary. We might say d = {}# make an empty dictionary a = 'b' d[a] = something # assign to d['b'] some_functab[a](p1) # look up 'b' in some function table and call it For your last example we could say obj.getattr(a)() but even that is a bit ugly, depending. For your other examples there are gross hacks using the dictionaries that represent the local and global symbol tables, so we translate your examples fairly directly, but stylistically we'd usually stay away from that kind of thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
Sagari [EMAIL PROTECTED] writes: $a = 'b'; $obj = new $a(); // instantiating class b() Classes are first class objects in python: class b: . # define class b We could assign the class object to a variable a = b and make an instance: obj = a()# same as obj = b() Continuing that example we could make a dispatch table of classes: class b: ... class c: ... class d: ... table = [b, c, d]# 3 element array, each element is a class i = 1 a = table[i] # this means a = c obj = a()# instantiate c -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
En Thu, 08 Feb 2007 05:29:23 -0300, Paul Rubin http://phr.cx@NOSPAM.invalid escribió: Sagari [EMAIL PROTECTED] writes: $a = ''b'; $obj-$a(); // call method b() of the instance $obj What is the Python way of performing the same indirections? For your last example we could say obj.getattr(a)() but even that is a bit ugly, depending. Surely you meant to say getattr(obj, a)() -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading the tilde operator?
On Feb 8, 7:02 am, Dave Benjamin [EMAIL PROTECTED] wrote: Neil Cerutti wrote: There's been only one (or two?) languages in history that attempted to provide programmers with the ability to implement new infix operators, including defining precedence level and associativity (I can't think of the name right now). You're probably thinking of SML or Haskell. OCaml also allows you to define new infix operators, but the associativities are fixed (and determined by what punctuation you use). Also some flavours of Prolog, as descrived in the classic book by Clocksin Mellish. Regarding the OP, I hope his need for an infix tilde operator is overestimated; there are plenty of infix operators that can be abused, and at least one of them should be unused and available for redefinition. Lorenzo Gatti -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
Gabriel Genellina [EMAIL PROTECTED] writes: obj.getattr(a)() but even that is a bit ugly, depending. Surely you meant to say getattr(obj, a)() Yeah, darn. Counterintuitive. I keep making that error in my own code too. Maybe I should put in an RFE. -- http://mail.python.org/mailman/listinfo/python-list
Re: idea for testing tools
Bruno Desthuilliers [EMAIL PROTECTED] writes: http://codespeak.net/py/current/doc/test.html#assert-with-the-assert-statement Ok, I didn't come across this before. I didn't work for me though, even the simple case #!/usr/bin/python a = 1 b = 2 def test_some(): assert a == b didn't reveal the values for a and b, though some more complex cases showed something. -- Cheers, Jens -- http://mail.python.org/mailman/listinfo/python-list
iso 8601, quality criteria
for each library/module or even application, a note in [0:10] in front of every quality criterium. criteria?: completeness robustness how well tested? simplicity documentation maintenance team responsiveness usage: how many developpers picked it up and still use it? how many picked it up but gave it up? The list is an obvious oversimplification, each criterium could be discussed for hours. robustness, for instance, means: how well does it behave when illegal data is fed? A LOT of actual modules (comprising mine (:-) raise obscure exceptions. the iso8601 module is simple enough, easy to install, but fails on legal data. I guess the fix would be useful, but is it maintained? Is it in use? I used xml.dom.minidom, recently. Works fine, but I found the interface awfully complicated. Right or wrong, when I had to write some xml, I wrote my own code: better be simple, although untested, undocumented, etc, than using a module so complicated U never finished the learning curve... So, my questions would be: - how do You, other developpers, cope with this question? - is there such a base, helping to pick up existing modules? - if no, dont U think such an initiative might be useful? - Those who have to deal with iso8601 dates, how do U proceed? Ill have a look to mxdatetime, but is it the right answer? -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling J from Python
Tina I wrote: .. It's also a village in Norway: http://en.wikipedia.org/wiki/Hell,_Norway In German it's bright -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: iso 8601, quality criteria
Imbaud Pierre a écrit : cutnpaste error in this posting, here is the complete message: Context: I am writing an application that accesses XMP-coded files. Some fields contain dates, and comply to iso 8601. I installed the iso8601 python module (http://cheeseshop.python.org/pypi/iso8601), it fails on the simplest forms: ipdb parse_date('2005-01-01') *** TypeError: expected string or buffer (behaves fine with complete strings, but this one is legal!) Choose a module Python interfaces to the world: very few libs or protocols have no python module interfacing them. But they sometimes have many, and it aint easy to pick up the right one. And if there is only one, it aint obvious wether it will fill your quality criteria. My dream: a table with, for each library/module or even application, a note in [0:10] in front of every quality criterium. criteria?: completeness robustness how well tested? simplicity documentation maintenance team responsiveness usage: how many developpers picked it up and still use it? how many picked it up but gave it up? The list is an obvious oversimplification, each criterium could be discussed for hours. robustness, for instance, means: how well does it behave when illegal data is fed? A LOT of actual modules (comprising mine (:-) raise obscure exceptions. the iso8601 module is simple enough, easy to install, but fails on legal data. I guess the fix would be useful, but is it maintained? Is it in use? I used xml.dom.minidom, recently. Works fine, but I found the interface awfully complicated. Right or wrong, when I had to write some xml, I wrote my own code: better be simple, although untested, undocumented, etc, than using a module so complicated U never finished the learning curve... So, my questions would be: - how do You, other developpers, cope with this question? - is there such a base, helping to pick up existing modules? - if no, dont U think such an initiative might be useful? - Those who have to deal with iso8601 dates, how do U proceed? Ill have a look to mxdatetime, but is it the right answer? -- http://mail.python.org/mailman/listinfo/python-list
Re: uml and python
Ralf Schönian wrote: azrael schrieb: hy guys i've been googling and got several posts, but nothing that is a satisfaction in my eyes. can someone tell me a nice uml diagram tool with python export (if possible nice gui), or at least nice uml tool gpl or freeware (widows) prefered thanks Take a look at gaphor: http://gaphor.sourceforge.net/ Yes, Gaphor is fine and already rather powerful. @ azrael, You can also have a look at OpenSwarm: http://openswarm.sourceforge.net/ It is an UML - Python/SQL generator tool with some kind of runtime architecture. Sadly, still alpha and with-out GUI or Gaphor support. Regards, Anastasios -- http://mail.python.org/mailman/listinfo/python-list
Re: Object type check
def modify(list_of_x): for x in list_of_x: try: x.change_in_place # don't call the method, just check it exists XX...what exactly is going on here ? I mean, what is actually happens if you omit the parenethesis as you just did ? I understand that it does not call the method, but what is really doing ?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Object type check
On Feb 8, 12:00 pm, king kikapu [EMAIL PROTECTED] wrote: def modify(list_of_x): for x in list_of_x: try: x.change_in_place # don't call the method, just check it exists XX...what exactly is going on here ? I mean, what is actually happens if you omit the parenethesis as you just did ? I understand that it does not call the method, but what is really doing ?? See http://users.rcn.com/python/download/Descriptor.htm for more than you ever wanted to know about attribute access in Python. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: 'IF' Syntax For Alternative Conditions
[EMAIL PROTECTED] wrote: All my python books and references I find on the web have simplistic examples of the IF conditional. A few also provide examples of multiple conditions that are ANDed; e.g., if cond1: if cond2: do_something. However, I cannot find, nor create by trial-and-error, the syntax for alternative conditions that are ORed; e.g., if cond1 OR if cond2: do_something. I've tried using the C syntax for OR (||) but python complained. I'm sure there's a way to do this rather than using if cond1: elif cond2: both with the same code to execute. Please pass me a pointer so I can learn how to correctly write this. Rich For lots of conditions: import operator reduce(operator.or_, list_of_conditions) e.g.: py import operator py list_of_conditions = [ ...'big' 'small', ...'all' 'half', ...'five' 'one', ...'six' 'seven' ... ] py list_of_conditions [True, False, False, False] py reduce(operator.or_, list_of_conditions) True James -- http://mail.python.org/mailman/listinfo/python-list
Getting file line numbers from Nodes in a DOM?
I have a DOM parsed with xml.dom.mindom.parse()...for a particular Node, is there an easy way to get the line (and maybe even column) numbers that the element appeared in the original file? Thanks, -Beej -- http://mail.python.org/mailman/listinfo/python-list
Re: Object type check
Ο/Η Michele Simionato έγραψε: See http://users.rcn.com/python/download/Descriptor.htm for more than you ever wanted to know about attribute access in Python. Michele Simionato Great stuff Michele, thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python design project
Hi Josh, Thank you for replying my message, sorry for the late reply, i was ill for two days.. I thought about the things you said, and think that it would be interesting, if fonts hit eachother the fonts would be merging. stuck together. so in a kind of way you create 'a new font' . I think the mutate part works also in that, by mutating, you can also create a new form family'. But I think that the fonts must not unrecognizable mutate. the reproducing thing would be nice, so you also get the 'families' like family of a, family of b... and so on... I think that the family must remain at each other presence, stuck together, and when a touches b you get a new form and family. 2 think that all the things could transform, except for the serifs, kerning. 3 does flash work with vector? flash is pixel based isn't? what doe you think about the project, i'm verry interesting in more things oppinions. do you think that the designer creates the final work here, because of the programming or do you think that the fonts of the computer does it? Best, Rick -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
greg When I want to do this, usually I define the parts as ordinary, greg separate classes, and then define the main class as inheriting greg from all of them. Agreed. Maybe it's just my feeble brain, but I find this the most compelling (and easy to understand) use for multiple inheritance by far. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling J from Python
I may have mistook the source code licence for the use licence.. I will look into a little further to see what it can do.. Looks like you are not allowed to redistribute k for profit. Some day I will look up letters a random in the search engine to see what I come up with. On Feb 6, 2:05 am, Gosi [EMAIL PROTECTED] wrote: On Feb 6, 3:04 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Feb 5, 8:48 am, Gosi [EMAIL PROTECTED] wrote: It is quite easy to call J from Python http://groups.google.com/group/J-Programming/browse_thread/thread/5e8... There are a couple of issue that should be adressed. Am I going to jail if I write a program and then redistribute all the files required to run the program I write?? J is free for anyone to download and use. If someone is interested in putting you in jail it will not because you distribute J or redistribute the J utilities. The second is how do I use the j stuff without learning all that much about j. Just like Python then how much time you spend is uo to you. If you want to be good at it you may have to spend some time. You may also be just a casual user and dip into it now and again. There are lots of Demos, Labs and Help files besides all the utilities. You can freely use the utilities and examples to create your own application. You can write code in conventional style and not spend any time on the advanced functionality. I am just intrested in stealing graphics libraries and using what I have already written in python.. There are a number of graphics examples, utilities and demos you can use in J and combine it with Python. The new grid classes in J are amazingly useful too. I am just starting to learn Python and I find it interesting to combine it with J. I know a few people who are doing so successfully. There are always some nicetise in any language that can be beneficial. Combining them enhances both. http://groups.google.com/group/j-programminghttp://jsoftware.com/ -- http://mail.python.org/mailman/listinfo/python-list
Best Free and Open Source Python IDE
Yes, All I need is a good IDE, I can't find something like Eclipse (JDT). Eclipse has a Python IDE plug-in but it's not that great. Please recommend. Thanks, Srikanth -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Free and Open Source Python IDE
Srikanth schrieb: Yes, All I need is a good IDE, I can't find something like Eclipse (JDT). Eclipse has a Python IDE plug-in but it's not that great. Please recommend. Thanks, Srikanth http://www.serpia.org/spe http://www.die-offenbachs.de/detlev/eric.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Free and Open Source Python IDE
On 8 fév, 13:03, Srikanth [EMAIL PROTECTED] wrote: Yes, All I need is a good IDE, I can't find something like Eclipse (JDT). Eclipse has a Python IDE plug-in but it's not that great. Please recommend. emacs +python-mode +ecb -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
On Feb 8, 1:04 pm, [EMAIL PROTECTED] wrote: greg When I want to do this, usually I define the parts as ordinary, greg separate classes, and then define the main class as inheriting greg from all of them. Agreed. Maybe it's just my feeble brain, but I find this the most compelling (and easy to understand) use for multiple inheritance by far. Skip That is a common design, but I don't like it, since it becomes very easy to get classes with dozens of methods inherited from everywhere, a modern incarnation of the spaghetti-code concept. I find it much better to use composition, i.e. to encapsulate the various behaviors in different objects and to add them as attributes. In other words, instead of a flat class namespace with hundreds of methods, I prefer a hierarchical namespace, a class with few attributes, which in turns have their own attributes, and so on. In other words, nested is better than flatten ;) Michele Simionato P.S. Of course I mean situations where the methods can be meaningfully grouped together, which I find is the most common case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Free and Open Source Python IDE
Srikanth wrote: All I need is a good IDE, I can't find something like Eclipse (JDT). Eclipse has a Python IDE plug-in but it's not that great. Please recommend. My favourite at the mo is Komodo Edit - free (though not OSS). On the OSS side, SPE is very good too - more of an IDE than Komodo Edit. DrPython is worth a look as is the similar Ulipad. Also have a look at Boa. Cheers, Davy Mitchell -- http://mail.python.org/mailman/listinfo/python-list
postgres backup script and popen2
Hi, i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. I tested popen2 with dir (i'm on windows 2000, python 2.4.3) and it works. However when i try popen2 and my pg_dump command, it prompts for a password and I was under the impression that i was going to be able to dynamically communicate with the process. sin, sout = popen2(backup_command) sin.readline() # the password prompt sout.write(password) sin.readlines() How can i catch the password prompt and feed the password from my code? Thanks, Benedict -- http://mail.python.org/mailman/listinfo/python-list
distutils: different names in src and dist/build
Hi, is it possible to have different names between the original package name and that which will be installed? Example: setup.py src/ sdk/ __init__.py startme.py This usually creates a distribution file like sdk-0.6.2.tar.gz, which may create site-packages/ sdk/ But I would like to have a MySDK-0.6.2.tar.gz and in site-packages/ MySDK/ Of course with-out changing the original src package name sdk to MySDK (which likely would be the easiest way, hum). Any suggestion or link how I can achieve this? Many thanks, Anastasios -- http://mail.python.org/mailman/listinfo/python-list
Re: postgres backup script and popen2
Use pexpect: http://pexpect.sourceforge.net/ flupke schrieb: Hi, i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. I tested popen2 with dir (i'm on windows 2000, python 2.4.3) and it works. However when i try popen2 and my pg_dump command, it prompts for a password and I was under the impression that i was going to be able to dynamically communicate with the process. sin, sout = popen2(backup_command) sin.readline() # the password prompt sout.write(password) sin.readlines() How can i catch the password prompt and feed the password from my code? Thanks, Benedict -- http://mail.python.org/mailman/listinfo/python-list
Simple Interpolation in Numpy?
Hi, Please bear with me as I am new to Python and have not done any programming in about 20 years. I am attempting to do a simple interpolation of a line's intermediate points given the x,y coordinates of the line's two endpoints within an Active State Python script that I am working with. Is there a simple way to do this simple interpolation in the Active state Python 2.4 that I have or do I need to get Numeric Python? And where do I get it? Thanks, Vince Lapi -- http://mail.python.org/mailman/listinfo/python-list
Re: Group Membership in Active Directory Query
On Feb 7, 7:52 pm, alex23 [EMAIL PROTECTED] wrote: On Feb 8, 4:27 am, [EMAIL PROTECTED] wrote: First and foremost thanks for the feedback. Although I don't appreciate the slight dig at me. dummy = ldap_obj.simple_bind.. I _really_ don't think Uwe was intending any slight, 'dummy' generally means 'dummy variable' ie it's just there to catch the value but it's never used after that :) If you're doing a lot of AD work, I highly recommend Tim Golden's active_directory module:http://timgolden.me.uk/python/ active_directory.html His WMI module has also been a godsend on a number of occasions. - alex23 Alex- Thanks for your response and Uwe I apologize if I misunderstood and misinterpreted your comments. I am sorry. I have tried Tim's module called active_directory and it works really well. But I can't figure out how to connect to a specific group is I know the common name for it but not the DN and then return it's members. Example I know the group name is domain1\sharedaccess. How do I bind to that group and get the members. The domain isn't necessarily the defaultnamingcontext. It could be another domain in the forest. I need to be able to connect to any domain group and get it's members. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-installing Numeric and PIL Files
Robert Kern wrote: W. Watson wrote: Robert Kern wrote: W. Watson wrote: For some reason Python 2.2.4 cannot find the Numeric module. It's been suggested that I should re-install the Numeric file. How do that? Also the PIL. The three install files are: python-2.4.4.msi PIL-1.1.5.win32-py2.4.exe Numeric-24.2.win32-py2.4.exe The latter two are executable installers. Run them. I have re-run Numeric. The python program still cannot detect the Numeric module. Well, check to make sure that the Python executable is the one that you think it is. You can look at sys.executable to find the actual .exe of the running Python interpreter. With Python 2.4.4 and a standard installation, it should be c:\Python24\python.exe I believe. Then check to make sure that Numeric and PIL are actually installed in c:\Python24\Lib\site-packages\ . This may be a good clue. I'm not the author of the sentuser.py program that I'm using 2.4 for. It's an application meant for another PC. On that machine, I only have 2.4 installed. I decided to learn Python a few weeks ago and installed 2.5.It's quite possible there's some confusion with the just installed application. I have not yet started my education on python, so know little about it. I did a search in the python24 folder for sys.exec* (in c:\python24), but came up with nothing. [nothing in a search of c:--sys.exec*] I have two python folders, c:\python24 and c:\python25. The contents of both folders look fairly similar and each have a python.exe. I do not use a PIL or Numeric in 2.5. 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 think it not improbable that man, like the grub that prepares a chamber for the winged thing it has never seen but is to be, may have... destinies that he does not understand. -- Oliver Wendell Holmes -- Web Page: home.earthlink.net/~mtnviews -- http://mail.python.org/mailman/listinfo/python-list
Re: uml and python
tahks guys -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
On Feb 8, 3:40 am, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-02-08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Oh for Pete's sake... struct.pack('%dsIL' % len(buffer), buffer, count, offset) -- Grant Edwards grante Yow! I want the presidency at so bad I can already taste visi.comthe hors d'oeuvres. that is great but how does one unpack on the other side? -ishwar -- http://mail.python.org/mailman/listinfo/python-list
Re: 'IF' Syntax For Alternative Conditions
On 2007-02-08, Paul Rubin http wrote: [EMAIL PROTECTED] writes: if cond1: if cond2: do_something. You can write: if cond1 and cond2: do_something if cond1 OR if cond2: do_something. if cond1 or cond2: do_something I've tried using the C syntax for OR (||) but python complained. I'm sure there's a way to do this rather than using if cond1: elif cond2: both with the same code to execute. Python uses the and and or keywords for and ||. Allow me to thank all of you who responded with this one article. For whatever reason, it did not occur to me to use the words 'and' and 'or.' And, I did not see this in the tutorial or introduction ... which is my fault. So, I do thank all of you. Rich -- http://mail.python.org/mailman/listinfo/python-list
python linux distro
Hy guys last night i was lying in my bed and thinking about something. is there any linux distro that is primary oriented to python. you know what i mean. no need for php, java, or something like this. pure python and containig all the funky modules like scipy, numpy, boaconstructor (wx of course). something like the python enthought edition, but all this on a distro included. maybe psql but persistant predered, zope of course. everything a developer is ever going to need. So i stood up, sat down on my ugly acer notebook with a python stiker on it and made a huge list of cool modles i would prefer. I would like to make such a distro but i am not a linux pro. so this is going to stay just a idea. i thouht it should be realy user fredly like sabayon or ubuntu (without xgel). if this were a live distro it would be amazing. I know, dont expet someone else to do your work, but is there anyone who likes the idea and has the knowledge i dont have. I also know for quantian (cool distro), but for me, there is too much other crap and not enough python. i even got the nam of it. maybee not the best but it fits the context. PyTux --- and no, I am not a junkee, I'm addicted to Python -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
[EMAIL PROTECTED] wrote: On Feb 8, 3:40 am, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-02-08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Oh for Pete's sake... struct.pack('%dsIL' % len(buffer), buffer, count, offset) -- Grant Edwards grante Yow! I want the presidency at so bad I can already taste visi.comthe hors d'oeuvres. that is great but how does one unpack on the other side? By peeking into the header, determining the number of bytes necessary? But why do you need this anyway - if you know that you will have python on both ends, use Pyro or xmlrpc. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
Michele That is a common design, but I don't like it, since it becomes Michele very easy to get classes with dozens of methods inherited from Michele everywhere, a modern incarnation of the spaghetti-code Michele concept. I find it much better to use composition, i.e. to Michele encapsulate the various behaviors in different objects and to Michele add them as attributes. Composition is great when you know how largish classes are going to be composed ahead of time and/or already have the pieces available in the form of other classes you want to reuse. I use this fragment-by-multiple- inheritance (I hesitate to call it a) pattern when I realize after a long period of organic growth that a single-inheritance class has gotten too big. It's often relatively easy to carve the class up into multiple related base classes. The next step after that might be to morph those independent base classes back into delegated attributes. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
On Thu, 08 Feb 2007 15:56:30 +0100, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Feb 8, 3:40 am, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-02-08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Oh for Pete's sake... struct.pack('%dsIL' % len(buffer), buffer, count, offset) -- Grant Edwards grante Yow! I want the presidency at so bad I can already taste visi.comthe hors d'oeuvres. that is great but how does one unpack on the other side? By peeking into the header, determining the number of bytes necessary? But why do you need this anyway - if you know that you will have python on both ends, use Pyro or xmlrpc. Grant had the right idea, I think, but he failed to actually include a byte length in his format. :) So there's nothing to peek at. If the packing is done like this, instead.. struct.pack('!IIL', len(buffer), count, offset) + buffer Then it is a simple matter to unpack it once the receiving side, by waiting for struct.calcsize('!IIL') bytes, using struct to get len(buffer), count, and offset: length, count, offset = struct.unpack('!IIL', bytes) And then waiting for `length' more bytes, which will be the buffer. I'm not sure what the original use-case was here. XML-RPC isn't a good transport for arbitrary binary data. If `buffer' contains text, though, that might be a good suggestion. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Linux-Signal VS QT
Can I use LinuX signal as a tool for commuction with a QT(PyQt4) programme? The follow code didNOT work... from PyQt4 import QtCore,QtGui import signal import sys import os try: import psyco psyco.full() except: pass class Main(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.frame = QtGui.QFrame(self) self.label = QtGui.QLabel(str(os.getpid()), self.frame) signal.signal(15, self.sig_handler) print signal.getsignal(15) def sig_handler(self, signum, sframe): print 'received!' self.label.setText('haha') self.show() # main routine# if __name__ == '__main__': app = QtGui.QApplication(sys.argv) main = Main() main.show() app.exec_() -- LinuX Power -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
Hi, the world doesn't need another Linux distro, there are too many already... ( 100) I believe it's a better idea to spend your time contributing to an existing distro (e.g. http://www.ubuntu.com/developers/bounties) doing Python related stuff. Besides that, all distros I know of (4) already have a lot of Python packages ready for download. regards, Dimitri On 8 Feb 2007 06:44:22 -0800, azrael [EMAIL PROTECTED] wrote: Hy guys last night i was lying in my bed and thinking about something. is there any linux distro that is primary oriented to python. you know what i mean. no need for php, java, or something like this. pure python and containig all the funky modules like scipy, numpy, boaconstructor (wx of course). something like the python enthought edition, but all this on a distro included. maybe psql but persistant predered, zope of course. everything a developer is ever going to need. So i stood up, sat down on my ugly acer notebook with a python stiker on it and made a huge list of cool modles i would prefer. I would like to make such a distro but i am not a linux pro. so this is going to stay just a idea. i thouht it should be realy user fredly like sabayon or ubuntu (without xgel). if this were a live distro it would be amazing. I know, dont expet someone else to do your work, but is there anyone who likes the idea and has the knowledge i dont have. I also know for quantian (cool distro), but for me, there is too much other crap and not enough python. i even got the nam of it. maybee not the best but it fits the context. PyTux --- and no, I am not a junkee, I'm addicted to Python -- http://mail.python.org/mailman/listinfo/python-list -- --- You can't have everything. Where would you put it? -- Steven Wright --- please visit www.serpia.org -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
Grant had the right idea, I think, but he failed to actually include a byte length in his format. :) So there's nothing to peek at. If the packing is done like this, instead.. struct.pack('!IIL', len(buffer), count, offset) + buffer Then it is a simple matter to unpack it once the receiving side, by waiting for struct.calcsize('!IIL') bytes, using struct to get len(buffer), count, and offset: length, count, offset = struct.unpack('!IIL', bytes) And then waiting for `length' more bytes, which will be the buffer. That was my intention, yes - I thought the header information of the OP contained a byte count already. I'm not sure what the original use-case was here. XML-RPC isn't a good transport for arbitrary binary data. If `buffer' contains text, though, that might be a good suggestion. Certainly XMLRPC isn't too good - and Pyro in many aspects better. AFAIK it uses pickle, and that means that things should be comparably compact. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Linux-Signal VS QT
On Thursday 08 February 2007 3:08 pm, Marco wrote: Can I use LinuX signal as a tool for commuction with a QT(PyQt4) programme? The follow code didNOT work... from PyQt4 import QtCore,QtGui import signal import sys import os try: import psyco psyco.full() except: pass class Main(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.frame = QtGui.QFrame(self) self.label = QtGui.QLabel(str(os.getpid()), self.frame) signal.signal(15, self.sig_handler) print signal.getsignal(15) def sig_handler(self, signum, sframe): print 'received!' self.label.setText('haha') self.show() # main routine# if __name__ == '__main__': app = QtGui.QApplication(sys.argv) main = Main() main.show() app.exec_() The problem is that Python only delivers the signal when the interpreter is running but your program is sat in the Qt event loop. You need to force Qt to hand back to the interpreter from time to time. The easiest way is to use the object timer. Add self.startTimer(500) to your __init__() method and add the following dummy timer event handler... def timerEvent(self, e): pass Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
azrael wrote: Hy guys last night i was lying in my bed and thinking about something. is there any linux distro that is primary oriented to python. you know what i mean. no need for php, java, or something like this. pure python and containig all the funky modules like scipy, numpy, boaconstructor (wx of course). something like the python enthought edition, but all this on a distro included. maybe psql but persistant predered, zope of course. everything a developer is ever going to need. On debian base distributions you can create a task. A task list all packages you need. You could make a task all-python-stuff. But I don't think many people will use it. I use Python daily, but at the moment I never use Zope, scipy or twisted. Ubuntu is a very python friendly environment. Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
On Feb 8, 4:05 pm, [EMAIL PROTECTED] wrote: Composition is great when you know how largish classes are going to be composed ahead of time and/or already have the pieces available in the form of other classes you want to reuse. I use this fragment-by-multiple- inheritance (I hesitate to call it a) pattern when I realize after a long period of organic growth that a single-inheritance class has gotten too big. It's often relatively easy to carve the class up into multiple related base classes. The next step after that might be to morph those independent base classes back into delegated attributes. Skip I know, I just try to avoid the multiple inheritance transitional state and switch directly to the last step ;) M. Simionato -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Python new user question - file writeline error
To the list: I have come up with something that's working fine. However, I'm fairly new to Python, so I'd really appreciate any suggestions on how this can be made more Pythonic. Thanks, Shawn Okay, here's what I have come up with: #! /usr/bin/python import sys import re month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12} infile=file('TVA-0316','r') outfile=file('tmp.out','w') def formatDatePart(x): take a number and transform it into a two-character string, zero padded x = str(x) while len(x) 2: x = 0 + x return x regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: dayNum = formatDatePart(someDate[1:3]) monthNum = formatDatePart(month[someDate[4:7]]) yearNum = formatDatePart(someDate[8:12]) newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) line = line.replace(someDate, newDate) outfile.writelines(line) infile.close outfile.close -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name from within main
On Wed, Feb 07, 2007 at 01:02:39AM -0800, [EMAIL PROTECTED] wrote: Hi, Lets say I have the following class - class MyClass: def __init__(self): print (__name__.split(.))[-1] I would spell this: print self.__class__.__name__ if __name__ == '__main__': MyClassName = MyClass I can print the name of the class from within the class scope as seen above in the init, but is there any way of printing it from within the main without creating an object of the MyClass type. I need to assign the name of the class within my script, to a variable in main. Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: idea for testing tools
#!/usr/bin/python a = 1 b = 2 def test_some(): assert a == b didn't reveal the values for a and b, though some more complex cases showed something. def test_some(): print 'a:', a, 'b:', b assert a == b http://codespeak.net/py/current/doc/test.html#debug-with-the-print-statement -- EduardoOPadoan (eopadoan-altavix::com) Bookmarks: http://del.icio.us/edcrypt Blog: http://edcrypt.blogspot.com Jabber: edcrypt at jabber dot org ICQ: 161480283 GTalk: eduardo dot padoan at gmail dot com MSN: eopadoan at altavix dot com -- http://mail.python.org/mailman/listinfo/python-list
PyQt install problem
hi Bruce, I was trying to interpret the code you wrote for xroot.sh. I saw it on pg 115 in Sitepoint's Run Your Own Web Server Using Linux Apache Could you possibly consider commenting on what each line of code is doing? It works; the warning message goes away. I just don't understand what its doing. here it is: if [ $# -lt 1 ] then echo usage: 'basename $0' command $2 exit 2 fi su - -c exec env DISPLAY='$DISPLAY' \ XAUTHORITY= ' ${XAUTHORITY - $HOME/ .Xauthority}' ' $SHELL ' -c '$*' - Need Mail bonding? Go to the Yahoo! Mail QA for great tips from Yahoo! Answers users.-- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
On 2/8/07, dimitri pater [EMAIL PROTECTED] wrote: Hi, the world doesn't need another Linux distro, there are too many already... ( 100) I believe it's a better idea to spend your time contributing to an existing distro (e.g. http://www.ubuntu.com/developers/bounties) doing Python related stuff. Besides that, all distros I know of (4) already have a lot of Python packages ready for download. regards, Dimitri snip You're right, there are too many. Not just over 100, but over 500. As of this week, DistroWatch reports having 528 in their database. Check out DistroWatch.com for details. To the original poster: You may not be a Linux expert, but if you feel like reading some documentation, you can easily remaster a live CD such as Knoppix or DSL (Damn Small Linux). Just to to the distro's site and check out the documentation. This won't be the creation of a brand-new distro -- it's the same thing as changing the wallpaper and creating your custom re-master just for yourself. Both distros I mentioned (and many others, I'm sure) have a simple, built-in tool for installing additional packages. Do that, then make your re-image from your running live version. Shawn -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils: different names in src and dist/build
Anastasios Hatzis wrote: Hi, is it possible to have different names between the original package name and that which will be installed? Example: setup.py src/ sdk/ __init__.py startme.py This usually creates a distribution file like sdk-0.6.2.tar.gz, which may create site-packages/ sdk/ But I would like to have a MySDK-0.6.2.tar.gz and in site-packages/ MySDK/ Of course with-out changing the original src package name sdk to MySDK (which likely would be the easiest way, hum). Any suggestion or link how I can achieve this? Sorry, now I understood that package_dir option can also be used to have a installed package layout *totally different* from original source layout. Regards, Anastasios -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Application Within Emacs
You can call scripts from the interpreter with execfile('script.py'). If you use ipython there is a %run command that executes a script. Enjoy! Bernhard On Feb 7, 3:26 pm, [EMAIL PROTECTED] wrote: My editor is emacs in linux, and I have the python mode enabled. The two menus -- IM-Python and Python -- allow me to navigate within the loaded module and open execute buffers, among other things. But, I don't see a way to run a wxPython application from within the editor as I would from the command line. Is this possible? If so, how? Ric -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-installing Numeric and PIL Files
W. Watson wrote: I did a search in the python24 folder for sys.exec* (in c:\python24), but came up with nothing. [nothing in a search of c:--sys.exec*] I have two python folders, c:\python24 and c:\python25. The contents of both folders look fairly similar and each have a python.exe. I do not use a PIL or Numeric in 2.5. I'm sorry. sys is a module. I meant for you to execute the following Python code: import sys print sys.executable -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Interpolation in Numpy?
LAPI, VINCENT J, ATTLABS wrote: Hi, Please bear with me as I am new to Python and have not done any programming in about 20 years. I am attempting to do a simple interpolation of a line's intermediate points given the x,y coordinates of the line's two endpoints within an Active State Python script that I am working with. Is there a simple way to do this simple interpolation in the Active state Python 2.4 that I have or do I need to get Numeric Python? And where do I get it? Thanks, Vince Lapi You shouldn't really *need* Numeric (NumPy or numpy, nowadays) for a relatively simple problem like that, since the formulae involved are pretty simple. Given known points on the line at (xa, ya) and (xb, yb) then for any point (x, y) on the line we get y = ya + ((x - xa) * (yb - ya))/(xb - xa) So you just need to plug the values for x and the known points into the formula to get the interpolated value of y. If you are interpolating a non-linear formula through a number of samples clearly there'd be a little more jiggery pokery involved to identify the particular interval on which interpolation is required, but nothing horrendous. Numpy, which is derived from the old Numeric code, is at http://numpy.scipy.org/ should you wish to investigate its features. It probably has better-than-linear interpolation algorithms in it. Note that if you decide to download it you should choose the Python 2.4 version - extensions coded in compiled languages are specific to a particular version of the language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.8.0b3
Hello! I'm pleased to announce the 0.8.0b3 release of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.8.0b3 News and changes: http://sqlobject.org/devel/News.html What's New == News since 0.8.0b2 -- * Separate docs subdirectory instead of the shared external one. For a more complete list, please see the news: http://sqlobject.org/devel/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: postgres backup script and popen2
On 8 feb, 10:27, Maël Benjamin Mettler [EMAIL PROTECTED] wrote: flupke schrieb: i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. Use pexpect:http://pexpect.sourceforge.net/ pexpect could work. But a better way would be to supply the password on the command line. I don't know how postgres does that things, but I hope there is some way to automate the backup process... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: postgres backup script and popen2
On 8 Feb 2007 08:23:49 -0800, Gabriel Genellina [EMAIL PROTECTED] wrote: On 8 feb, 10:27, Maël Benjamin Mettler [EMAIL PROTECTED] wrote: flupke schrieb: i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. Use pexpect:http://pexpect.sourceforge.net/ pexpect could work. But a better way would be to supply the password on the command line. So that it shows up in `ps' output to anyone on the system? :) Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Strings in Python
Playing a little more with strings, I found out that string.find function provides the position of the first occurance of the substring in the string. Is there a way how to find out all substring's position ? To explain more, let's suppose mystring='12341' import string string.find(mystring ,'1') 0 But I need to find the possition the other '1' in mystring too. Is it possible? Or must I use regex? Thanks for help L -- http://mail.python.org/mailman/listinfo/python-list
Re: Referencing vars, methods and classes by name
On 8 feb, 05:51, Paul Rubin http://[EMAIL PROTECTED] wrote: Gabriel Genellina [EMAIL PROTECTED] writes: obj.getattr(a)() but even that is a bit ugly, depending. Surely you meant to say getattr(obj, a)() Yeah, darn. Counterintuitive. I keep making that error in my own code too. Maybe I should put in an RFE. The method way is using __getattribute__ or __getattr__. A generic function helps on using it on objects of any kind - like len() Perhaps it was more important with old style classes. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings in Python
Johny wrote: Playing a little more with strings, I found out that string.find function provides the position of the first occurance of the substring in the string. Is there a way how to find out all substring's position ? To explain more, let's suppose mystring='12341' import string string.find(mystring ,'1') 0 But I need to find the possition the other '1' in mystring too. Is it possible? Or must I use regex? Thanks for help L You could use a regular expression. The re module has s function findall that does what you want. Also, if you read the documentation for strings find method, you'll find: 1 S.find(sub [,start [,end]]) - int 2 3 Return the lowest index in S where substring sub is found, 4 such that sub is contained within s[start,end]. Optional 5 arguments start and end are interpreted as in slice notation. 6 7 Return -1 on failure. So put your find in a loop, starting the search one past the previously found occurrence. i = string.find(mystring, i+1) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings in Python
On 8 Feb 2007 08:28:25 -0800, Johny [EMAIL PROTECTED] wrote: Playing a little more with strings, I found out that string.find function provides the position of the first occurance of the substring in the string. Is there a way how to find out all substring's position ? To explain more, let's suppose mystring='12341' import string string.find(mystring ,'1') 0 But I need to find the possition the other '1' in mystring too. Is it possible? Or must I use regex? Thanks for help L -- http://mail.python.org/mailman/listinfo/python-list Loop it -- once you know the index of the first character, add the third argument to string.find(), which tells it the position at which to start (the last find + 1). -- http://mail.python.org/mailman/listinfo/python-list
Re: idea for testing tools
Jens Theisen [EMAIL PROTECTED] writes: def test_some(): assert a == b didn't reveal the values for a and b, though some more complex cases showed something. I usually use assert a == b, (a,b) -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings in Python
On 2/8/07, Gary Herron [EMAIL PROTECTED] wrote: Johny wrote: Playing a little more with strings, I found out that string.find function provides the position of the first occurance of the substring in the string. Is there a way how to find out all substring's position ? To explain more, let's suppose mystring='12341' import string string.find(mystring ,'1') 0 But I need to find the possition the other '1' in mystring too. Is it possible? Or must I use regex? Thanks for help L You could use a regular expression. The re module has s function findall that does what you want. Also, if you read the documentation for strings find method, you'll find: 1 S.find(sub [,start [,end]]) - int 2 3 Return the lowest index in S where substring sub is found, 4 such that sub is contained within s[start,end]. Optional 5 arguments start and end are interpreted as in slice notation. 6 7 Return -1 on failure. So put your find in a loop, starting the search one past the previously found occurrence. i = string.find(mystring, i+1) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list Speaking of regex examples, that's basically what I did in the script below which James Kim and I were collaborating on yesterday and this morning, as a result of his thread. This matches not only a string, but a regex, then loops through each match to do something to it. I hope this helps. I submitted this to the list for recommendations on how to make it more Pythonic, but at least it works. Here are the most important, stripped down pieces: #! /usr/bin/python import re #match a date in this format: 05/MAR/2006 regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: newDate = #do something here line = line.replace(someDate, newDate) Here is the full script: #! /usr/bin/python import sys import re month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12} infile=file('TVA-0316','r') outfile=file('tmp.out','w') def formatDatePart(x): take a number and transform it into a two-character string, zero padded x = str(x) while len(x) 2: x = 0 + x return x regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: dayNum = formatDatePart(someDate[1:3]) monthNum = formatDatePart(month[someDate[4:7]]) yearNum = formatDatePart(someDate[8:12]) newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) line = line.replace(someDate, newDate) outfile.writelines(line) infile.close outfile.close -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
azrael wrote: Hy guys last night i was lying in my bed and thinking about something. is there any linux distro that is primary oriented to python. you know what i mean. no need for php, java, or something like this. pure python and containig all the funky modules like scipy, numpy, boaconstructor (wx of course). something like the python enthought edition, but all this on a distro included. maybe psql but persistant predered, zope of course. everything a developer is ever going to need. So i stood up, sat down on my ugly acer notebook with a python stiker on it and made a huge list of cool modles i would prefer. I would like to make such a distro but i am not a linux pro. so this is going to stay just a idea. i thouht it should be realy user fredly like sabayon or ubuntu (without xgel). if this were a live distro it would be amazing. I know, dont expet someone else to do your work, but is there anyone who likes the idea and has the knowledge i dont have. I also know for quantian (cool distro), but for me, there is too much other crap and not enough python. i even got the nam of it. maybee not the best but it fits the context. PyTux Well, Ubuntu is normally held to be a pretty Python-friendly distro. But nowadays you might get more mileage out of distributing a Xen or VMWare virtual machine that has Python and all necessary packages installed with it. There is a fine example, the Python Web Developer Appliance, at http://www.mcguru.net/pyweb.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
On 2007-02-08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Feb 8, 3:40 am, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-02-08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Oh for Pete's sake... struct.pack('%dsIL' % len(buffer), buffer, count, offset) that is great but how does one unpack on the other side? struct.unpack('%dsIL' % buflen ,packet) -- Grant Edwards grante Yow! Yow! Did something at bad happen or am I in a visi.comdrive-in movie?? -- http://mail.python.org/mailman/listinfo/python-list
Re: help on packet format for tcp/ip programming
On 2007-02-08, Diez B. Roggisch [EMAIL PROTECTED] wrote: struct module pack and unpack will only work for fixed size buffer : pack('1024sIL', buffer, count. offset) but the buffer size can vary from one packet to the next :-( Oh for Pete's sake... struct.pack('%dsIL' % len(buffer), buffer, count, offset) that is great but how does one unpack on the other side? By peeking into the header, determining the number of bytes necessary? Better yet, use a protocol that's not brain-dead: send the buffer size _before_ you send the buffer. But why do you need this anyway - if you know that you will have python on both ends, use Pyro or xmlrpc. -- Grant Edwards grante Yow! A dwarf is passing at out somewhere in Detroit! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: C parsing fun
Károly Kiripolszky [EMAIL PROTECTED] wrote: I've found a brute-force solution. In the preprocessing phase I simply strip out the comments (things inside comments won't appear in the result) and replace curly brackets with these symbols: #::OPEN::# and #::CLOSE::#. This fails when the code already has the strings #::OPEN::# and #::CLOSE:: in it. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python new user question - file writeline error
On 8 feb, 12:41, Shawn Milo [EMAIL PROTECTED] wrote: I have come up with something that's working fine. However, I'm fairly new to Python, so I'd really appreciate any suggestions on how this can be made more Pythonic. A few comments: You don't need the formatDatePart function; delete it, and replace newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) with newDate = ,%04.4d-%02.2d-%02.2d, % (yearNum,monthNum,dayNum) and before: dayNum, monthNum, yearNum = [int(num) for num in someDate[1:-1].split('/')] And this: outfile.writelines(line) should be: outfile.write(line) (writelines works almost by accident here). You forget again to use () to call the close methods: infile.close() outfile.close() I don't like the final replace, but for a script like this I think it's OK. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the world need another v0.1 python compiler?
On Feb 8, 8:03 am, Kay Schluehr [EMAIL PROTECTED] wrote: This code generation for an arbitrary backend sounds more like an appropriate task for PyPy. I think Grant's or anyone elses compiler could be a viable tool for augmenting the CPython interpreter in particular in the presence of optional type annotations in Py3K. IMHO, with the presence of static types in Py3K, we should have a static compiler that can be invoked dynamically, just like Common Lisp. Something like def foo(...): bar = static_compile(foo, optimize=2) bar(...) JIT compilers are hyped, static compilers perform much better. This way the programmer can decide what needs to be compiled. This is the reason why CMUCL can compete with most C compilers. -- http://mail.python.org/mailman/listinfo/python-list
Re: C parsing fun
Yes, of course. But you can still fine-tune the code for the sources you want to parse. The C++ header files I needed to analyze contained no such strings. I believe there are very few real-life .h files out there containing those. In fact I chose #::OPEN::# and #::CLOSE::# because they're more foreign to C++ like eg. ::OPEN or #OPEN would be. I hope this makes sense. :) Roberto Bonvallet írta: Károly Kiripolszky [EMAIL PROTECTED] wrote: I've found a brute-force solution. In the preprocessing phase I simply strip out the comments (things inside comments won't appear in the result) and replace curly brackets with these symbols: #::OPEN::# and #::CLOSE::#. This fails when the code already has the strings #::OPEN::# and #::CLOSE:: in it. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: postgres backup script and popen2
On 8 feb, 13:29, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 8 Feb 2007 08:23:49 -0800, Gabriel Genellina [EMAIL PROTECTED] wrote: On 8 feb, 10:27, Maël Benjamin Mettler [EMAIL PROTECTED] wrote: flupke schrieb: i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. Use pexpect:http://pexpect.sourceforge.net/ pexpect could work. But a better way would be to supply the password on the command line. So that it shows up in `ps' output to anyone on the system? :) Any solution has pros and cons... having the password in the source code is not so good anyway... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python new user question - file writeline error
On 8 Feb 2007 09:05:51 -0800, Gabriel Genellina [EMAIL PROTECTED] wrote: On 8 feb, 12:41, Shawn Milo [EMAIL PROTECTED] wrote: I have come up with something that's working fine. However, I'm fairly new to Python, so I'd really appreciate any suggestions on how this can be made more Pythonic. A few comments: You don't need the formatDatePart function; delete it, and replace newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) with newDate = ,%04.4d-%02.2d-%02.2d, % (yearNum,monthNum,dayNum) and before: dayNum, monthNum, yearNum = [int(num) for num in someDate[1:-1].split('/')] And this: outfile.writelines(line) should be: outfile.write(line) (writelines works almost by accident here). You forget again to use () to call the close methods: infile.close() outfile.close() I don't like the final replace, but for a script like this I think it's OK. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list Gabriel, Thanks for the comments! The new version is below. I thought it made a little more sense to format the newDate = ... line the way I have it below, although I did incorporate your suggestions. Also, the formatting options you provided seemed to specify not only string padding, but also decimal places, so I changed it. Please let me know if there is some other meaning behind the way you did it. As for not liking the replace line, what would you suggest instead? Shawn #! /usr/bin/python import sys import re month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12} infile=file('TVA-0316','r') outfile=file('tmp.out','w') regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: dayNum = someDate[1:3] monthNum = month[someDate[4:7]] yearNum = someDate[8:12] newDate = ,%04d-%02d-%02d, % (int(yearNum),int(monthNum),int(dayNum)) line = line.replace(someDate, newDate) outfile.write(line) infile.close() outfile.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: postgres backup script and popen2
On 8 Feb 2007 09:18:26 -0800, Gabriel Genellina [EMAIL PROTECTED] wrote: On 8 feb, 13:29, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 8 Feb 2007 08:23:49 -0800, Gabriel Genellina [EMAIL PROTECTED] wrote: On 8 feb, 10:27, Maël Benjamin Mettler [EMAIL PROTECTED] wrote: flupke schrieb: i made a backup script to backup my postgres database. Problem is that it prompts for a password. It thought i could solve this by using popen2. Use pexpect:http://pexpect.sourceforge.net/ pexpect could work. But a better way would be to supply the password on the command line. So that it shows up in `ps' output to anyone on the system? :) Any solution has pros and cons... Some solutions have more or less of these than other solutions though. having the password in the source code is not so good anyway... Sure, but just because one has a password in the source doesn't mean one should completely give up. If you want to completely give up, you can just disable password authentication in pgsql. That's a lot simpler than any other solution mentioned so far. :) Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: python linux distro
thanks guys when i wrote this, i thought that out there is some crazy guy like me. i was hoping for more support but after these arguments, there is nothing more then to say:you are right. the world doesnt need another distro. but if one day I mange to do it, hope you will be glade that i post the lik here. i will look out (if i mange to do it) to use the slax distro and just add some packages. thnx On Feb 8, 5:56 pm, Steve Holden [EMAIL PROTECTED] wrote: azrael wrote: Hy guys last night i was lying in my bed and thinking about something. is there any linux distro that is primary oriented to python. you know what i mean. no need for php, java, or something like this. pure python and containig all the funky modules like scipy, numpy, boaconstructor (wx of course). something like the python enthought edition, but all this on a distro included. maybe psql but persistant predered, zope of course. everything a developer is ever going to need. So i stood up, sat down on my ugly acer notebook with a python stiker on it and made a huge list of cool modles i would prefer. I would like to make such a distro but i am not a linux pro. so this is going to stay just a idea. i thouht it should be realy user fredly like sabayon or ubuntu (without xgel). if this were a live distro it would be amazing. I know, dont expet someone else to do your work, but is there anyone who likes the idea and has the knowledge i dont have. I also know for quantian (cool distro), but for me, there is too much other crap and not enough python. i even got the nam of it. maybee not the best but it fits the context. PyTux Well, Ubuntu is normally held to be a pretty Python-friendly distro. But nowadays you might get more mileage out of distributing a Xen or VMWare virtual machine that has Python and all necessary packages installed with it. There is a fine example, the Python Web Developer Appliance, at http://www.mcguru.net/pyweb.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenwebhttp://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon?http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-installing Numeric and PIL Files
Robert Kern wrote: W. Watson wrote: I did a search in the python24 folder for sys.exec* (in c:\python24), but came up with nothing. [nothing in a search of c:--sys.exec*] I have two python folders, c:\python24 and c:\python25. The contents of both folders look fairly similar and each have a python.exe. I do not use a PIL or Numeric in 2.5. I'm sorry. sys is a module. I meant for you to execute the following Python code: import sys print sys.executable I'm savvy about a number of languages, but not yet about Python. What py file will allow this to be executed? main myprog { import sys print sys.executable pause } ?? 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 Humans aren't the first species to alter the atmosphere; that distinction belongs to early bacteria, which some two million years ago, invented photosynthesis. -- Field Notes from a Catastrophe, Kolbert -- Web Page: home.earthlink.net/~mtnviews -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
Martin v. Löwis wrote: I'm happy to announce partial 1.0; a module to implement partial classes in Python. It is available from http://cheeseshop.python.org/pypi/partial/1.0 A partial class is a fragment of a class definition; partial classes allow to spread the definition of a class over several modules. One location serves as the original definition of the class. To extend a class original_module.FullClass with an additional function, one writes from partial import * import original_module Erm, Please don't use 'from x import *', especially in a demo example like this. It makes it less clear which variables below come from your module. Thanks, Cliff class ExtendedClass(partial, original_module.FullClass): def additional_method(self, args): body more_methods This module is licensed under the Academic Free License v3.0. Please send comments and feedback to [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: idea for testing tools
That's hardly desirable. If one is writing a test library that goes as far as reparsing the assert statements, I can't see the point of requiring the user to clutter his test suite with such spurious print statements. After all, that's one of the main points of test suites in the first place (that's why there is assertEqual). It will be only be printed when the test fails, along with the rest of the info. The tests will not be cluttered by this litle print. -- EduardoOPadoan (eopadoan-altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
begin to parse a web page not entirely downloaded
Hi, Is there a way to retrieve a web page and before it is entirely downloaded, begin to test if a specific string is present and if yes stop the download ? I believe that urllib.openurl(url) will retrieve the whole page before the program goes to the next statement. I suppose I would be able to do what I want by using the sockets module, but I'm sure there's a simpler way to do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple SVN/CVS-like library in Python?
Andrea Gavana wrote: Hi All, in our office we work with quite complex input files for a reservoir simulator. Those files have thousands of keywords, switches, sub-keywords and whatever. Every time a modification is requested, we modify the input file and re-run the simulator. Obviously, the possible modifications are innumerable: so, after few months, we lose the records of all the changes we made during time and we don't have anymore a clear history of our work. This can be a problem, as sometimes it happens that an old input file is requested by collegues/sub-companies, and it is a pain to retrieve the correct file and results. So, I have written a GUI in wxPython that could help us in tracking the history, but I was wondering if there exists a small and simple SVN/CVS-like library in Python that may help us in a better way, storing modifications/changes and showing which input file are the children of (are derived from) another input file (older). But I am open to all possible suggestions to improve/modify the software, as this is an area in which my experience is about nothing above zero. Thank you guys for all your useful suggestions. Andrea. Imagination Is The Only Weapon In The War Against Reality. http://xoomer.virgilio.it/infinity77/ -- http://mail.python.org/mailman/listinfo/python-list
Re: begin to parse a web page not entirely downloaded
k0mp wrote: Is there a way to retrieve a web page and before it is entirely downloaded, begin to test if a specific string is present and if yes stop the download ? I believe that urllib.openurl(url) will retrieve the whole page before the program goes to the next statement. Use urllib.urlopen(), but call .read() with a smallish argument, e.g.: foo = urllib.urlopen('http://google.com') foo.read(512) 'htmlhead ... foo.read(512) will return as soon as 512 bytes have been received. You can keep caling it until it returns an empty string, indicating that there's no more data to be read. -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling J from Python
On Feb 8, 12:00 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I may have mistook the source code licence for the use licence.. I will look into a little further to see what it can do.. Looks like you are not allowed to redistribute k for profit. Some day I will look up letters a random in the search engine to see what I come up with. On Feb 6, 2:05 am, Gosi [EMAIL PROTECTED] wrote: On Feb 6, 3:04 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Feb 5, 8:48 am, Gosi [EMAIL PROTECTED] wrote: It is quite easy to call J from Python http://groups.google.com/group/J-Programming/browse_thread/thread/5e8... There are a couple of issue that should be adressed. Am I going to jail if I write a program and then redistribute all the files required to run the program I write?? J is free for anyone to download and use. If someone is interested in putting you in jail it will not because you distribute J or redistribute the J utilities. The second is how do I use the j stuff without learning all that much about j. Just like Python then how much time you spend is uo to you. If you want to be good at it you may have to spend some time. You may also be just a casual user and dip into it now and again. There are lots of Demos, Labs and Help files besides all the utilities. You can freely use the utilities and examples to create your own application. You can write code in conventional style and not spend any time on the advanced functionality. I am just intrested in stealing graphics libraries and using what I have already written in python.. There are a number of graphics examples, utilities and demos you can use in J and combine it with Python. The new grid classes in J are amazingly useful too. I am just starting to learn Python and I find it interesting to combine it with J. I know a few people who are doing so successfully. There are always some nicetise in any language that can be beneficial. Combining them enhances both. http://groups.google.com/group/j-programminghttp://jsoftware.com/ You can get older versions of the source code too for free. The utility sources are also free. -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert from unicode chars to HTML entities
Steven D'Aprano [EMAIL PROTECTED] wrote: I have a string containing Latin-1 characters: s = u© and many more... I want to convert it to HTML entities: result = copy; and many more... [...[ Is there a batteries included solution that doesn't involve reinventing the wheel? recode is good for this kind of things: $ recode latin1..html -d mytextfile It seems that there are recode bindings for Python: $ apt-cache search recode | grep python python-bibtex - Python interfaces to BibTeX and the GNU Recode library HTH, cheers. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the world need another v0.1 python compiler?
sturlamolden: IMHO, with the presence of static types in Py3K, we should have a static compiler that can be invoked dynamically, just like Common Lisp. Something like def foo(...): bar = static_compile(foo, optimize=2) bar(...) JIT compilers are hyped, static compilers perform much better. This way the programmer can decide what needs to be compiled. This is the reason why CMUCL can compete with most C compilers. Lot of Python code uses Psyco, so maybe it may be better to extend Psyco to that 'static compilation' functionality too: def foo(...): psyco.static_bind(foo) At the moment I think this approach can't improve much the speed of Python programs compared to what Psyco is already able to do. PyPy's RPython and ShedSkin are also to be considered, recently ShedSkin is going to support some of the usual Python forms of lazy processing too. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple SVN/CVS-like library in Python?
On Wednesday 07 February 2007 21:29, Andrea Gavana wrote: Hi All, in our office we work with quite complex input files for a reservoir simulator. Those files have thousands of keywords, switches, sub-keywords and whatever. Every time a modification is requested, we modify the input file and re-run the simulator. Obviously, the possible modifications are innumerable: so, after few months, we lose the records of all the changes we made during time and we don't have anymore a clear history of our work. This can be a problem, as sometimes it happens that an old input file is requested by collegues/sub-companies, and it is a pain to retrieve the correct file and results. So, I have written a GUI in wxPython that could help us in tracking the history, but I was wondering if there exists a small and simple SVN/CVS-like library in Python that may help us in a better way, storing modifications/changes and showing which input file are the children of (are derived from) another input file (older). But I am open to all possible suggestions to improve/modify the software, as this is an area in which my experience is about nothing above zero. Thank you very much for every hint. http://www.selenic.com/mercurial/wiki/ http://www.selenic.com/mercurial/wiki/index.cgi/HgkExtension Andrea. Imagination Is The Only Weapon In The War Against Reality. http://xoomer.virgilio.it/infinity77/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python new user question - file writeline error
Shawn Milo kirjoitti: To the list: I have come up with something that's working fine. However, I'm fairly new to Python, so I'd really appreciate any suggestions on how this can be made more Pythonic. Thanks, Shawn Okay, here's what I have come up with: What follows may feel harsh but you asked for it ;) #! /usr/bin/python import sys import re month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12} infile=file('TVA-0316','r') outfile=file('tmp.out','w') def formatDatePart(x): take a number and transform it into a two-character string, zero padded If a comment or doc string is misleading one would be better off without it entirely: take a number: the function can in fact take (at least) any base type transform it: the function doesn't transform x to anything although the name of the variable x is the same as the argument x two-character string: to a string of at least 2 chars zero padded: where left/right??? x = str(x) while len(x) 2: x = 0 + x You don't need loops for these kind of things. One possibility is to replace the whole body with: return str(x).zfill(2) return x regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: Empty lines are supposed to make code more readable. The above empty line does the contrary by separating the block controlled by the for and the for statement dayNum = formatDatePart(someDate[1:3]) monthNum = formatDatePart(month[someDate[4:7]]) yearNum = formatDatePart(someDate[8:12]) You don't need the formatDatePart function at all: newDate = ,%4s-%02d-%2s, % \ (someDate[8:12],month[someDate[4:7]],someDate[1:3]) newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) line = line.replace(someDate, newDate) outfile.writelines(line) infile.close outfile.close You have not read the answers given to the OP, have you. Because if you had, your code would be: infile.close() outfile.close() The reason your version seems to be working, is that you probably execute your code from the command-line and exiting from Python to command-line closes the files, even if you don't. Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python new user question - file writeline error
On 2/8/07, Jussi Salmela [EMAIL PROTECTED] wrote: Shawn Milo kirjoitti: To the list: I have come up with something that's working fine. However, I'm fairly new to Python, so I'd really appreciate any suggestions on how this can be made more Pythonic. Thanks, Shawn Okay, here's what I have come up with: What follows may feel harsh but you asked for it ;) #! /usr/bin/python import sys import re month ={'JAN':1,'FEB':2,'MAR':3,'APR':4,'MAY':5,'JUN':6,'JUL':7,'AUG':8,'SEP':9,'OCT':10,'NOV':11,'DEC':12} infile=file('TVA-0316','r') outfile=file('tmp.out','w') def formatDatePart(x): take a number and transform it into a two-character string, zero padded If a comment or doc string is misleading one would be better off without it entirely: take a number: the function can in fact take (at least) any base type transform it: the function doesn't transform x to anything although the name of the variable x is the same as the argument x two-character string: to a string of at least 2 chars zero padded: where left/right??? x = str(x) while len(x) 2: x = 0 + x You don't need loops for these kind of things. One possibility is to replace the whole body with: return str(x).zfill(2) return x regex = re.compile(r,\d{2}/[A-Z]{3}/\d{4},) for line in infile: matches = regex.findall(line) for someDate in matches: Empty lines are supposed to make code more readable. The above empty line does the contrary by separating the block controlled by the for and the for statement dayNum = formatDatePart(someDate[1:3]) monthNum = formatDatePart(month[someDate[4:7]]) yearNum = formatDatePart(someDate[8:12]) You don't need the formatDatePart function at all: newDate = ,%4s-%02d-%2s, % \ (someDate[8:12],month[someDate[4:7]],someDate[1:3]) newDate = ,%s-%s-%s, % (yearNum,monthNum,dayNum) line = line.replace(someDate, newDate) outfile.writelines(line) infile.close outfile.close You have not read the answers given to the OP, have you. Because if you had, your code would be: infile.close() outfile.close() The reason your version seems to be working, is that you probably execute your code from the command-line and exiting from Python to command-line closes the files, even if you don't. Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list Jussi, Thanks for the feedback. I received similar comments on a couple of those items, and posted a newer version an hour or two ago. I think the only thing missing there is a friendly blank line after my for line in infile: statement. Please let me know if there is anything else. Shawn -- http://mail.python.org/mailman/listinfo/python-list
Re: begin to parse a web page not entirely downloaded
On Feb 8, 6:54 pm, Leif K-Brooks [EMAIL PROTECTED] wrote: k0mp wrote: Is there a way to retrieve a web page and before it is entirely downloaded, begin to test if a specific string is present and if yes stop the download ? I believe that urllib.openurl(url) will retrieve the whole page before the program goes to the next statement. Use urllib.urlopen(), but call .read() with a smallish argument, e.g.: foo = urllib.urlopen('http://google.com') foo.read(512) 'htmlhead ... foo.read(512) will return as soon as 512 bytes have been received. You can keep caling it until it returns an empty string, indicating that there's no more data to be read. Thanks for your answer :) I'm not sure that read() works as you say. Here is a test I've done : import urllib2 import re import time CHUNKSIZE = 1024 print 'f.read(CHUNK)' print time.clock() for i in range(30) : f = urllib2.urlopen('http://google.com') while True: # read the page using a loop chunk = f.read(CHUNKSIZE) if not chunk: break m = re.search('html', chunk ) if m != None : break print time.clock() print print 'f.read()' print time.clock() for i in range(30) : f = urllib2.urlopen('http://google.com') m = re.search('html', f.read() ) if m != None : break print time.clock() It prints that : f.read(CHUNK) 0.1 0.31 f.read() 0.31 0.32 It seems to take more time when I use read(size) than just read. I think in both case urllib.openurl retrieve the whole page. -- http://mail.python.org/mailman/listinfo/python-list
Functions, parameters
Hi, I'am still learning Python and while reading Django tutorial couldn't understand this part: class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') # Django provides a rich database lookup API that's entirely driven by # keyword arguments. Poll.objects.filter(question__startswith='What') This 'question__startswith' is the problem. What is the common idiom for this type od arguments, so I can Google it? I understand what this filter is suppose to do, but don't know how it is done (this separation of Poll atribute and startwith function). -- http://www.nacional.hr/articles/view/23894/23 -- http://mail.python.org/mailman/listinfo/python-list
Re: Strings in Python
On Feb 8, 8:28 am, Johny [EMAIL PROTECTED] wrote: Playing a little more with strings, I found out that string.find function provides the position of the first occurance of the substring in the string. Is there a way how to find out all substring's position ? To explain more, let's suppose mystring='12341' import string string.find(mystring ,'1') 0 But I need to find the possition the other '1' in mystring too. Is it possible? Or must I use regex? In this case, you can use: mystring = '12341' indices = [ _ for _ in range(len(mystring)) if mystring[_] == '1' ] print indices -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, parameters
Boris Ozegovic a écrit : Hi, I'am still learning Python and while reading Django tutorial couldn't understand this part: class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateTimeField('date published') # Django provides a rich database lookup API that's entirely driven by # keyword arguments. Poll.objects.filter(question__startswith='What') This 'question__startswith' is the problem. What is the common idiom for this type od arguments, so I can Google it? It's a named argument - in Python we usually name them keyword args. http://docs.python.org/tut/node6.html#SECTION00672 I understand what this filter is suppose to do, but don't know how it is done (this separation of Poll atribute and startwith function). Why don't you just read the source code ? Django is free software, you know !-) What about something like: def filter(self, **kw): for argname, value in kw.items(): fieldname, op = argname.split('__', 1) assert fieldname in self.fields # build the query here # etc... -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, parameters
Poll.objects.filter(question__startswith='What') That is an example of a keyword argument. You can read about it in the Python Tutorial: http://docs.python.org/tut/node6.html#SECTION00672 -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, parameters
Boris Ozegovic [EMAIL PROTECTED] writes: Poll.objects.filter(question__startswith='What') This 'question__startswith' is the problem. What is the common idiom for this type od arguments, so I can Google it? You can refer to function args in Python by name, e.g. define a function def print_power(x, y): print x ** y and you can pass the parameters in by position, like in most languages: print_power(5, 2)# prints 25 You can also pass them by name, saying explicitly which arg is which (called keyword arguments): print_power(x=5, y=2) # also prints 25 print_power(y=5, x=2) # prints 32 You can make functions that take arbitrary named parameters. The ** below means that arg gets bound to a dictionary containing all the keyword args: def func(**keyword_args): print 'args are:' for k in keyword_args: print k, '=', keyword_args[k] func(a=2, b=5, c='whee') prints: a = 2 b = 5 c = whee -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, parameters
Bruno Desthuilliers wrote: Why don't you just read the source code ? Django is free software, you know !-) Yes, I know. :) What about something like: def filter(self, **kw): for argname, value in kw.items(): fieldname, op = argname.split('__', 1) Yes, this is what confused me in the first place: how to separate arguments. If you call split, and split returns list of String, then you have fieldname = 'question' and startwith = 'what', and not references at question and startwith, or am I missing something big. -- http://www.nacional.hr/articles/view/23894/23 -- http://mail.python.org/mailman/listinfo/python-list
Re: begin to parse a web page not entirely downloaded
k0mp wrote: It seems to take more time when I use read(size) than just read. I think in both case urllib.openurl retrieve the whole page. Google's home page is very small, so it's not really a great test of that. Here's a test downloading the first 512 bytes of an Ubuntu ISO (beware of wrap): $ python -m timeit -n1 -r1 import urllib urllib.urlopen('http://ubuntu.cs.utah.edu/releases/6.06/ubuntu-6.06.1-desktop-i386.iso').read(512) 1 loops, best of 1: 596 msec per loop -- http://mail.python.org/mailman/listinfo/python-list
Re: Functions, parameters
Boris Ozegovic [EMAIL PROTECTED] writes: def filter(self, **kw): for argname, value in kw.items(): fieldname, op = argname.split('__', 1) Yes, this is what confused me in the first place: how to separate arguments. If you call split, and split returns list of String, then you have fieldname = 'question' and startwith = 'what', and not references at question and startwith, or am I missing something big. Oh, I understand your question now. The call was: Poll.objects.filter(question__startswith='What') 'filter' receives the argument 'kw', which is a dictionary whose value will be { 'question__startswith' : 'What' } That means the for argname, value loop iterates just once, with argname = 'question__startswith' and value = 'What' Since split is applied to argname, it retrieves 'question' and 'startswith'. -- http://mail.python.org/mailman/listinfo/python-list
Re: begin to parse a web page not entirely downloaded
On Thu, 08 Feb 2007 10:20:56 -0800, k0mp wrote: On Feb 8, 6:54 pm, Leif K-Brooks [EMAIL PROTECTED] wrote: k0mp wrote: Is there a way to retrieve a web page and before it is entirely downloaded, begin to test if a specific string is present and if yes stop the download ? I believe that urllib.openurl(url) will retrieve the whole page before the program goes to the next statement. Use urllib.urlopen(), but call .read() with a smallish argument, e.g.: foo = urllib.urlopen('http://google.com') foo.read(512) 'htmlhead ... foo.read(512) will return as soon as 512 bytes have been received. You can keep caling it until it returns an empty string, indicating that there's no more data to be read. Thanks for your answer :) I'm not sure that read() works as you say. Here is a test I've done : import urllib2 import re import time CHUNKSIZE = 1024 print 'f.read(CHUNK)' print time.clock() for i in range(30) : f = urllib2.urlopen('http://google.com') while True: # read the page using a loop chunk = f.read(CHUNKSIZE) if not chunk: break m = re.search('html', chunk ) if m != None : break print time.clock() print print 'f.read()' print time.clock() for i in range(30) : f = urllib2.urlopen('http://google.com') m = re.search('html', f.read() ) if m != None : break A fair comparison would use pass here. Or a while loop as in the other case. The way it is, it compares 30 times read(CHUNKSIZE) against one time read(). Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the world need another v0.1 python compiler?
On Feb 8, 7:02 pm, [EMAIL PROTECTED] wrote: At the moment I think this approach can't improve much the speed of Python programs compared to what Psyco is already able to do. Pyrex generates code that competes with hand-written C. It is as close to statically typed Python as it gets. http://www.scipy.org/PerformancePython -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial 1.0 - Partial classes for Python
Ziga Seilnacht schrieb: Thomas Heller wrote: Do you have a pointer to that post? I think that he was refering to this post: http://mail.python.org/pipermail/python-list/2006-December/416241.html If you are interested in various implementations there is also this: http://mail.python.org/pipermail/python-list/2006-August/396835.html and a module from PyPy: http://mail.python.org/pipermail/python-dev/2006-July/067501.html which was moved to a new location: https://codespeak.net/viewvc/pypy/dist/pypy/tool/pairtype.py?view=markup Thanks for these links. It seems they all (including Martin's partial) implementation all use more or less the same trick (or hack ;-). I agree with most of the posters is this thread that it is confusing to spread the definition of a class over several places or files. But, there are cases where the trick come in handy - when classes are created not by class statements. In ctypes, for example, a pointer type to a ctypes type is created by calling the POINTER function which creates a new class. When you have done this, the usual way to add additional methods to the new class is by assigning them like this: from ctypes import * pointer_to_c_int = POINTER(c_int) @classmethod def from_param(cls, value): ... do something ... pointer_to_c_int.from_param = from_param IMO, using the tricky class in the recipes mentioned above, you can write instead: class pointer_to_c_int(partial, POINTER(c_int)): @classmethod def from_param(cls, value): ... do something ... Thomas -- http://mail.python.org/mailman/listinfo/python-list
default mutable arguments
I read that this is not the same: if arg is None: arg = [] arg = arg or [] def functionF(argString=abc, argList = None): if argList is None: argList = [] # this ... def functionF(argString=abc, argList=None): argList = argList or [] # and this ... Why? thanks !!! -- http://mail.python.org/mailman/listinfo/python-list