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/
--
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
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
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.
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
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
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
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
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
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:
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
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
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
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
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
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
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]
| 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
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
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/
--
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/
--
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
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
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
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:
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
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/
--
://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
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)
*
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
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
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
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
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
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
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 = [
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
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 =
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]
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
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
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
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
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
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
--
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
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
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
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
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.
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
--
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
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
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
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
PS sorry for the rude remarks out of nowhere.
Xah
--
http://mail.python.org/mailman/listinfo/python-list
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
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
# 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)
@
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
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
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
/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
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
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
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'};
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
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
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
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
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
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) {
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
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
# -*- 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
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
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
--
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
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
# -*- 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
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
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
# -*- 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,
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
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
# -*- 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
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
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
# -*- 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
©
© # -*- 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 =
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
# -*- 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
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,
© # -*- 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! (^_^)
©
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
# -*- 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
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
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
© # -*- 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
© #
© # -*- 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
©
401 - 500 of 510 matches
Mail list logo