Re: problem with split
On 6 Oct 2006 23:09:08 -0700, MonkeeSage [EMAIL PROTECTED] wrote: On Oct 6, 11:33 pm, hanumizzle [EMAIL PROTECTED] wrote: import re snip if line.startswith('instr'): p = re.compile(r'(\d+)\s+;(.*)$') m = p.search(line) return (m.group(1), m.group(2)) You probably don't want startswith, in case there are initial spaces in the line. Pardon me; I am not very familiar with file format in question. Also, since the regexp is single use, you can just use the re.search class method, which will compile the regexp implicitly. Cool. May also want to strip the second grouped match, in case of trailing spaces. Cosmetic, but good idea. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Subclassing built-in classes
On 10/7/06, Gabriel Genellina [EMAIL PROTECTED] wrote: At Friday 6/10/2006 06:58, Maric Michaud wrote: As the first post said ...couldn't python (in theory)..., I was discussing if it would be possible for python (in some future version) to manage the literals so that they use the constructors in the __builtin__ module, I didn't say it works actually (I'm aware it's not the case). The idea looks crazy for me... You suggest that code like this: x = 12 + 6.0 - len('ABCD' would be evaluated at run time as it were: x = int('12') + float('6.0') - len(str('ABCD')) Certainly would slow down the whole execution time *a*lot*, with no benefit for almost nobody, if *every* reference to *any* literal in the code calls a python function at run time. And unless you return *exactly* the same object as now, almost all code would break! Do you have any useful usage for this? Sometimes I've had weird ideas that I thought might be useful, but they turned out to be doo doo. On other occasions, the SWAG paid off (e.g., vesa driver runs faster than accelerated via driver for compositing in Xorg) It's all a matter of proposing and disposing, and mistakes happen. Somehow, I missed Python's round() function and came up with convoluted solution involving decimal. Gee duh, Theerasak -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich text processor component
On 10/6/06, Jorge Vilela [EMAIL PROTECTED] wrote: Hello, do anyone know if exists anything about rich text processor in python, as a component or good tutorial about it? http://pyrtf.sourceforge.net/ Regards, Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: need some regular expression help
On 7 Oct 2006 15:00:29 -0700, Diez B. Roggisch [EMAIL PROTECTED] wrote: Chris wrote: I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = [ '((2x+2)sin(x))', '(log(2)/log(5))' ] Can anybody help me out? This is not possible with regular expressions - they can't remember how many parens they already encountered. Remember that regular expressions are used to represent regular grammars. Most regex engines actually aren't regular in that they support fancy things like look-behind/ahead and capture groups...IIRC, these cannot be part of a true regular expression library. With that said, the quote-unquote regexes in Lua have a special feature that supports balanced expressions. I believe Python has a PCRE lib somewhere; you may be able to use the experimental ??{ } construct in that case. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an alternative to os.walk?
On 10/8/06, Tim Roberts [EMAIL PROTECTED] wrote: Umm, may I point out that you don't NEED the os.path.exists call, because you are already being HANDED a list of all the filenames in that directory? You could dirtest with this much faster routinee: def dirtest(a_dir,filenames): for f in ['a','b','c']: if not f in filenames: return 0 return 1 Or False / True for sufficiently new versions of Python. :) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw beginner....
On 10/8/06, Colin Lehmann [EMAIL PROTECTED] wrote: I am new to Python although I have been using Delphi since version one, I have been employed as a C and C++ programmer so when I went to Linux (Ubuntu 5.10) I thought Python looked pretty good. I downloaded and installed 'Eric Python IDE' which seems OK, any alternatives suggested will be looked at Myself, I just use GNU Emacs. But this is perhaps an acquired taste. My current problem is I am trying to compile a package I downloaded, it is a PodCaster called 'CastPodder'!!), I looked at the source file and it tried to import something called 'wxversion' and couldn't find it. Please copy and paste the exact error messages into a reply. I searched the net and found a package called 'Python wxversion???.Deb'. Downloaded it and unpacked it but the IDE still can't find it! Have you installed the base wxpython package as well? Furthermore, are you using Ubuntu package? I don't know Debian variants too well, but it seems best to go with the official release. http://packages.ubuntu.com/cgi-bin/search_packages.pl?keywords=wxsearchon=namessubword=1version=dapperrelease=all My question is : Where should I put the package (download it to..) so when I unpack it the IDE can find it? I looked around and found a reference to PYTHONPATH which is supposed to tell Python where everything is but I simply cannot find it anywhere. I found sys.path but I don't think that is what I want sys.path and PYTHONPATH do configure the location of Python libraries for special purposes. sys.path is actually a list of all standard locations for libraries built-in to Python at compile time as well as nonstandard locations given in PYTHONPATH or through command line arguments. You can even add to sys.path dynamically I think. But wxpython from Debian/Ubuntu should install to a standard location. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 5 Oct 2006 22:54:46 -0700, MonkeeSage [EMAIL PROTECTED] wrote: hanumizzle wrote: Why a subset? I don't think JSON is a subset of YAML. Apparent slip of the fingers by OP. From JSON website: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. I'm happy with my Pythonesque YAML syntax, thank you. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 5 Oct 2006 23:19:18 -0700, MonkeeSage [EMAIL PROTECTED] wrote: On Oct 6, 1:06 am, hanumizzle [EMAIL PROTECTED] wrote: I'm happy with my Pythonesque YAML syntax, thank you. :) YAML is a little more complex, and a little more mature. But JSON should not be ruled out. I actually like JSON personally. I guess I'll keep an open mind. But I like editing YAML for the same reason that I like editing Python. (Although I admit I usually I gen my data structures in ipython and then dump them.) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: profiling memory usage
On 5 Oct 2006 16:21:50 -0700, Eddie [EMAIL PROTECTED] wrote: Hi, I am looking for a method to profile memory usage in my python program. The program provides web service and therefore is intended to run for a long time. However, the memory usage tends to increase all the time, until in a day or two the system cannot handle it any more and starts to do constant swapping. Is there a way to look at which objects or variables are taking the huge amount of memory space? Have a look at: http://www.velocityreviews.com/forums/t353289-memory-profiler.html -- Remember that time Thotsakan punched Neil Bush in the dick? -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 10/6/06, Fredrik Lundh [EMAIL PROTECTED] wrote: MonkeeSage wrote: YAML is a little more complex a little? when did you last look at the spec? and a little more mature. than JavaScript's expression syntax? are you sure you're not confusing libraries with standards here? (has anyone even managed to write a YAML library that's small and simple enough to be obviously correct?) Tell. I'm interested in knowing. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 10/6/06, Fredrik Lundh [EMAIL PROTECTED] wrote: hanumizzle wrote: I guess I'll keep an open mind. But I like editing YAML for the same reason that I like editing Python. JSON is almost identical to Python's expression syntax, of course, while YAML isn't even close. Getting the source now. S'pose it isn't too late to convert my project over... -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 5 Oct 2006 23:43:50 -0700, MonkeeSage [EMAIL PROTECTED] wrote: On Oct 6, 1:28 am, Fredrik Lundh [EMAIL PROTECTED] wrote: when did you last look at the spec? I'm fairly versed in JS objects, having written 10 or so extensions for firefox; but I've only used YAML for trivial tasks like config files. So I can't really say how they stack up in the big picture. But from what I have seen, JSON is a simpler and easier to use format than YAML. That and it sounds like Strongbad pronouncing the name 'Jason'. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Block Structure Parsing
On 10/4/06, Blacktiger [EMAIL PROTECTED] wrote: Hi all, I'm new to this list because I had a question about parsing python block structure. I am taking a programming languages course this semester and for our final project we are writing an interperator in scheme(awful language) for whatever language that we want. The language that I want to do is one I have been designing for a little while and it shares some syntactic features of Python; most notably the block structure. What dialect of scheme are you limited to, if any? Because PLT and Chicken appear to have the widest selection of extensions, it might be good to look at them. Already on the chicken website (the cumbersome http://www.call-with-current-continuation.org/eggs/) I found this: http://www.iro.umontreal.ca/~boucherd/Lalr/documentation/lalr.html. Might be what you need, might not, can't be sure. Or you can just cheat, use s-exp syntax with unique semantics, and then use (read) as your 'parser'. :) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange sorting error message
On 10/5/06, Neil Cerutti [EMAIL PROTECTED] wrote: It was a joke, based on you hiding what you are doing, he decided to hide the solution to your problem. Get it? What if it was for a proprietary software of some kind? -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do this?
On 10/6/06, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Thu, 5 Oct 2006 11:28:08 +0100, Matthew Warren [EMAIL PROTECTED] declaimed the following in comp.lang.python: Now, I started programming when I was 8 with BBC Basic. Remember what the acronym BASIC stands for? Boobie-drawing Adolescent Symbolic Instruction Code. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI Tutorial
On 10/5/06, Sells, Fred [EMAIL PROTECTED] wrote: content is great, my comments are editorial. wrt what document? I prefer PDF with bookmarks rather than HTML. 1. easy to print the whole thing and read offline. 2. easy to find a secion from bookmarks, rather that chasing links 3. easy to save on my local doc folder so I can be sure It will always be there. (i.e. I don't have to try to find it when you change servers) wget will save you everytime. Of course that's just my opinion, I could be wrong ;) If you choose to go the PDF route, I've found OpenOffice 2.0 pretty good at generating PDF with bookmarks. Just don't get too complex or OO may hose you. LyX + pdflatex :) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Package to handle table text render (handle space or tab between the columns) ?
On 10/6/06, KLEIN Stéphane [EMAIL PROTECTED] wrote: Hi, I would like print tabular values on terminal (stdout). Are there package to handle table text render ? Have a look at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662 -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Package to handle table text render (handle space or tab between the columns) ?
On 10/6/06, KLEIN Stéphane [EMAIL PROTECTED] wrote: hanumizzle a écrit : On 10/6/06, KLEIN Stéphane [EMAIL PROTECTED] wrote: Hi, I would like print tabular values on terminal (stdout). Are there package to handle table text render ? Have a look at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662 Thanks, this package is very useful ! But I'm suprised than this package isn't in python standard library ! The occurence of such a problem is relatively rare I would imagine. Rendering anything formatted to a character cell terminal is inherently limited, which is why I like lynx: it eliminates all the dumb formatting crap that people put on their websites, and even collapses multiple columns into a single stream of pages. Yay! See also reStructuredText for rendering plain text input to HTML and other formats (includes tables), sil vous plait. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 6 Oct 2006 01:41:48 -0700, virg [EMAIL PROTECTED] wrote: Hi, The data is simple dictionary with one or more keys. If i use YAML at the client (webui) do i have to change serialisation method to YAML at server also. Without changing serialisation method at server, can i use any of the deserialisation methods at the client. We cannot change the serialisation methods at the server since it is not under our control. Oh, poopy. What do you have at the server end? -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 10/6/06, Steve Holden [EMAIL PROTECTED] wrote: I have to agree that YAML, having started out with simplicity in mind, has become a monster that threatens to collapse under its own weight. The very existence of JSON is a good indicator that YAML has failed to meet its design goals for a significant proportion of application developers. I am looking at JSON, but YAML does work fine for my purposes w/ no discernable disadvantages. Of course I didn't implement the library, so I can't really speak with any kind of expertise on this matter. I'm just saying that, at least at the front end, it's pretty simple to use. (JMO) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 6 Oct 2006 02:03:07 -0700, virg [EMAIL PROTECTED] wrote: At the server, based on client request it does some computations , it sends the result as dictionary (serialized) to the client. If I interpret your message correctly, you are receiving a Python dictionary object from the server. Yes? In this case, I guess it might be necessary to use Jython. I'm drawing a blank otherwise. (This may be naive, but can you write the client in Python as well?) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 6 Oct 2006 09:21:11 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: On 2006-10-06, Fredrik Lundh [EMAIL PROTECTED] wrote: Antoon Pardon wrote: Is this general rules documeted somewhere? My impression is that readers of the documentation will treat arguments as keyword arguments unless this is explicitly contradicted. Sorry, I missed that this was comp.lang.python.alternate.reality. My mistake. A personal attack won't make my argument go away. It also doesn't answer my question. Not sure exactly what is going on / being argued about in this thread but HTH :? http://docs.python.org/tut/node6.html This doesn't say anything positive or negative about the practice in question, but does point out that it is possible. I think it is a reasonable assumption that if it isn't necessary, most users will elide the keywords. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: printing variables
On 10/6/06, Gerrit Holl [EMAIL PROTECTED] wrote: import fnmatch var1, var2, var3 = foo, bar, baz for k in fnmatch.filter(locals(), var*): ... print locals()[k] ... foo baz bar This is evil. It's unpythonic. It's so evil, Perl 4 would look upon it in scorn. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 6 Oct 2006 02:29:59 -0700, virg [EMAIL PROTECTED] wrote: Yes your are right. I will send a dictionary object from the server to the client. I already have client which is written in python. But we are migrating the python client which is a command line tool to Web UI client (java). Please explain 'Web UI'. Can Python perform an equivalent function? -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: HOST - Assembla Inc. Breakout - Copyright Violation by Mr. Andy Singleton
On 10/6/06, Diez B. Roggisch [EMAIL PROTECTED] wrote: This is on the same level of interest to the communities of python, ruby java as the color of my socks this morning - a deep black with cute little skulls imprinted. Where did you get these? -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Names changed to protect the guilty
On 6 Oct 2006 16:27:51 -0700, Aahz [EMAIL PROTECTED] wrote: The following line of lightly munged code was found in a publicly available Python library... if schema.elements.has_key(key) is False: if not schema.elements.has_key(key): or, actually, if not key in schema.elements: is how I would write it, but this reads more like English. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 6 Oct 2006 10:57:01 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Again that is not the fault of those that read the documentation. If this discinction can't be easily made in python 2.X, you can't fault the reader for coming to a conclusion that seems to follow rather naturally from how python currently works. It would depend on prior experience with programming (and perhaps mathematics). -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Can't get around IndexError: list index out of range
On 6 Oct 2006 16:57:23 -0700, erikcw [EMAIL PROTECTED] wrote: I ended up using len(sys.argv) 1 for this particular problem. But I think slicing is closer to the tool I was looking for. I found a.has_key(k) or k in a for dictionaries - but haven't found anything similar for lists. Does it exist? As Gabriel Genellina observed, lists also may use the 'in' syntax. Actually, any object that supports the method __contains__ can do this, which means you may furnish your own in user objects. What hasn't been addressed is efficiency. This is often a secondary concern in a VHLL such as Python, but you may wish to know that using the 'in' test on a large list repeatedly will slow down a program. You may wish to use a set object instead, according to the application. I guess my example from php would technically be a dictionary in python and not a list, it would nice to be able to quickly tell if a list key existed or not. Yes, PHP arrays are associative (dicts). But lists (in the Pythonic sense, aka 'vectors') do not have keys as such, only indices. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary containing a list
On 6 Oct 2006 14:37:59 -0700, Ben [EMAIL PROTECTED] wrote: Is there a way to acheive what I was attempting ? I have done something almost identical with classes in a list before, and in that case a new instance was created for each list entry... Not sure what you're trying to pull off, but you may wish to copy the items in question. (Questions indeed!). Dictionarys have their own shallow copy method, surprisingly named copy, and there is also a copy module that does shallow and deep copy (copy and deepcopy, resp.) HTH, Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] Detect a key press
On 10/6/06, Sergei Organov [EMAIL PROTECTED] wrote: Try print -%s\r % ch or just sys.stdout.write(ch) Ah! -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive descent algorithm able to parse Python?
On 10/6/06, Diez B. Roggisch [EMAIL PROTECTED] wrote: Lawrence D'Oliveiro schrieb: In message [EMAIL PROTECTED], Diez B. Roggisch wrote: I have to admit that I have difficulties to compare LR(k) to recursive descent, but the fact that the latter contains backtracking makes it at least more powerful than LL(k) LR(k) is more powerful than LL(k). I know _that_, the point was that recursive descent is more power full than LL(k) Correct me if I'm wrong, but recursive descent parsers are top-down, yes? Parse::RecDescent in Perl is a top-down parser. It can even do some context-sensitive grammars and can almost certainly handle Python. Is Python context-free? Not sure. Does left parenthesis opening either a function call (x) or an empty tuple () count as context-sensitive, for instance? Or can () be considered a terminal symbol unto itself? I am new to most of this :) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: Skullsocks to the rescue - was [irrelevant squabble of IL]
On 10/6/06, Diez B. Roggisch [EMAIL PROTECTED] wrote: Fredrik Lundh schrieb: Diez B. Roggisch wrote: This is on the same level of interest to the communities of python, ruby java as the color of my socks this morning - a deep black with cute little skulls imprinted. are they perhaps red or green? and look something like the skulls on this: Due to the unexpected interest in my foot-garments, I here present an image of my current collection of skullsocks(tm) Eric Cartman: KICK ASS -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: extract certain values from file with re
On 6 Oct 2006 13:16:13 -0700, Matteo [EMAIL PROTECTED] wrote: Coming from C++, using exceptions in this way still feels a bit creepy to me, but I've been assured that this is very pythonic, and I'm slowly adopting this style in my python code. Parsing the line can be easy too: (umom,vmom,wmom,mass...) = map(float,vals[1:]) Style question. Should one consider the map functional deprecated and use [float(val) for val in vals[1:]] or no? I'm not sure myself. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with split
On 6 Oct 2006 21:07:43 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I want comment returned in an array and instr_number returned in an array. Let me see if I understand what you want: if there is a line that starts with instr (best tested with line.startswith('instr') :)), you want the number and the commen afterwards. I used regexes for this purpose. In your case: import re snip if line.startswith('instr'): p = re.compile(r'(\d+)\s+;(.*)$') m = p.search(line) return (m.group(1), m.group(2)) I returned a tuple of course; you may wish to change that. BTW, thank you -- I just learned how to use re's in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with split
On 10/7/06, goyatlah goyatlah wrote: Think you need a regex like this: regex = r\s*instr\s+([0-9]+)\s*(;.*)? [0-9] maybe written simply as \d (d for digit) Then: import re test = re.compile(regex) Regexes are usually passed as literals directly to re.compile(). testing is done as follows: res = test.match(mystring) Initial \s* is redundant if you use the search() method. if res: I forgot that part. :) number = res.group(1) # always a string consisting of decimals comment = res.group(2) # string starting with ; or None it might be necessary to have the instr part of the regex as follows [iI][nN][sS][tT][rR] to handle things like Instr or INSTR. It is sufficient to use the re.IGNORECASE flag. -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I put % in a format sting?
On 10/5/06, Gregory Piñero [EMAIL PROTECTED] wrote: Thanks guys, putting it twice is all it took! This rule holds true for a lot of string formatting conventions. (such as in regexes) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: CGI Tutorial
On 5 Oct 2006 14:56:54 -0700, Jim [EMAIL PROTECTED] wrote: * You need a DEBUG variable: from defaults import DEBUG : if DEBUG: .. WADR, there is a more formal way to do this: http://docs.python.org/ref/assert.html Use -O to remove the assert statements, essentially: -O sets the builtin var __debug__ to False. (BTW, thank you for making a Linear Algebra textbook that an innumerate dolt like myself can almost understand.) -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary of list from a file
On 4 Oct 2006 06:09:21 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi guys, this is my first post. my programming background is perlish scripting and now I am learning python. I need to create a dictionary of list from a file. Normally in perl I use to do like: You may wish to consider some kind of data serialization. For python specifically, there's pickle and cPickle, for many platforms there is YAML (I recommend this; the py binding is really good), and as a last resort you can use XML (yuck). -- http://mail.python.org/mailman/listinfo/python-list
Re: [Linux] Detect a key press
On 5 Oct 2006 21:45:47 -0700, Jia,Lu [EMAIL PROTECTED] wrote: Hi all I write a program to detect key press,but , why there is a *space* before the character I typed.?? Puzzles me too, but I know this is really easy in Curses (on top of that, it isn't specific to Linux; curses works on many terminals) http://www.amk.ca/python/howto/curses/ -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 5 Oct 2006 21:52:56 -0700, virg [EMAIL PROTECTED] wrote: Hi, i have client-server application which is written in python using XMLRPC protocol. The existing client is a command line. Now client application we are converting it as Web UI using java. I have seen some problems in writing a java client. At the server for each request from client, the server sends a response in hashtable and is serialized using pickle. The python function we call at the server is... What kind of data are we talking about? Is it strictly dictionary / list stuff or is it more complex (functions other objects)? I can see 2 possible options: Jython or YAML. (I have been answering a lot of questions re: serialization today and mentioned YAML in all of them :)) -- http://mail.python.org/mailman/listinfo/python-list
Re: A Universe Set
On 10/4/06, Wildemar Wildenburger [EMAIL PROTECTED] wrote: Jorgen Grahn wrote: - the wildcard object, which compares equal to everything else - infinite xrange()s - the black hole function 'def f(*args): pass' - the identity function 'def f(x): return x' Any use cases for these? I used the last one in my .emacs (but it had a lot to with stupid emacs lisp). It might also be useful for some theoretical aspects of FP and mathematical applications (maybe! IANAE!!). See: http://en.wikipedia.org/wiki/Fixed_point_%28mathematics%29 -- Theerasak -- http://mail.python.org/mailman/listinfo/python-list
Re: was python implemented as a object oriented langage at the beginning ?
On 10/4/06, Bruno Desthuilliers [EMAIL PROTECTED] wrote: has wrote: Python's type/class distinction Which type/class distinction ? I think he means pre 2.2. (?) -- http://mail.python.org/mailman/listinfo/python-list
Re: help on pickle tool
On 5 Oct 2006 22:25:58 -0700, Paddy [EMAIL PROTECTED] wrote: You might try picking the data with a different pickle formatter that your Java can use. Maybe an XML pickler (http://www.gnosis.cx/download/Gnosis_Utils.More/Gnosis_Utils-1.2.1.ANNOUNCE untested by me). You might also use a JSON/YAML pickler. JSON is now a subset of YAML: http://cheeseshop.python.org/pypi/python-json/3.4 http://pyyaml.org/wiki/PyYAML http://jyaml.sourceforge.net/ http://www.yaml.org/ http://www.json.org/ http://www.json.org/java/ Why a subset? -- http://mail.python.org/mailman/listinfo/python-list
kudos
After a long hiatus, I finally found *something* as a vehicle to learn Python. My friends and I are (hopefully) getting together to play FEAR RPG and I decided to use Python to write chargen utilities and such. What do I have to say? Except for not having TrueClosures, which can be emulated with objects anyway, way better than Perl. Of course I still develop and one-line frob with Perl, but Python might even take over in the latter capacity if I become fluent as I have in Perl. The community is also a significant advantage always, which is why I use Vector Linux as well. In principle, I like Ruby in some ways better than I do Python, but as far as pragmatism goes: Py for teh win! ipython just owns house on irb. Had to say it. reStructuredText looks like it might also be very useful to me. Greetings to all. -- What if Iraqis were blastocysts? -- http://mail.python.org/mailman/listinfo/python-list
Re: python html rendering
On 10/3/06, Colin J. Williams [EMAIL PROTECTED] wrote: Another approach is to use PyScripter (an editor and IDE). One can generate documentation and then save the generated html doc. Also PyDoc can be used directly. And if you want to go the traditional way, Emacs and Vim can both be used to produce colored HTML IIRC. Not sure about Vim (something like 2html.vim I believe), but Emacs has htmlize.el. If someone already said this, pardon me; I just joined via python-list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Resuming a program's execution after correcting error
On 3 Oct 2006 16:58:17 -0700, MRAB [EMAIL PROTECTED] wrote: I like your idea Matthew but I don't know how to pickle the many variables in one file. Do I need to pickle each and every variable into a seperate file? var1,var2 pickle.dump(var1,f) pickle.dump(var2,f2) Using the 'pickle' module: # To store: f = open(file_path, wb) pickle.dump(var1, f) pickle.dump(var2, f) f.close() # To load f = open(file_path, rb) var1 = pickle.load(f) var2 = pickle.load(f) f.close() A more flexible alternative is to use the 'shelve' module. This behaves like a dict: # To store s = shelve.open(file_path) s[var1] = first s[var2] = [2, 3] s.close() # To load s = shelve.open(file_path) print s[var1] # This prints first print s[var2] # This prints [2, 3] s.close() As long as we're on the subject of data serialization, I should like to bring up PyYaml. YAML is a portable format for storing data of all kinds; it became popular via Ruby I think, but there are implementations for many other languages. If you stick to storing simple stuff like lists, strings, and dictionaries, you can use your YAML data almost anywhere, but PyYaml even supports reifying things like lambdas. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dive Into Python -- Still Being Updated?
Alan Franzoni wrote: Il 22 Jul 2006 15:48:36 -0700, [EMAIL PROTECTED] ha scritto: http://diveintopython.org/getting_to_know_python/indenting_code.html The function called fib (presumably short for Fibonacci) appears to produce factorials. Anyway, 'fib' should really be called 'hem'. :) I think this is just a bad name for the function... it's not stated anywhere that it should return a Fibonacci sequence. Well, yeah, my point. It's misleading. He was on the right track (it is a sequence), but he goofed a little. In general, Mark Pilgrim's material is pretty damn good. http://diveintopython.org/native_data_types/tuples.html#odbchelper.tuplemethods I think tuples have methods, na? Well... of course they have some *special* methods, (any python object has) but they have no method of their own. I think this is pretty clear, it's employed to emphasize the contrast with the list object. I'm coming from Perl/Ruby, so maybe I don't grasp the concept of 'special' methods yet. BTW, you can see last update is 20 May 2004; it's right on the homepage. I know :( ...it is open content (GFDL), so I suppose I could pick it up...maybe later :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Pyton Book For Newbies?
Bob Sinclar wrote: Web programming is all about stdin stdout. Recommanded practice before going further. It's actually a little more (at least as far as CGI is concerned)...it bears some level of abstraction, namely, a decent CGI lib. -- http://mail.python.org/mailman/listinfo/python-list
Re: Type signature
Yacao Wang wrote: Hi, I'm a newbie to Python. I've recently read some books about this language and none of them have answered my question. As a dynamically-typed language Python doesn't need any form of type signature which makes the syntax very clean and concise. OK... However, type signatures are not only a kind of information provided for the compiler Statically-typed code tends (generally) to be faster than dynamically-typed code, obviously. Often, it doesn't really matter, though. (This is an old argument.) Lush is an interesting Lisp-like language that supports admixture of dynamic and static typing, and uses type signatures to support it. It can produce high performance machine code because of this. Python relies too much on run-time type-checking, that is, whenever you give the wrong type, you just end up with an exception, which is logically correct, but not that useful as type signatures. As said before, polymorphism plays an important role. In addition to looking up 'duck typing' (c.f. Programming Ruby), it might also be useful to look for Damian Conway's observations on 'interface polymorphism' (standard practice in Perl, Python, Ruby, etc.) vs. 'inheritance polymorphism' (what you get with C++ and IIRC Java). -- http://mail.python.org/mailman/listinfo/python-list
Dive Into Python -- Still Being Updated?
I find Dive Into Python generally an excellent text, and I am not surprised to see people recommending it...but I have noticed a few errors already: http://diveintopython.org/getting_to_know_python/indenting_code.html The function called fib (presumably short for Fibonacci) appears to produce factorials. Anyway, 'fib' should really be called 'hem'. :) http://diveintopython.org/native_data_types/tuples.html#odbchelper.tuplemethods I think tuples have methods, na? [EMAIL PROTECTED]:~$ python Python 2.4.3 (#1, Jun 20 2006, 11:52:59) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type help, copyright, credits or license for more information. print \n.join(dir(tuple)) __add__ __class__ __contains__ __delattr__ __doc__ __eq__ __ge__ __getattribute__ __getitem__ __getnewargs__ __getslice__ __gt__ __hash__ __init__ __iter__ __le__ __len__ __lt__ __mul__ __ne__ __new__ __reduce__ __reduce_ex__ __repr__ __rmul__ __setattr__ __str__ -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Pyton Book For Newbies?
W. D. Allen wrote: I want to write a retirement financial estimating program. Python was suggested as the easiest language to use on Linux. I have some experience programming in Basic but not in Python. I have two questions: 1. What do I need to be able to make user GUIs for the program, and 2. Which book would be easiest to use to learn Python programming? I am a fairly experienced programmer and I have been reading Dive Into Python. If you have prior experience, you may find it very satisfactory. (But see a recent thread I started which points out a few small mistakes...nothing too bad over all.) If you have less programming experience, you may wish to look at Byte of Python. The great thing about Python is that there is a ton of online material to peruse... -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
Dhanyavaad (thank you) -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
Scott David Daniels wrote: [EMAIL PROTECTED] wrote: ... Is the Python debugger fairly stable? Yes, but it is not massively featured. The Pythonic way is to rarely use a debugger (test first and straightforward code should lead to shallow bugs). Often for most of us judiciously placed print statements suffice. The one you get with Perl stinks on ice. More than anything else, I would like to have a powerful OO environment where I do not have to worry about the debugger sucking Do watch your language on this newsgroup. Lots of people read this group and there is no good reason to offend them. In turn, you will be cut some slack. As one who avidly studies language, I have observed that the meaning of a word slip out of its original context through idiomatic usage. If I had included the implicit object of 'sucks', then you would have more grounds for complaint. However, 'sucks', used in the intransitive sense, is no worse than 'bites the bag'. Think about the word 'mogul'. Like 'oil mogul' or 'software mogul'. Well, the **Mughals**, whence comes the word, were mass-murderers: http://www.geocities.com/hindoo_humanist/mughal.html If you were a Hindu in those times, saying 'oil mogul', would be equivalent to saying 'oil Stalin' or 'oil Hitler' today. But this isn't about human rights so much as it is about semantics. (Nobody likes long-winded, abstract philosophical discussions on a technology NG.) 'Sucks' doesn't mean what it used to, at least how I used it there. Unless one is willing to investigate the etymology of every word he uses (like mogul, Christian, or juggernaut), there needs to be a more lenient attitude towards use of language. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
Exactly...this is how most of my Perl modules are written and tested, actually. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
Scott David Daniels wrote: [EMAIL PROTECTED] wrote: Scott David Daniels wrote: [EMAIL PROTECTED] wrote: ... Is the Python debugger fairly stable? Yes, but it is not massively featured. The Pythonic way is to rarely use a debugger (test first and straightforward code should lead to shallow bugs). Often for most of us judiciously placed print statements suffice. The one you get with Perl stinks on ice. More than anything else, I would like to have a powerful OO environment where I do not have to worry about the debugger sucking Do watch your language on this newsgroup. Lots of people read this group and there is no good reason to offend them. In turn, you will be cut some slack. As one who avidly studies language, I have observed that the meaning of a word slip out of its original context through idiomatic usage. If I had included the implicit object of 'sucks', In fact I elided the ass from your original sucks ass in my original quote, and now you carefully forget it in order to bolster your case. D'oh! You are right. That's why I always liked BB Forums. You get to pull Big Brother 'rectifications'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
Dennis Lee Bieber wrote: On 12 Mar 2006 17:58:43 -0800, [EMAIL PROTECTED] declaimed the following in comp.lang.python: Double-underscore methods are rewritten with the class name? That's an ugly hack, but remember I'm coming from Perl. If the language doesn't pull many other hijinks, that's OK. Compared to a language that added OO by requiring the user to bless things to make it behave as an object, you find name-mangling for private methods to be ugly? I saw the duplicity in my own post; mai ben rai. :D I suggest you never look under the hood of a C++ compiler...They not only name-mangle, but add such crud as type/size codes for arguments and return value -- all to be able to invoke the correct method due to overloading. I've heard about the brain damages of C++. Never programmed in it; don't need to. If I were ever forced to program C++ as a result of a career, I think I would probably quit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very, Very Green Python User
bruno at modulix wrote: [EMAIL PROTECTED] wrote: I have used Perl for a long time, but I am something of an experimental person and mean to try something new. Most of my 'work' with Vector Linux entails the use of Perl (a bit of a misnomer as it is not now a paid position -- I am not yet even out of K-12), and there a lot of things I love about it. I can look past a number of misfeatures in Perl, but I am surprised to see that Python has very few (that I know of). Most of them are documented here, it would seem: http://www.c2.com/cgi/wiki?PythonProblems. Seems that this page is sometimes just plain wrong and somewhat outdated. Let's see some of them: I doubt it not. The CC wiki is full of blowhards. 1/Memory Management The reference implementation uses reference counting, the worst-performing memory management scheme there is Actually, Python uses *both* reference-counting and a garbage collector. ...that, and ORO is the worst-performing memory management scheme there is. Look at NewLISP for an implementation. 2/ No Ternary If Well... actually true, but not such a major annoyance. NB : the tuple_dispatch option works well if you know how-to python. IOW, you can avoid useless evaluation with a simple lambda : result = (lambda: action_if_true, lambda : action_if_false)[test]() Ternary if, in itself, is a lame substitute for the free combination of expressions available in Lisp, where all flow-control statements are, in fact, functions (or special forms for the pedantic; the semantics I'm talking about are the same regardless). You can regress with that argument to the logical conclusion that everyone should be a 'SmugLispWeenie'. 4/ Speed Never been a problem for me so far. Yeah, as I say, the bottleneck in speed is usually user interaction. 5/ Ugly mechanism for privates This is *not* a mechanism for privates. This is a mechanism to protect some crucial implementation attributes from being *accidentally* overriden in a child class. I get it now. It would be kind of nice if these 'isolated' methods had their own 'namespace', but I can't complain too much. Perl can use closures as private methods, which is pretty nifty. I never used them like this though, because I don't really believe in the concept of private methods. (Although what you described above is reasonable enough.) After I stopped programming C, I quickly adopted this maxim: validation occurs only on user (or cracker, as the case may be) input. If the programmer is being a dick, that's his/her problem. A couple blemishes I'm concerned about, though: Python closures are apparently very poor, In Python, encapsuling state is better done with objects. Once you'll get a better understanding of Python's object model, you'll find out that there's not such a need for more powerfull closures (well, that's MHO at least). Amongst other things, functions and methods are objects, and any other class can be made callable if you implement a method for the call operator... I used to kind of / sort of program Lisp and Scheme, so I just like first-class everything. I also disagree with the sentiment against deep binding in lambdas (lambdae?) that seems to prevail in the Python community. I used deep binding like this once in my .emacs (my .emacs is SICK); I had to (require 'cl) just to use lexical-let. It was in fact quite useful and no mutation of values in the lexical environment was necessary. but from what I can surmise of the PyGTK2 page, instances of objects are dynamic enough to add new methods, so you get your callbacks, at least. You don't even need this to use callbacks. Remember, functions and methods are objects, and other objects can be callable too... Eh?? I need an example. Double-underscore methods are rewritten with the class name? That's an ugly hack, Ever looked at what a C++ compiler do to symbols ?-) I'm afraid I don't want to know. but remember I'm coming from Perl. Talking about ugky hacks... !-) Not all hacks are ugly. -- http://mail.python.org/mailman/listinfo/python-list
Very, Very Green Python User
I have used Perl for a long time, but I am something of an experimental person and mean to try something new. Most of my 'work' with Vector Linux entails the use of Perl (a bit of a misnomer as it is not now a paid position -- I am not yet even out of K-12), and there a lot of things I love about it. I can look past a number of misfeatures in Perl, but I am surprised to see that Python has very few (that I know of). Most of them are documented here, it would seem: http://www.c2.com/cgi/wiki?PythonProblems. Is the Python debugger fairly stable? The one you get with Perl stinks on ice. More than anything else, I would like to have a powerful OO environment where I do not have to worry about the debugger sucking ass. A couple blemishes I'm concerned about, though: Python closures are apparently very poor, but from what I can surmise of the PyGTK2 page, instances of objects are dynamic enough to add new methods, so you get your callbacks, at least. Double-underscore methods are rewritten with the class name? That's an ugly hack, but remember I'm coming from Perl. If the language doesn't pull many other hijinks, that's OK. I have plenty of docs and stuff, now I'm just looking for wisdom. As a seasoned Python user, what do you have to impart? -- http://mail.python.org/mailman/listinfo/python-list