iful Soup. The value in the attribute
dictionary can be a callable; try this:
def isFoodOrDrink(attr):
return attr in ['food', 'drink']
b = incident.findNextSibling('div', {'class': isFoodOrDrink})
Alternately you could omit the class spec and check for it in code.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh wrote:
> Kent Johnson wrote:
>>Is there such a list? I have contributed many doc patches and if such
>>glory is mine I would like to know it!
>
> unfortunately, your name don't seem to be mentioned in the Doc version
> history either:
>
> do you
Steve Holden wrote:
> Clearly. So get your sleeves rolled up and provide a fix. Then you too
> will get your name in the Python documentation contributors' list.
Is there such a list? I have contributed many doc patches and if such
glory is mine I would like to know it!
Ke
tr, value):
... print 'foo.__setattr__'
... object.__setattr__(self, attr, value)
...
>>> f=foo()
>>> f.x = 3
foo.__setattr__
>>> def new_setattr(attr, value):
... print 'new_setattr'
...
>>> f.__setattr__ = new_setattr
foo.__setattr__
>>> f.y=3
foo.__setattr__
still calls foo.__setattr__()
Kent
--
http://mail.python.org/mailman/listinfo/python-list
examples??
This essay gives some simple suggestions of when and why you might want
to use classes:
http://www.pycs.net/users/0000323/stories/15.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
module by that name. In this
case your module doesn't have a compile attribute. This would cause the
error you see.
Kent
>
>
> "Kent Johnson" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>livin wrote:
>>
>>>
e the
> threading module.
I have always seen mutexes used in multi-threaded programs. I'm curious,
what is the usefulness of a non-thread-safe mutex? I'm sure it must be
good for something, I just can't figure it out.
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
'compile'
That line reads
_typeprog = re.compile('^([^/:]+):')
Do you have a module named 're' that is shadowing the library module of
the same name?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Doru-Catalin Togea wrote:
> Hi!
>
> I have some experience with PLY. What other alternatives are there, and
> which is the "best" (that is most feature rich, easiest to use, ...)?
Here is a list:
http://www.nedbatchelder.com/text/python-parsers.html
pyparsing is easy to u
le for production use for
many years. The Groovy community was still working on the *language
definition* in November 2005 and has yet to deliver a stable final release.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
not needed.
If you can live with CSV output instead of XLS then see the csv module
for the processing part.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
27; or '..' then you are including them in the zip.
Try something like
fullname = os.path.join(root, f)[len(dirname):]
to get relative paths in the zip
- WinZip puts empty entries for directories in the zip. Maybe WinXP
requires these.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
t;
> any idea what i'm doing wrong here with the syntax? thanks in advance
>
ISTM that is a child of , not a sibling, and
findNextSibling is a method, not an indexable element. Try
n = incident('a', {'class': 'btn'})
link = n['href'] + "','"
Kent
--
http://mail.python.org/mailman/listinfo/python-list
#x27;tr'):
print row
and expand from there. At each step use print statements to make sure
you are finding the data you expect.
Kent
if i however chnage row to incident in "for incident in
> bs('tr'):" i then get mytuples printed out nicely but once again get a
>
ronment - while still being local.
Which can be as simple as typing
python -c "import CGIHTTPServer; CGIHTTPServer.test()"
from the command line in the root dir of your site (the dir that
contains the cgi-bin dir).
Kent
--
http://mail.python.org/mailman/listinfo/python-list
rectly from the
response object.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
', {'id' : 'food'}):
> food = ""
> for oText in incident.fetchText( oRE):
> food += oText.strip() + "','"
>
I would use a loop that finds the row for a single item with something like
for item in bs('tr', {'class' : 'base'}):
then inside the loop fetch the values for store, food and price for that
item and write them to your output file.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
> learn?
Tkinter is quite easy to use for simple apps. Pythoncard is a layer on
top of wxPython that makes it easier to use, you might want to look at that.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
nd user interface is also much better. Where is the
> search button, where can I find the latest additions?
If you go to the main cheeseshop page
http://cheeseshop.python.org/pypi?%3Aaction=home
there is a search link, you can view by categories, and it shows the
last 20 additions. There is also
.listdir() and compares it with the
> one before. But this isn't really working properly.
>
> Can anyone give me a hint to get this working?
We just had a thread on this topic:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/b8808c14ecd333ab/ca7110a977
e.
>
> Here we go:
>
> OPTIONS
> =
> - libxml2
> - lxml
> - Pyxml
> - 4Suite
Also ElementTree, Amara
>
> lxml
> -
> Disadvantages
> ==
- No Windows release to date :-(
Kent
--
http://mail.python.org/mailman/listinfo/python-list
I think this is one of the great strengths of Python - that those who
create the language have been able to discover very powerful, general
concepts and apply them broadly and consistently to solve a variety of
problems.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
y what
the OP is trying to avoid.
If there is some function of the arrays which sorts in the same order as
the natural comparison then that function can be used as a sort key.
sort(arrayList, key=some_proxy_function)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ent again and working towards compatibility with CPython 2.3. And of
course the
current 2.1 release is extremely stable and usable as is.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
g in its abilitity to make nice, readable renderings of
graph data.
http://dkbza.org/pydot.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
of the object file? (Without
> going to the filesystem and reading the filesize from the directory ...)
Once you have read the data you can get the size of that:
d = file.read()
print len(d)
Is that what you mean? Otherwise I don't know how you can get the size of a
file without
asking
p 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> class Foo:
... pass
...
>>> f=open('pickle.txt')
>>> lst = pickle.load(f)
>>> f.close()
>>> lst
['hello world', (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), {'a': 1, 'c': 3, 'b': 2},
<__main__.Foo
instance at 0x00A51350>]
>>>
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ist.
> So how do I initialize this list such that I can access them
> as elements... like
> mylist[1] = [c,f,g]
> in random order...
If you can separate the code into a list builder and a list client, maybe the
builder can
just use append and the client can use indexing.
Kent
--
e presented as the 'default', available for editing.
For fields that long I think a GUI is more appropriate than trying to use
command-line
editing. You might take a look at easygui - it's textbox is readonly but it
looks like it
wouldn't be hard to make it editable - or
(1==0)".
No, there are not. Jython implements Python 2.1 which did not have boolean
literals. You
can just use 1 and 0.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ut Python. The hard part for me
is getting
them to believe me enough to try Python for themselves.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
http://phaseit.net/claird/comp.lang.python/python_varieties.html >.
If you are maintaining that page - JPython is now called Jython and has a web
site at
http://www.jython.org.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin wrote:
> [Kent Johnson]
> Where would you draw the line? Suppose I want to use a GPLed library
> in my Python code, does that mean I have to distribute my code under
> the GPL if I distribute them together?
>
> Yes, that's the point of using the G
tLength= lambda : self.assertEqual( len(returnedVals)
> , len(inp) )
I don't understand the above at all. What do function_call,
function_returnedVals,
returnedVals and inp refer to? What is the point of the lambdas and the
assignment to
attributes of (undefined) self?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Martin Christensen wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
>
>>>>>>"Kent" == Kent Johnson <[EMAIL PROTECTED]> writes:
>
> Kent> [Karrigell is GPL'ed] Unfortunately this makes it impossible for
> Kent> me
>
> How can this be achieved easily?
Is this homework? str.count() and string multiplication are your friends here.
See
http://docs.python.org/lib/string-methods.html
http://docs.python.org/lib/typesseq.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:
>
>>You've lost me here. The server certainly would contain Karrigell
>>code, it wouldn't function without it. I don't understand the analogy
>>to GCC, the web site is not something that
make 15 is not a digit.
Maybe so, but '15'.isdigit() == True:
isdigit(...)
S.isdigit() -> bool
Return True if all characters in S are digits
and there is at least one character in S, False otherwise.
>>> '15'.isdigit()
True
though your other points ar
se, at least. I have been avoiding GPL products at work for many
years, much
longer than Microsoft has been telling me to do so.
>
> In this case I agree there's likely to be a clear separation between
> server and content that will allow Kent to distribute an unmodified
> Karrig
Paul Rubin wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:
>>>Remember that the GPL only applies to the code of Karrigell
>>>itself, not to stuff that you write using it.
>>
>>IANAL but that is not my understanding of the GPL. GPL version 2
>>sect
Paul Rubin wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:
>
>>I chose CherryPy in part because its license allows this. I
>>would have considered Karrigell if it had a different license.
>
>
> Have you had to modify CherryPy in some substantive way that you
ause its license allows this. I would have considered Karrigell if it had a
different
license.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
under the
GPL. Most of my projects at least have the potential of being distributed to
customers and
GPL is not an option.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
useful features of prior
> languages in an unusually pleasant way?
IMO it is the latter. Most of the features of Python can be found in other
languages. Not
so many languages have them all. It is the combination of ease of use and power
that makes
Python stand out.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
sion (though
your OP
shows 2.4.2...). Try
python c:\python23\Lib\pydoc.py sys
or whatever the correct path is to python on your system.
>
> I should also be able to run 'pydoc -g' to start a webserver.
python c:\python23\Lib\pydoc.py -g
or Start / Programs / Python 2.x / Module
ook, they
> could be abandoned - hint: have a better homepage !!)
This hint needs to go to the MySQL for Python folks, it's their home page.
Kent
>
> Thanks,
> Sebastian
>
--
http://mail.python.org/mailman/listinfo/python-list
DB-API
specification.)
- read list, find the database of your choice
Kent
--
http://mail.python.org/mailman/listinfo/python-list
#x27;t do what you want
I tend to use 'condition and A or B' if I'm sure A won't be false, otherwise
just write
out the if / else.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
uot;python text adventure game" if you want to build on others'
work instead
of starting from scratch.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
examples I saw (python.org, aspn.activestate.com,
> Learning Python by Lutz, among others) use d={'x' : 'y'}.
>
The second form is only available in Python 2.3 and newer, so any example that
is older
than that will use the first form.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
).
Your usage will work for either, but your names are misnomers.
>
> filelist = listFiles(path)
> for s in filelist:
I would write
for dirpath, dirnames, filenames in filelist:
which gives names to what you call s[0] and s[2]
or just
for dirpath, dirnames, filenames in os.walk(path):
Jean-Paul Calderone wrote:
> On Sat, 10 Dec 2005 13:40:12 -0500, Kent Johnson <[EMAIL PROTECTED]>
>> Do any of these tools (PyLint, PyChecker, pyflakes) work with Jython? To
>> do so they would have to work with Python 2.1, primarily...
>
> Pyflakes will *check* Pytho
(PyLint, PyChecker, pyflakes) work with Jython? To
do so they would have to work with Python 2.1, primarily...
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
27;Peters', 'Thomas', 'Liesner']
>
> I think it is theoretically faster (and more pythonic) than using regexes.
Unfortunately it gives the wrong result.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ec per loop
You need a lot of imports before 1 usec becomes "appreciable". And your
proposal is doing the import anyway, just under the hood. How will you
avoid the same penalty?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Peter Hansen wrote:
> Kent Johnson wrote:
>
>> The simplest fix is to use raw strings for all your Windows path needs:
>> os.path.isfile(r'c:\bookmarks.html')
>> os.path.isfile(r'c:\wumpus.c')
>
>
> Simpler still is almost always t
xc()
If you want more control over the exception info - for example to put it
in a string instead of printing it - look at the other functions in the
traceback module.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
('\b')
1
>>> len('\w')
2
The simplest fix is to use raw strings for all your Windows path needs:
os.path.isfile(r'c:\bookmarks.html')
os.path.isfile(r'c:\wumpus.c')
In raw strings the only \ escapes are \' and \", everything else is left
alone.
>>> len(r'\b')
2
>>> len(r'\w')
2
Kent
--
http://mail.python.org/mailman/listinfo/python-list
>Yes. Reaching through objects to do things is usually a bad idea.
>
>
> I don't necessarily disagree, but I don't understand why you say this. Why
> it is bad?
http://en.wikipedia.org/wiki/Law_of_Demeter
Kent
--
http://mail.python.org/mailman/listinfo/python-list
A.M. Kuchling wrote:
> On Wed, 07 Dec 2005 12:10:18 -0500,
> Kent Johnson <[EMAIL PROTECTED]> wrote:
>
>>OK I'll bite. That Beginners Guide page has bugged me for a long time.
>>It's a wiki page but it is marked as immutable so I can't change
o these files, but am unable, since
> python (on Win32, at least) does not recognize this as a valid
> filename.
Just to eliminate the obvious, you are calling os.path.join() with the
parent name before calling isfile(), yes? Something like
for f in os.listdir(someDir):
fp = os.path.jo
, from the point of view of a C++ programmer, Python passes
references by value. In other words if you think of variables as
pointers (references) to values, and function call as passing the
reference by value, the behaviour of Python makes sense.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
an Gauld's tutorial is very popular on the
tutor list, so is A Byte of Python (which is not listed on the
NonProgrammers page). I would list them first. Or maybe take a vote on
the tutor list for favorite beginner's tutorial.
That should help a little, maybe we won't confuse the
Ravi Teja wrote:
> Hi Kent,
> Too complicated example :-). Jythonc works just fine to create a
> regular jar file that you can reference in your jnlp file.
If it works for you, good. I have never been able to compile a real app
with jythonc and I gave up on it long ago.
Kent
desktop and Start menu shortcuts for the app, and you
can update users automatically by deploying new jars to the web server.
It's pretty nice and largely trouble-free.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
deploy
with JWS, be happy, go home early ;)
I have some notes about it here:
http://personalpages.tds.net/~kent37/Python/JythonWebStart.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
a very good job
of guessing the encoding of text files.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
nt
binaries for this package?
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
27;]
> How do I obtain the reference to the method it is bound to.
> The same problem can be extended to attributes and classes.
Use getattr() to inspect classes and instances:
>>> class deeper:
... def deepest(self):
... print 'goodbye'
...
>>> getattr(deeper, 'deepest')
>>> d=deeper()
>>> getattr(d, 'deepest')
>
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ripts, but has no
> formal programming training.
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
Kent
--
http://mail.python.org/mailman/listinfo/python-list
:
http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters
and AFAIK it is commonly supported by browsers which IMO argues that it should
be included.
Any thoughts?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Sybren Stuvel wrote:
> Kent Johnson enlightened us with:
>
>>Is there a way to persist a class definition (not a class instance,
>>the actual class) so it can be restored later?
>
>
> From the docs:
>
> "Similarly, classes are pickled by named refere
://premierpressbooks.com/ptr_detail.cfm?group=Programming&isbn=1%2D59200%2D073%2D8
Python Programming: An Introduction to Computer Science
http://www.fbeedle.com/99-6.html
And the Introductory Books page in the wiki lists many:
http://wiki.python.org/moin/IntroductoryBooks
Kent
--
http://mail.python
= self.find_class(module, name)
File "C:\Python24\lib\pickle.py", line 1140, in find_class
klass = getattr(mod, name)
AttributeError: 'module' object has no attribute 'Foo'
The idea is to persist classes that are created and modified at runtime.
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
t hacking.
My Jython and Web Start recipe is here:
http://personalpages.tds.net/~kent37/Python/JythonWebStart.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Paul Watson wrote:
> Kent Johnson wrote:
>> Stephen Kellett wrote:
>>> ActiveState do a version of Python that can run in a script tag like
>>> JavaScript and VBScript. This requires Windows Scripting Host. They
>>> also do a similar thing for Perl, n
Nathan Pinno wrote:
> Hey all,
>
> Is there a way to create a button in either pygame or livewires, that is
> able to be clicked and when clicked sends a command to restart the program?
Maybe something here:
http://www.pygame.org/wiki/gui
Kent
--
http://mail.python.org/mailman/lis
t because everything else really isn't cross platform.
>
>
> ActiveState do a version of Python that can run in a script tag like
> JavaScript and VBScript. This requires Windows Scripting Host. They also
> do a similar thing for Perl, not sure about TCL.
See
http://gro
Peter Hansen wrote:
> Kent Johnson wrote:
>> import path
>> files = path.path(pathToSearch).walkfiles(filename)
>
> A minor enhancement (IMHO) (though I certainly agree with Kent's
> recommendation here): since there is nothing else of interest in the
> "
path.path objects in pathToSearch whose names match
filename (which is a glob so wildcards are recognized).
path.path is a subclass of str so the results can be used wherever you want the
full path.
http://www.jorendorff.com/articles/python/path/index.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
u
could have a factory like this:
import C
def makeC(x, y):
subtype = 'C_%d_%d' % (x, y)
cls = getattr(C, subtype, C.C)
return cls(x, y)
Then in module C just define the subtypes you need to specialize; all other
values of x and y will get the base class C.C.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
% ('text',)
'text to go here: text'
>>> "text to go here: %s" % ('text',)
'text to go here: text'
Kent
--
http://mail.python.org/mailman/listinfo/python-list
David Rasmussen wrote:
> What is the best book for Python newbies (seasoned programmer in other
> languages)?
I like Learning Python. Python in a Nutshell is good if you want something
brief.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
John J. Lee wrote:
> Kent Johnson <[EMAIL PROTECTED]> writes:
>
>>Leif K-Brooks wrote:
>>
>>>New-style classes look up special methods on the class, not on the instance:
>>
>>For my future reference, is this documented somewhere in the standard doc
Leif K-Brooks wrote:
> New-style classes look up special methods on the class, not on the instance:
For my future reference, is this documented somewhere in the standard docs?
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
tax is handled internally, or do all special methods
work this way, or is there something else going on?
PS Is there any place in the standard Python docs where the details of
attribute lookup are spelled out?
Thanks,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
noise1 01 noise2 00 target 01']
>>> rgx = re.compile(r"(00.*?01) target_mark")
>>> rgx.findall('00 noise1 01 noise2 00 target 01 target_mark 00 dowhat 01')
['00 noise1 01 noise2 00 target 01']
Since target_mark only occurs once in the string the greedy and non-greedy
match is the same in this case.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
e bit between the numbers then
use everything-but-that instead of . - for example if spaces can only appear as
you show them, use
"(00 [^ ]* 01) target_mark" or
"(00 \S* 01) target_mark"
Kent
--
http://mail.python.org/mailman/listinfo/python-list
oo(bar)').group(1)
'bar'
>>> fooRe.search('This is a foo bar baz blah blah (bar)').group(1)
'bar'
Kent
--
http://mail.python.org/mailman/listinfo/python-list
e drawn. I don't know if it
will work incrementally if you call show() in the loop.
Kent
>
> thank you in advance
>
> David
>
>
>
> import serial
> from pylab import *
>
> ser = ser
nstances (their methods).
Ok, I think my first reply completely missed the mark. IIUC what you want is
hard. This recipe might help:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
Kent
--
http://mail.python.org/mailman/listinfo/python-list
0b19b37ac48deaa/e599041de4b8feb0?rnum=22#e599041de4b8feb0
Kent
--
http://mail.python.org/mailman/listinfo/python-list
if text == 'enddelim':
self.delimiterSeen = False
return text
if self.delimiterSeen:
return text
return ''
delimRe = re.compile('\n|startdelim|enddelim')
newText = delimRe.sub(subber(), a)
print repr(newText)
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ames:
for method in [ 'SomeMethod', 'SomeOtherMethod' ]:
setattr(self, method, getattr(self.customwidget, method))
This gives you more control over which methods are delegated - if there are
some Custom methods that you do *not* want to expose in MainClass this might be
a better approach.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Lad wrote:
> Can you please explain in more details (1) choice?
If you are using CGI you might be interested in the VoidSpace logintools which
seems to handle much of this process. See
http://www.voidspace.org.uk/python/logintools.html#no-login-no-access
Kent
--
http://mail.python.org/mail
.
Never? When you move on? You can become proficient in a couple of months but
that is different from "expert" which is different from "knows everything there
is to know". I have been using Python for several years and I still learn from
the old hands in this news group.
Ken
hop", but most of them were alpha,
> better, or seemed to be forsaken a long time ago. Can you recommend me
> anything?
>
SQLObject, PyDO, Durus and Django's database API.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
binary has to run in order to use the
> dbase. Oh, and I'm using Python under Cygwin.
Depending on what you mean by "SQL-like" you might like KirbyBase
http://www.netpromi.com/kirbybase.html
Kent
--
http://mail.python.org/mailman/listinfo/python-list
. for
information on suggesting changes." If you click the link there it will tell
you how to submit a doc bug which is the best way to get this fixed.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
next caller up. See example below.
Kent
>
> I have this program:
>
> import sys
> from xml.dom.minidom import parse
>
>
> # search the tree for an element with a particular class
>
> def findelement(current, classtofind, topnode = None):
> if topnode
401 - 500 of 792 matches
Mail list logo