Blind programmers can use braille displays, which let them perceive
indentation as easily as sighted programmers can. http://xrl.us/tydj
As for people with physical disabilities that have trouble typing, a
Python-aware editor does the identation for you, so all you have to do
is type a colon and
Just a guess, but I think you need to be using at least Python 2.4 if
you are going to use IDLE version 2.4.4-2.
On Dec 20, 1:16 pm, altern [EMAIL PROTECTED] wrote:
Hi
when i try to run IDLE on my debian laptop I get this error.
$ idle
Traceback (most recent call last):
File
Type sudo easy_install myeggfile.egg.
If that gives you an error, then you don't have easy_install installed.
Install it this way:
sudo apt-get install python-setuptools
On Dec 19, 3:44 pm, Morpheus [EMAIL PROTECTED] wrote:
On Windows I'm used to install packages by setup.py install. So did I
You want re.sub((?s)!--.*?--, , htmldata)
Explanation: To make the dot match all characters, including newlines,
you need to set the DOTALL flag. You can set the flag using the (?_)
syntax, which is explained in section 4.2.1 of the Python Library
Reference.
A more readable way to do this is:
Oops, I mean obj.sub(, htmldata)
On Dec 19, 4:15 pm, [EMAIL PROTECTED] wrote:
You want re.sub((?s)!--.*?--, , htmldata)
Explanation: To make the dot match all characters, including newlines,
you need to set the DOTALL flag. You can set the flag using the (?_)
syntax, which is explained in
Not just Python, but every Regex engine works this way. You want a ?
after your *, as in --(.*?)-- if you want it to catch the first
available --.
At this point in your adventure, you might be wondering whether regular
expressions are more trouble than they are worth. They are. There are
two
(x for x in xrange(N+1) if x != m)
rjtucke wrote:
I want an iterable from 0 to N except for element m (=M).
I could write
x = range(N)
x.remove(m)
but I want it in one expression.
Thanks,
Ross
--
http://mail.python.org/mailman/listinfo/python-list
Have you considered JavaScript Spidermonkey or JavaScript Rhino?
Sandboxing is automatic, and lots of people know the language already
(although fewer people are familiar with its dynamic object-oriented
capabilities).
Tony Belding wrote:
I'm interested in using an off-the-shelf interpreted
For a free out of the box solution, look at MoinMoin. It is wiki
software, but nothing stops you from turning off user signups, locking
down the whole site, and just using it as a CMS. It's very easy to set
up, can run as a CGI, and requires no database backend.
Echo wrote:
I am going to start
It's just sequence unpacking. Did you know that this works?:
pair = (California,San Francisco)
state, city = pair
print city
# 'San Francisco'
print state
# 'California'
John Salerno wrote:
I'm a little confused, but I'm sure this is something trivial. I'm
confused about why this works:
t
When you want to repeatedly apply a certain ALGORITHM to arbitrary sets
of DATA, you write a FUNCTION.
When you want to add a certain BEHAVIOR to arbitrary sets of FUNCTIONS,
you write a DECORATOR.
An excellent use of decorators is in Django, the web programming
framework. Django keeps track of
You are opening the same file twice, reading its contents line-by-line
into memory, replacing Document with Doc *in memory*, never writing
that to disk, and then discarding the line you just read into memory.
If your file is short, you could read the entire thing into memory as
one string using
Can you safely assume that the lines you want to extract all contain
numbers, and that the lines you do not wish to extract do not contain
numbers?
If so, you could just use the Linux grep utility: grep '[0123456789]'
filename
Or, in Python:
import re
inf = file(your-filename-here.txt)
outf =
I was scanning the 9/13/2006 issue of the Electronic Commerce Law
Report, which is a newsletter for lawyers published by BNA. They have
an article headlined Game Developers Making Tomorrow's Hits Face Host
of Copyright Issues Along the Way, and the article is mostly a writeup
of a speech given
def transform(seq, size):
i = 0
while i len(seq):
yield tuple(seq[i:i+size])
i += size
Neal Becker wrote:
Any suggestions for transforming the sequence:
[1, 2, 3, 4...]
Where 1,2,3.. are it the ith item in an arbitrary sequence
into a succession of tuples:
[(1,
This may be a rare case where regular expressions are not a horrible,
self-defeating idea. Something like:
delimiter = re.compile([:\.])
delimiter.split(PCI:2:3.0)
...and then ignore the first entry, and map int the rest.
Alternatively, if the delimiters can really be anything, and if there
are
You could also use itertools:
import itertools
import re
find = re.compile(pattern)
for line in itertools.ifilter(lambda x: find.search(x),
file(filepath)):
print line
Fredrik Lundh wrote:
bhavya sg wrote:
I saw in PEP4 of python 2.5 that grep module has gone
obsolete in perl 2.5.
You should use os.path.exists to test if a file exists. Your
exception-catching structure is not necessary.
Also, if the file you are reading from contains proper Windows
filenames, it is not necessary to replace \ with \\ and so forth. The
\ acts as an escape character only when it is in
Also, it may be easier to use string interpolation, as in:
return INSERT INTO statecode (state, name) VALUES ('%(state)s',
'%(name)s') % insert_dict
...after all necessary escaping, of course.
John Machin wrote:
len wrote:
Hi all
I am writing a python program that inserts records into a
mp wrote:
Hello, I have a couple general questions.
First, how do most web frameworks serve html? I'm coding in python and
I want to keep all my html seperate from my python stuff. I can serve
these html files from a mysql database or just from the file system, do
people use both these
Check out the .translate method and the string.maketrans documentation.
You can use it to delete a list of characters all in one line:
s = I am the walrus
import string
s.translate(string.maketrans(,),aeiou)
'I m th wlrs'
Michele Petrazzo wrote:
Hi,
a lot of times I need to replace more
How about an effort to compile Python into JavaScript? Such an
effort is underway for Scheme.
http://www-sop.inria.fr/mimosa/personnel/Florian.Loitsch/scheme2js/
Tim Chase wrote:
As explained in this thread
http://mail.python.org/pipermail/python-list/2006-June/348241.html
what you try to
Is there a module (or, better yet, sample code) that scrubs
user-entered text to remove cross-site scripting attacks, while also
allowing a small subset of HTML through?
Contemplated application: a message board that allows people to use
b, a href=, i and so on, but does not allow any javascript,
manstey wrote:
Hi,
Is there a clever way to see if two strings of the same length vary by
only one character, and what the character is in both strings.
You want zip.
def diffbyonlyone(string1, string2):
diffcount = 0
for c1, c2 in zip(string1, string2):
if c1 != c2:
How about a dictionary, keyed on tuples of (height, weight)?
[EMAIL PROTECTED] wrote:
I'm new to Python and want to contruct a lookup table which would be
similar to a spreadsheet in that a value is read along the first
column, then along the top row, and the intersection of the two gives a
Why not use split instead of regular expressions?
ln = 3232 23 9 9 - 9 9 - 911
110
ln.split()
['32', '32', '23', '9', '9', '-', '9', '9', '-', '9', '11', '1', '10']
Much simpler, yes? Just find the line that comes after a line that
begins
[EMAIL PROTECTED] wrote:
On a related note, is there a way to fire up Adobe's Acorbat Reader or
and Web Browser from Python and have the external application open a
specified PDF or HTML file? (For example, I want to open the file
myhelp.pdf in reader from Python code.)
The webbrowser module
It's a bit overkill, but consider using os.walk.
root, dirnames, filenames = os.walk(rC:\).next() # (in real code,
you'd want to catch exceptions here)
print dirnames
Florian Lindner wrote:
Hello,
how can I get all subdirectories of a given directories? os.listdir() gives
me all entries and
Use __repr__. Behold:
class NamedThing(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
a = NamedThing(Delaware)
b = NamedThing(Hawaii)
d = {}
d[a] = 1
d[b] = 50
print d
{Delaware: 1, Hawaii: 50}
d[a]
1
d[b]
50
Actually, come to think of it, __str__ works just as well.
class NamedThing(object):
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
d = {}
d[a] = 1
d[b] = 50
d
{__main__.NamedThing object at 0x00C528D0: 1, __main__.NamedThing
object
If you are parsing HTML, it may make more sense to use a package
designed especially for that purpose, like Beautiful Soup.
--
http://mail.python.org/mailman/listinfo/python-list
If what you need is simple, regular expressions are almost never the
answer. And how simple can it be if you are posting here? :)
BeautifulSoup isn't all that hard. Observe:
from BeautifulSoup import BeautifulSoup
html = '10:00am - 11:00am:/b a
href=/tvpdb?d=tvpid=167540528[snip]The Price
First, note that form[date] is all you need. form[date].value is
redundant.
I would do this with sets:
import string
if set(form[date]) set(string.ascii_letters) != set([]): print You
have to enter a date with numbers
if set(form[purchases]) set(string.digits) != set([]): print
Please do not
How about using the numbers as delimiters:
pat = re.compile(r[\d\.\-]+)
pat.split([(some text)2.3(more text)4.5(more text here)])
['[(some text)', '(more text)', '(more text here)]']
pat.findall([(some text)2.3(more text)4.5(more text here)])
['2.3', '4.5']
pat.split([(xxx)11.0(bbb\))8.9(end
Johhny wrote:
Hello,
I have recently written a small function that will verify that an IP
address is valid.
==SNIP==
import re
ipAddress = raw_input('IP Address : ')
def validateIP(ipAddress):
ipRegex =
Uglier than yours, but down to two lines:
def recur_map(f, data):
return [ not hasattr(x, __iter__) and f(x) or recur_map(f, x) for x
in data ]
--
http://mail.python.org/mailman/listinfo/python-list
Robert Dodier wrote:
I've decided it's easier for me just to search for FOO, and then
break up the string based on the locations of FOO.
But I'd like to better understand regular expressions.
Those who cannot learn regular expressions are doomed to repeat string
searches. Which is not such
falcon wrote:
Is there a way I can do time series calculation, such as a moving
average in list comprehension syntax? I'm new to python but it looks
like list comprehension's 'head' can only work at a value at a time. I
also tried using the reduce function and passed in my list and another
There is some fine permutation code in the cookbook. Take a look at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465 .
You can easily code something like:
# xcombinations from the cookbook
def xcombinations(items, n):
if n==0: yield []
else:
for i in
You can come quite close to what you want without splitting the string
at all. It sounds like you are asking the user to build up a string,
and you want to keep checking through your list to find any items that
begin with the string built up by the user. Try something like this:
mylist =
Python lets you iterate through a list using an integer index, too,
although if you do so we will make fun of you. You can accomplish it
with a while loop, as in:
i = 0
while i len(rows):
if rows[i] == This code looks like BASIC without the WEND, doesn't
it?:
rowgroups.append(Pretty
map takes a function and a list, applies the function to each item in
a list, and returns the result list. For example:
def f(x): return x + 4
numbers = [4, 8, 15, 16, 23, 42]
map(f, numbers)
[8, 12, 19, 20, 27, 46]
So, rather that ask if there is a different way to write f, I'd just
use f
Although I don't know if this is faster or more efficient than your
current solution, it does look cooler:
def grouprows(inrows):
rows = []
rows[:] = inrows # makes a copy because we're going to be
deleting
while len(rows) 0:
rowspan = rows[0][rowspan]
yield
You don't need to copy the list; but if you don't, your original list
will be emptied.
Len(rows) recalculates each time the while loop begins. Now that I
think of it, rows != [] is faster than len(rows) 0.
By the way, you can also do this using (gasp) a control index:
def grouprows(rows):
I like Fredrik's solution. If for some reason you are afraid of
logarithms, you could also do:
x = 4978
decades = [10 ** n for n in xrange(-1,8)]
import itertools
itertools.ifilter(lambda decade: x decade, decades).next()
1
BTW, are the python-dev guys aware that 10 ** -1 =
Your tools are:
1. map lets you apply a function to every element of a list.
Strings are lists. (List comprehensions let you do the same thing, but
map is better to use if you are turning in homework).
2. sum lets you calculate the sum of all numbers in a list.
3. val and str let you turn
There's more to re than just sub. How about:
sanesplit = re.split(r/tdtd|td|/td, text)
date = sanesplit[1]
times = times = [time for time in sanesplit if re.match(\d\d:\d\d,
time)]
... then date contains the date at the beginning of the line and
times contains all your times.
--
You can check len(sanesplit) to see how big your list is. If it is
2, then there were no td's, so move on to the next line.
It is probably possible to do the whole thing with a regular
expression. It is probably not wise to do so. Regular expressions are
difficult to read, and, as you
48 matches
Mail list logo