Re: Python documentation problem

2005-06-18 Thread Xah Lee
Apparently i tried it before posting eval '3' and got misleading errors because i forgot the parenthesis... This is a easy one to find in the doc... The unhelpful doc organization and past experiences confounded this case. Thanks. Xah [EMAIL PROTECTED] http://xahlee.org/ --

Re: Python documentation problem

2005-06-18 Thread Xah Lee
what is wrong with python doc http://python.org/doc/2.4.1/lib/typesfunctions.html the problem is that the page essentially says nothing. Nothing that is relevant to programing, and such nothingness occupies a significant portion of the python doc. (at least a quarter) It is like reading a

tree functions daily exercise: Range

2005-06-12 Thread Xah Lee
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); } public static List range(double n, double m) { return range(n,m,1); } public

Re: tree functions daily exercise: Table

2005-06-12 Thread Xah Lee
Here's the next tree functions exercise in Python, Perl, Java. Other language solutions welcome. http://xahlee.org/tree/tree.html - Table('exprString', [iMax]) generates a list of iMax copies of value of eval('exprString'), and returns the refence to the list. i.e.

count string replace occurances

2005-06-12 Thread Xah Lee
if i have mytext.replace(a,b) how to find out many many occurances has been replaced? Xah [EMAIL PROTECTED] http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: What are OOP's Jargons and Complexities?

2005-06-07 Thread Xah Lee
things. http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html (local copy) --- to be continued... This is part of an installment of the article What are OOP's Jargons and Complexities by Xah Lee, 20050128. The full text is at http://xahlee.org/Periodic_dosage_dir/t2/oop.html Copyright 2005

Re: What are OOP's Jargons and Complexities?

2005-06-03 Thread Xah Lee
Lee, 20050128. The full text is at http://xahlee.org/Periodic_dosage_dir/t2/oop.html Copyright 2005 by Xah Lee. Verbatim duplication of the complete article for non-profit purposes is granted. The article is published in the following newsgroups: comp.lang.c,comp.lang.c++,comp.lang.lisp

Re: What are OOP's Jargons and Complexities?

2005-05-31 Thread Xah Lee
and Complexities by Xah Lee, 20050128. The full text is at http://xahlee.org/Periodic_dosage_dir/t2/oop.html Copyright 2005 by Xah Lee. Verbatim duplication of the complete article for non-profit purposes is granted. The article is published in the following newsgroups: comp.lang.c,comp.lang.c

Re: What are OOP's Jargons and Complexities?

2005-05-28 Thread Xah Lee
as a special method at the language level, its concept and linguistic issues is a OOP machinery complexity, while the Accessor concept is a OOP engineering complexity. - to be continued tomorrow. This is part of an installment of the article What are OOP's Jargons and Complexities by Xah Lee

Re: What are OOP's Jargons and Complexities?

2005-05-26 Thread Xah Lee
Joe: lang x is strongly typed Dave: you mean statically typed? John: no no, that's weakly typed. Mike: actually, it is dynamically typed! rely on the morons of the IT industry, every mother fucking one of them, to sing and propagate jargons. See also:

Re: What are OOP's Jargons and Complexities?

2005-05-25 Thread Xah Lee
of the article What are OOP's Jargons and Complexities by Xah Lee, 20050128. The full text is at http://xahlee.org/Periodic_dosage_dir/t2/oop.html Copyright 2005 by Xah Lee. Verbatim duplication of the complete article for non-profit purposes is granted. The article is published in the following newsgroups

What are OOP's Jargons and Complexities?

2005-05-23 Thread Xah Lee
What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } In advanced languages such as LISP family, it is not uncommon

What are OOP's Jargons and Complexities?

2005-05-23 Thread Xah Lee
What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } In advanced languages such as LISP family, it is not uncommon

Re: Range function

2005-05-15 Thread Xah Lee
Here's the Perl code. -- #! perl # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 #_ Range _ _ _ _ =pod BRange Range($iMax) generates the list [1, 2, ... , $iMax]. Range($iMin, $iMax) generates the list [$iMin, ... , $iMax]. Range($iMin, $iMax, $iStep

Re: Range function

2005-05-15 Thread Xah Lee
Here's the Python solution. -- # -*- coding: utf-8 -*- # Python # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 # implementation note: When iStep is a decimal, rounding error # accumulates. For example, the last item returned from # Range(0,18,0.3) is 17.7 not 18. A remedy

Re: Range function

2005-05-15 Thread Xah Lee
are not expected to be exemplary. These are exercises for all, also as a intro to functional programing to industry programers. Also, later on there will be non-trivial problems. # -*- coding: utf-8 -*- # Python # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 import math; def Range(iMin, iMax=None

Re: function with variable arguments

2005-05-14 Thread Xah Lee
Thanks to all for the reply. (i should've known better) on a related topic, I think it would be a improvement for the built-in range() so that step needs not be an integer. Further, it'd be better to support decreasing range. e.g. Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8]

Re: New Python regex Doc

2005-05-13 Thread Xah Lee
| Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse Xah Lee wrote: Let me expose one another fu Hello Xah, I think you will continue to have difficulty getting respect on this matter as long as you show disrespect to those who have come before you. When

function with variable arguments

2005-05-13 Thread Xah Lee
i wanted to define a function where the number of argument matters. Example: def Range(n): return range(n+1) def Range(n,m): return range(n,m+1) def Range(n,m,step): return range(n,m+1,step) this obvious doesn't work. The default argument like Range(n=1,m,step=1) obviously isn't a

[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl Python Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah [EMAIL PROTECTED] http://xahlee.org/ --

[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl Python Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah [EMAIL PROTECTED] http://xahlee.org/ --

Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-07 Thread Xah Lee
Let me expose one another fucking incompetent part of Python doc, in illustration of the Info Tech industry's masturbation and ignorant nature. The official Python doc on regex syntax ( http://python.org/doc/2.4/lib/re-syntax.html ) says: --begin quote-- | A|B, where A and B can be arbitrary

Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-06 Thread Xah Lee
HTML Problems in Python Doc I don't know what kind of system is used to generate the Python docs, but it is quite unpleasant to work with manually, as there are egregious errors and inconsistencies. For example, on the Module Contents page ( http://python.org/doc/2.4.1/lib/node111.html ), the

Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-06 Thread Xah Lee
erratum: the correct URL is: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Xah [EMAIL PROTECTED] http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: New Python regex Doc (was: Python documentation moronicities)

2005-05-05 Thread Xah Lee
I have now also started to rewrite the re-syntax page. At first i thought that page needs not to be rewritten, since its about regex and not really involved with Python. But after another look, that page is as incompetent as every other page of Python documentation. The rewritten page is here:

Re: Python documentation moronicities (continued)

2005-04-25 Thread Xah Lee
I have produced my doc. ( http://xahlee.org/perl-python/python_re-write/lib/module-re.html ) isn't there a hundred dollars due to me? Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Steve Holden wrote: Xah Lee wrote: [mountains of irrelevant drivel which normal people would

Re: Python documentation moronicities (continued)

2005-04-25 Thread Xah Lee
Dear Steve Holden, the rewrite of the regex doc is instigated by your offer. it is published and announced here on April 18th. If you deem it proper, paypal me. It will be to your credit and easier to incorporate into the main doc. Xah [EMAIL PROTECTED] http://xahlee.org/ --

Re: New Python regex Doc (was: Python documentation moronicities)

2005-04-19 Thread Xah Lee
://xahlee.org/ Xah Lee wrote: i have rewrote the Python's re module documentation. See it here for table of content page: http://xahlee.org/perl-python/python_re-write/lib/module-re.html The doc is broken into 4 sections: * regex functions (node111.html) * regex OOP (re-objects.html) * matched objects

New Python regex Doc (was: Python documentation moronicities)

2005-04-18 Thread Xah Lee
i have rewrote the Python's re module documentation. See it here for table of content page: http://xahlee.org/perl-python/python_re-write/lib/module-re.html The doc is broken into 4 sections: * regex functions (node111.html) * regex OOP (re-objects.html) * matched objects (match-objects.html) *

Re: unicode em space in regex

2005-04-17 Thread Xah Lee
Thanks. Is it true that any unicode chars can also be used inside regex literally? e.g. re.search(ur'+',mystring,re.U) I tested this case and apparently i can. But is it true that any unicode char can be embedded in regex literally. (does this apply to the esoteric ones such as other

re module methods: flags(), pattern()

2005-04-17 Thread Xah Lee
Python re module has methods flags and pattern. How to use these exactly? e.g. i tried print patternObj.flags() and the error is some int object is not callable. newpattern=re.compile(ur'\w+',patternObj.flags()) also bad. similar error for patternObj.pattern(). (and i suppose the same for

unicode em space in regex

2005-04-16 Thread Xah Lee
how to represent the unicode em space in regex? e.g. i want do something like this: fracture=re.split(r'\342371*\|\342371*',myline,re.U) Xah [EMAIL PROTECTED] http://xahlee.org/ -- http://mail.python.org/mailman/listinfo/python-list

[perl-python] Python documentation moronicities (continued)

2005-04-12 Thread Xah Lee
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html - QUOTE The module defines several functions, constants, and an exception. Some of the functions are simplified versions of the full featured methods for compiled regular expressions. Most

Re: EOL created by .write or .encode

2005-04-10 Thread Xah Lee
can any GNU person or emacs coder answer this? specifically: why does what-cursor-position give incorrect answer. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Xah Lee wrote: I found the problem now. (after some one hour debug time) Python didn't have problem. Emacs does

Re: EOL created by .write or .encode

2005-04-09 Thread Xah Lee
position and the char's ascii code, says the EOL is ascii 10 when it is in fact ascii 13. Fuck the irresponsible fuckhead who is responsible for this. http://xahlee.org/UnixResource_dir/writ/responsible_license.html Xah [EMAIL PROTECTED] http://xahlee.org/ Xah Lee wrote: Why is that some of my

EOL created by .write or .encode

2005-04-05 Thread Xah Lee
Why is that some of my files written out by outF.write(outtext.encode('utf-8')) has ascii 10 as EOL, while others has ascii 13 as EOL? both of these files's EOL are originally all ascii 10. If i remove the EOL after the tt below in the place string, then this doesn't happen. findreplace = [

Re: Python docs [was: function with a state]

2005-03-28 Thread Xah Lee
Python doc 3.6.4 Mutable Sequence Types at http://python.org/doc/2.4/lib/typesseq-mutable.html in which contains the documentation of the sort method of a list. Quote: -- .sort([cmp[, key[, reverse]]]) sort the items of s in place (7), (8), (9), (10) ... (8) The sort() method

Re: sorting matrixes

2005-03-27 Thread Xah Lee
Here's the solution to previous post. --- perl code: sub sort_matrix($$) { my $ref_matrix = $_[0]; my @indexMatrix = @{$_[1]}; my @indexes = map {$_-[0]} @indexMatrix; my @operators = map {$_-[1] ? ' cmp ' : ' = '} @indexMatrix; my @directions =

[perl-python] limericks

2005-03-25 Thread Xah Lee
Better: there is a Python, pithy mighty, lissome, and tabby algorithms it puffs conundrums it snuffs and cherished by those savvy there is a camel, kooky ugly, petty, ungainly hacking it supports TIMTOWTDI it sports and transports DWIM-wit's fancy Xah [EMAIL PROTECTED]

Re: Python docs [was: function with a state]

2005-03-24 Thread Xah Lee
The Python doc is relatively lousy, from content organization to the tech writing quality. I think i'll just post snippets of my comments as i find them. (and feel like exposing) Python doc: http://python.org/doc/2.4/lib/comparisons.html Quote: Comparison operations are supported by all

Re: Python docs [was: function with a state]

2005-03-24 Thread Xah Lee
there is a Python, pithy mighty, lissome, and tabby algorithms it puffs tim-toady it engulfs and sways universality there is a camel, lanky ugly, petty, ungainly foolhardy comports hacking it supports and toadies eunuch's fancy Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html

Re: Python docs [was: function with a state]

2005-03-24 Thread Xah Lee
umm... looks like it should've been: Comparison can be chained, and is equivalent to a sequence of comparisons with and in between. For example, xy=z is effectively (xy) and (y=z) Xah [EMAIL PROTECTED] http://xahlee.org/ Terry Reedy wrote: Comparisons can be chained, and is evaluated from

[perl-python] sorting matrixes

2005-03-22 Thread Xah Lee
Today we'll write a program that can sort a matrix in all possible ways. Here's the Perl documentation. I'll post a Perl and Python version in 2 days. --- sort_matrix( $matrix, [[$n1, $stringQ, $directionQ], [$n2, $stringQ, $directionQ], ...]) sorts a matrix by $n1 th column then $n2

Re: unicode study with unicodedata module

2005-03-16 Thread Xah Lee
anyone wants to supply a Perl version? Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Brian McCauley wrote: Xah Lee wrote: i don't know what's the state of Perl's unicode. perldoc perlunicode -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] unicode study with unicodedata module

2005-03-16 Thread Xah Lee
Fuck google incorporated for editing my subject name without permission. and fuck google incorporated for editing my message content without permission. http://xahlee.org/UnixResource_dir/writ/responsible_license.html Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html --

python version anachronism

2005-03-15 Thread Xah Lee
this url: http://www.python.org/doc/2.4/ sayz: Python 2.4 Documentation (released November 30, 2004) but this url: http://www.python.org/doc/2.3.5/ sayz: Python 2.3.5 Documentation (released February 8th, 2005) so, python 2.3.5 is released about 2 months later than 2.4?? also, does the

[perl-python] unicode study with unicodedata module

2005-03-15 Thread Xah Lee
python has this nice unicodedata module that deals with unicode nicely. #-*- coding: utf-8 -*- # python from unicodedata import * # each unicode char has a unique name. # one can use the lookup func to find it mychar=lookup('greek cApital letter sIgma') # note letter case doesn't matter print

Re: unicode study with unicodedata module

2005-03-15 Thread Xah Lee
how do i get a unicode's number? e.g. 03ba for greek lowercase kappa? (or in decimal form) Xah Xah Lee wrote: python has this nice unicodedata module that deals with unicode nicely. #-*- coding: utf-8 -*- # python from unicodedata import * # each unicode char has a unique name. # one

Re: function with a state

2005-03-09 Thread Xah Lee
Nevermind. I was thinking too much. :) Thanks. Xah Peter Hansen wrote: Xah Lee wrote: def myFun(var): return var+1 globe = 0 globe = myFun(globe) this is intriguing. How does it work? not a rhetorical question, but where in the python doc can i read about it? The tutorial

[perl-python] a program to delete duplicate files

2005-03-09 Thread Xah Lee
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are identical with which. Write a program that prints out which file are redundant copies. Here's the spec.

Re: function with a state

2005-03-08 Thread Xah Lee
def myFun(var): return var+1 globe = 0 globe = myFun(globe) this is intriguing. How does it work? not a rhetorical question, but where in the python doc can i read about it? thanks. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html --

Re: convert gb18030 to utf16

2005-03-07 Thread Xah Lee
Truely superb! Thanks! Xah [EMAIL PROTECTED] http://xahlee.org/ [EMAIL PROTECTED] wrote: Xah Lee [EMAIL PROTECTED] wrotE: i have a bunch of files encoded in GB18030. Is there a way to convert them to utf16 with python? You will need CJKCodecs (http://cjkpython.i18n.org/), or Python

convert gb18030 to utf16

2005-03-06 Thread Xah Lee
i have a bunch of files encoded in GB18030. Is there a way to convert them to utf16 with python? Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

function with a state

2005-03-06 Thread Xah Lee
is it possible in Python to create a function that maintains a variable value? something like this: globe=0; def myFun(): globe=globe+1 return globe apparently it can't be done like that. I thought it can probably be done by prefixing the variable with some package context... the Python

Re: function expression with 2 arguments

2005-03-03 Thread Xah Lee
Roel Schroeven wrote: (lambda x, y: x+y)(a, b) Thanks. That's what i was looking for. where in Pytho doc can one find this? or the lambda with multiple params? Most often the lambda is not used directly, but passed to a function. That is because the IT morons has been throughly brainwashed

Re: function expression with 2 arguments

2005-03-03 Thread Xah Lee
PS sorry for the rude remarks out of nowhere. Xah -- http://mail.python.org/mailman/listinfo/python-list

Re: function expression with 2 arguments

2005-03-02 Thread Xah Lee
once i have a expresson of a function, how to apply it to arguments? e.g. if i have lambda x,y:x+y i have to applied it to a,b in my code. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] generate all possible pairings

2005-03-01 Thread Xah Lee
Answer to the previous exercise. http://xahlee.org/perl-python/generate_pairings.html # perl sub genpair ($) { my $partiSet = $_[0]; my @result; for (my $head =0; $head = ((scalar @$partiSet)-2); $head++ ) { for (my $tail = $head+1; $tail = ((scalar @$partiSet)-1); $tail++ ) { foreach

Re: generic equivalence partition

2005-02-26 Thread Xah Lee
# the following solution is submitted by # Sean Gugler and David Eppstein independently # 20050224. @def parti(aList, equalFunc): @result = [] @for i in range(len(aList)): @for s in result: @if equalFunc( aList[i], aList[s[0]] ): @s.append(i) @

function expression with 2 arguments

2005-02-26 Thread Xah Lee
is there a way to write a expression of a function with more than 1 argument? e.g., i want a expression that's equivalent to def f(x,y) return x+y Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

Re: function expression with 2 arguments

2005-02-26 Thread Xah Lee
lambda x, y: x + y that's what i was looking for. ... once i have a lambda expr, how to apply it to arguments? e.g. in Mathematica Function[#1+#2][a,b] Python doc is quite confounded in it's way of organization centered around implementation tied to hardware (as most imperative languages are

Re: generic equivalence partition

2005-02-26 Thread Xah Lee
folks: when using google to post a reply, it sometimes truncates the subject line. i.e. [perl-python] is lost. This software error is obvious, they could not have not noticed it. another thing more egregious is that google _intentionally_ edit with people's posts. (e.g. they change email address

Re: generic equivalence partition

2005-02-26 Thread Xah Lee
/responsible_license.html Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Xah Lee wrote: folks: when using google to post a reply, it sometimes truncates the subject line. i.e. [perl-python] is lost. This software error is obvious, they could not have not noticed it. another

[perl-python] generic equivalence partition

2005-02-24 Thread Xah Lee
another functional exercise with lists. Here's the perl documentation. I'll post a perl and the translated python version in 48 hours. =pod parti(aList, equalFunc) given a list aList of n elements, we want to return a list that is a range of numbers from 1 to n, partition by the predicate

Re: exercise: partition a list by equivalence

2005-02-23 Thread Xah Lee
I started to collect i believe the 4 or so solutions by different people... but seems it's gonna take some an hour or more... So far the only other one i've run and find alright is Reinhold Birkenfeld's original. Others worth noting i'm aware of is David Epsteinn, improved versions from Reinhold

[perl-python] exercise: partition a list by equivalence

2005-02-19 Thread Xah Lee
here's the answer to the partition by equivalence exercise. --- # Perl code sub merge($) { my @pairings = @{$_[0]}; my @interm; # array of hashs # chop the first value of @pairings into @interm $interm[0]={$pairings[0][0]='x'};

[perl-python] exercise: partition a list by equivalence

2005-02-17 Thread Xah Lee
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of pairs, each pair indicates the sameness of the two indexes. Returns a partitioned list of same indexes. For

Re: problem: reducing comparison

2005-02-16 Thread Xah Lee
efficient? It works entirely differently. I'll have to think about it... besides algorithmic... onto the minute academic diddling, i wonder if it is faster to delete entries in dict or add entries... Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Xah Lee wrote: here are the answers

Re: [perl-python] problem: reducing comparison (correction)

2005-02-16 Thread Xah Lee
Xah Lee wrote: In imperative languages such as Perl and Python and Java, in general it is not safe to delete elements when looping thru a list-like entity. (it screws up the iteration) One must make a copy first, and work with the copy. Correction: When looping thru a list-like entity

Re: [perl-python] problem: reducing comparison (erratum)

2005-02-16 Thread Xah Lee
Xah Lee wrote: In imperative languages such as Perl and Python and Java, in general it is not safe to delete elements when looping thru a list-like entity. (it screws up the iteration) One must make a copy first, and work with the copy. Correction: When looping thru a list-like entity

Re: [perl-python] problem: reducing comparison (erratum)

2005-02-16 Thread Xah Lee
Xah Lee wrote: In imperative languages such as Perl and Python and Java, in general it is not safe to delete elements when looping thru a list-like entity. (it screws up the iteration) One must make a copy first, and work with the copy. Correction: When looping thru a list-like entity

Re: [perl-python] problem: reducing comparison

2005-02-15 Thread Xah Lee
here are the answers: Perl code: sub reduce ($$) { my %hh= %{$_[0]}; # e.g. {'1,2'=[1,2],'5,6'=[5,6],...} my ($j1,$j2)=($_[1]-[0],$_[1]-[1]); # e.g. [3,4] delete $hh{$j1,$j2}; foreach my $k (keys %hh) { $k=~m/^(\d+),(\d+)$/; my ($k1,$k2)=($1,$2); if ($k1==$j1) {

Re: problem: reducing comparison

2005-02-15 Thread Xah Lee
my Python coding is not experienced. In this case, is ps.pop(%d,%d%(j[1],k[1]),0) out of ordinary? if i have long paragraphs of documentation for a function, do i still just attach it below the fun def? Xah Xah Lee wrote: here are the answers: ©Python code. © ©def reduce(pairings, pair

[perl-python] problem: reducing comparison

2005-02-14 Thread Xah Lee
here's a interesting real-world algoritm to have fun with. attached below is the Perl documentation that i wrote for a function called reduce, which is really the heart of a larger software. The implementation is really simple, but the key is to understand what the function should be. I'll post

[perl-python] 20050211 generating expression by nested loops

2005-02-12 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return dict([('%d,%d'%(i+1,j+1),(i+1,j+1)) for j in range(n) for i in range(j)]) print combo2(5) # this

Re: [perl-python] combinatorics fun

2005-02-10 Thread Xah Lee
David Eppstein's code is very nice. Here's the python version of the perl code: ©# -*- coding: utf-8 -*- ©# Python © ©def combo (n): ©'''returns all possible (unordered) pairs out of n numbers 1 to n. © ©Returns a dictionary. The keys are of the form n,m, ©and their values are

Re: python code with indention

2005-02-09 Thread Xah Lee
i thought it is trivial for the Python parser to spit out a version with matching brackets. Similarly, perhaps some opensourcing student has modified a parser to read in a matching brackets delimited version of Python. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html --

[perl-python] text pattern matching, and expressiveness

2005-02-07 Thread Xah Lee
20050207 text pattern matching # -*- coding: utf-8 -*- # Python # suppose you want to replace all strings of the form # img src=some.gif width=30 height=20 # to # img src=some.png width=30 height=20 # in your html files. # you can use the re module. import re text = r'''html blab blab P look

python code with indention

2005-02-07 Thread Xah Lee
is it possible to write python code without any indentation? Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

[perl-python] get web page programatically

2005-02-04 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # suppose you want to fetch a webpage. from urllib import urlopen print urlopen('http://xahlee.org/Periodic_dosage_dir/_p2/russell-lecture.html').read() # note the line # from library_name import function_name1,function_name2... # it reads the library and import

Re: how to write a tutorial

2005-02-02 Thread Xah Lee
in the doc for re module http://python.org/doc/lib/module-re.html 4.2.2 on Matching vs Searching http://python.org/doc/lib/matching-searching.html Its mentioning of Perl is irrelevant, since the majority reading that page will not have expertise with Perl regex. The whole section should be

Re: how to write a tutorial

2005-02-02 Thread Xah Lee
i've noticed that in Python official doc http://python.org/doc/lib/module-re.html and also How-To doc http://www.amk.ca/python/howto/regex/ both mentions the book Mastering Regular Expressions by Jeffrey Friedl. I suggest it be dropped in both places. The mentioning of this book in the

[perl-python] string pattern matching

2005-02-01 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images files from gif # format to png format. Now you need to change the # html code to use the .png files. So,

Q: quoting string without escapes

2005-01-31 Thread Xah Lee
in Python, is there a way to quote a string as to avoid escaping ' or inside the string? i.e. like Perl's q or qq. thanks. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

[perl-python] find replace strings for all files in a dir

2005-01-31 Thread Xah Lee
suppose you want to do find replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web' © ©findStr='!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 3.2 FINAL//EN' ©repStr='!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01

[perl-python] sending email

2005-01-29 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # Suppose you want to spam your friend, and you have lots of # friends. The solution is to write a program to do it. After a gander # at python docs, one easily found the module for the job. # see http://python.org/doc/2.3.4/lib/SMTP-example.html # the code is a

[perl-python] daily tip website

2005-01-28 Thread Xah Lee
for those interested, i've created a webpage for these perl-python daily tips. The url is: http://xahlee.org/perl-python/python.html Thanks to those who have made useful comments. They will be assimilated. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html Hey all, I have seen no

what's OOP's jargons and complexities?

2005-01-28 Thread Xah Lee
in computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } in advanced languages such as LISP family, it is not uncommon to define functions inside a function. For example: subroutine f (x1, x2, ...) { variables... subroutine

[perl-python] 20050127 traverse a dir

2005-01-27 Thread Xah Lee
# -*- coding: utf-8 -*- # Python suppose you want to walk into a directory, say, to apply a string replacement to all html files. The os.path.walk() rises for the occasion. © import os © mydir= '/Users/t/Documents/unix_cilre/python' © def myfun(s1, s2, s3): © print s2 # current dir ©

[perl-python] 20050126 find replace strings in file

2005-01-26 Thread Xah Lee
© # -*- coding: utf-8 -*- © # Python © © import sys © © nn = len(sys.argv) © © if not nn==5: © print error: %s search_text replace_text in_file out_file % sys.argv[0] © else: © stext = sys.argv[1] © rtext = sys.argv[2] © input = open(sys.argv[3]) © output =

how to comment out a block of code

2005-01-26 Thread Xah Lee
is there a syntax to comment out a block of code? i.e. like html's !-- comment -- or perhaps put a marker so that all lines from there on are ignored? thanks. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

[perl-python] 20050125 standard modules

2005-01-25 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # some venture into standard modules import os # print all names exported by the module print dir(os) # print the module's online manual print help(os) # the above is also available in # interactive mode in Python terminal # example of using a function print

Re: how to write a tutorial

2005-01-25 Thread Xah Lee
in my previous two messages, i've criticized the inanity of vast majority of language documentations and tutorials in the industry. I've used the Python tutorial's chapter on class as an example. I've indicated that proper tutorial should be simple, covering just common cases, be self-contained,

[perl-python] 20050124 classes objects

2005-01-24 Thread Xah Lee
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as class. © © # in the following, we define a set of data © # and functions as a class, and name it xxx © class xxx: © a class extempore! (^_^) ©

Re: how to write a tutorial

2005-01-23 Thread Xah Lee
adding to my previosu comment... In the Python tutorial: http://python.org/doc/2.3.4/tut/node11.html the beginning two paragraphs should be deleted. Nobody gives a shit except a few smug academicians where the author wrote it for pleasing himself. For 99% of readers, it is incomprehensible and

[perl-python] 20050121 file reading writing

2005-01-22 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file object and name it f. # the second argument of open can be # 'w' for write (overwrite exsiting file) # 'a' for append (ditto) # 'r' or read only # to actually print to file

how to write a tutorial

2005-01-21 Thread Xah Lee
i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: quick example: If the input string is too long, they don't truncate it, but return it unchanged; this will mess up your column lay-out but that's usually better than the

iteritems() and enumerate()

2005-01-19 Thread Xah Lee
Python has iteritems() and enumerate() to be used in for loops. can anyone tell me what these are by themselves, if anything? are they just for idiom? thanks. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list

[perl-python] 20050120 find functions in modules

2005-01-19 Thread Xah Lee
© # -*- coding: utf-8 -*- © # Python © © # once a module is loaded © # import mymodule © # one can find all the names it © # export with dir() © © import sys © print dir(sys) © © # without argument it gives the names © # you've defined © print dir() © © # to find a list of built-in names © #

[perl-python] 20050119 writing modules

2005-01-18 Thread Xah Lee
© # -*- coding: utf-8 -*- © # Python © © # one can write functions, © # save it in a file © # and later on load the file © # and use these functions. © © # For example, save the following line in © # a file and name it module1.py © # def f1(n): returns range(n) © © # to load the file, use import ©

<    1   2   3   4   5   6   >