not sure about the right code structure of python oop.
Can anyone give some hint on it? would be great with reason.
Thanks in advance.
regards,
Kent
--
http://mail.python.org/mailman/listinfo/python-list
> * to do the same modification on the list "a" within a function
> * not to hardcode in this function the position of the string in each
>>> a = [ [4, "toto"], [5, "cou"] ]
>>> def assign(element,pos,newValue):
... element[pos]=newValue
...
>>> assign(a[0],1,'xxx')
>>> print a
[[4, 'xxx'],
On Mar 27, 3:01 pm, "David L. Jones" wrote:
> On Mar 26, 8:51 pm, Kent wrote:
>
> > ... Is
> > there any convention how to manage python classes into .py files?
>
> > ...
> > In above packages, each .py file contains one python class. And
> > C
uot;empty area"
of the lc, nothing happened, no popup menu. I tested under WINXP, the
function was not triggered at all when I right-clicked on the "empty
area".
I tried to bind wx.EVT_RIGHT_DOWN(UP) to the lc, but the function
cannot be triggered under Linux. any suggestion?
Thanks
re
#this is the function
def onTagMgmt(self,event):
tagId = event.GetData()
# following codes are omitted. just some business logic stuff.
checking the tagId, making decision of showing popup menu items...
Kent
On Apr 21, 11:24 pm, Mike Driscoll wrote:
> On Apr 21, 3:35 pm,
hello all,
i want to add a "new update notification" feature to my wxPython appl.
The codes below do the job. The logic is simple enough, I don't think
it needs to be explained.
since sometimes, under windows, proxy setting was a script. and was
set in IE. In this case, connecting to the HTML wil
Thanx you guys.
Now my program is working.
I used the Thread subclass. and at the end of the run method, i call
wx.CallAfter(mainFrame.somefunction, para) to show the dialog or
change some text. I tested in winxp&linux. both worked.
Kent
On Apr 23, 6:16 am, Carl Banks wrote:
> On Ap
le Error object which
implements the required methods at each level to just return self.
I don't know if this really works when you start nesting but perhaps
it is worth a try.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Try this on your *nix command line: echo ">$100"
On a *nix command line, the '$1' part of ">$100" will be seen as 'give me the
value of the shell variable "1"', and since it has no value, will result in an
empty string. So it's not optparse, or Python, because the literal string you
intend to
I agree that each test should test only one 'thing', but it's also true that
testing one 'thing' sometimes/often involves multiple assertions. But in the
OP's case, it does sound like the assertion he wants to skip should be broken
out into its own test.
--
http://mail.python.org/mailman/listi
You could also install Python 2.7 on that RedHat machine. It can be done
without interfering with the 2.5 that RedHat depends on.
--
http://mail.python.org/mailman/listinfo/python-list
If a filename does not contain a path component, os.path.abspath will prepend
the current directory path onto it.
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I've taught a python course with some positive results to high school students
with zero experience in programming. Now I am making these course materials
(slides in English and lecture videos in Cantonese) freely available as a
contribution back to the community
(http://www.istudycenter.o
Hi all,
This is a set of training materials I used to successfully teach Python to kids
as little as 10 years old. It was a success because the kids didn't just finish
the course, they independently completed most of the coding challenges by
applying the knowledge they had learned.
The first f
Hi,
I can add new variables to user-defined classes like:
>>> class Test:
... pass
...
>>> a=Test()
>>> a.x=100
but it doesn't work if the instances belong to a built-in class such as str or
list:
>>> a='abc'
>>> a.x=100
Traceback (most recent call last):
File "", line 1, in
Attribu
Hi Peter,
Thanks a lot for your excellent explanation!
--
https://mail.python.org/mailman/listinfo/python-list
Hi
I'm aware that we can use 'pass' as an empty code block. But why doesn't python
allow a code block to be empty and thus eliminate the need for this null
statement?
thanks in advance
--
https://mail.python.org/mailman/listinfo/python-list
On Saturday, July 23, 2016 at 9:49:51 AM UTC+8, Steven D'Aprano wrote:
> Because it cannot tell the difference between an empty code block and
> failing to indent the code block:
>
> for x in sequence:
> print('loop')
Thanks for the excellent answer!
--
https://mail.python.org/mailman/listinfo/
Hi,
I've made an online python learning environment available at
https://p4kweb.appspot.com
Please take a look and let me know what you think :-)
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
If you're interested, please get it for free at:
https://www.amazon.com/Yes-Kids-can-learn-Python-ebook/dp/B084CY2L43/ref=sr_1_3
This is a set of training materials I used to successfully teach Python to kids
as little as 10 years old. The online learning environment are freely available
at
#x27;__main__':
unittest.TextTestRunner().run(suite())
This runs under Jython (Python 2.1); in more recent Python I think you can
override TestSuite.run() instead of __call__().
Kent
--
http://mail.python.org/mailman/listinfo/python-list
?
> NameError: name 'Sphere' is not defined
Which version of cgkit are you using?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
vate {
public static void main(String[] argv) throws Exception {
HasPrivate hp = new HasPrivate();
Field notSoPrivate = hp.getClass().getDeclaredField("myPrivate");
notSoPrivate.setAccessible(true);
System.out.println("myPrivate = " + notSoPrivate.getInt(hp));
}
}
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ule:
euro=euro + float(rechnung[element][10].strip('"').replace(',' , '.'))
Kent
--
http://mail.python.org/mailman/listinfo/python-list
See the os, os.path and shutil modules for many file operations including copy
and move.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
EDB.1; User ID=user; Password=passwd;Initial
Catalog=Northwind;Data Source=(local)"
HTH
Kent
--
http://mail.python.org/mailman/listinfo/python-list
rovement, in style, logic, easier
> ways of doing things etc.
I second gene's recommendation of the python-tutor mailing list - we do all of
the above as well as cheerfully answer all questions, give suggestions on how
to do things, etc.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
r x in y]
[1, 2, 3, 4]
The outer loop comes first.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
it(' ')]
> Traceback (most recent call last):
> File "", line 1, in ?
> NameError: name 'y' is not defined
The order of the 'for' clauses is backwards:
>>> [x for y in mystr.split(' ') for x in y.split('_')]
['this', 'NP', 'is', 'VL', 'funny', 'JJ']
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Laszlo Zsolt Nagy wrote:
> Is this the good place to post?
Follow the "About this document" link at the bottom of any page of Python docs
for information about submitting change requests.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
is better than the obvious
triangle=3
square=4
color=red
drawshapes(polygon(triangle, color),
polygon(square, color) )
or even
drawshapes(polygon(3, red),
polygon(4, red) )
which is concise and readable IMO...?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
looks like this:
def openFileAndProcessContents(filename):
data = open(filename).read()
processContents(data)
then you can write your tests against processContents() and just pass it a
string with the test data.
I usually have a set of test files as part of my project that I can pass to
funct
ced, the docs are often helpful:
pprint( object[, stream[, indent[, width[, depth]]]])
Changed in version 2.4: The parameters indent, width and depth were added.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
; (which I've had a pleasant experience
> with in the past) or any of the other parsers listed on the PLY site's
> "Other Python Parsing Tools".
A more complete list is here:
http://www.nedbatchelder.com/text/python-parsers.html
I have found pyparsing easy to work with.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
;, this will call a special method
of the object bound to l2, passing "hello" as a parameter. The result will be
evaluated as True or False. The actual method called on l2 may be __cmp__ or
__eq__.
http://docs.python.org/ref/customization.html
Kent
>
> and what if I never used it in the definition body?
>
> Elucidate please.
>
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> how ?
> i have tried to use unix timestamps, and i have also tried with
> DateTime objects
> do i need to use a scale that isn't linear (default in most) ?
> how do i putt this off ?
Here is some code that works for me. It plots multiple datasets against time.
The input
good reason for update :)
or learn about decorate-sort-undecorate:
lst = [ ...whatever ]
lst = [ x[3], i, x for i, x in enumerate(lst) ]
lst.sort()
lst = [ x for _, _, x in lst ]
Kent
>
> Thanks,
> Michele
--
http://mail.python.org/mailman/listinfo/python-list
>>> re.IGNORECASE
2
>>> pattern = re.compile('.*HTTP/(\d\.\d) *(\d*) *(.*)$', re.IGNORECASE)
>>> pattern.search("GGHTTP/1.1 200 OK\r\n")
<_sre.SRE_Match object at 0x00965980>
>>> pattern.search("GHTTP/1.1 200 OK\r\n")
<
k before October 30. See
for example
http://www.bookpool.com/sm/159059519X
Kent
--
http://mail.python.org/mailman/listinfo/python-list
gt;
> would show
>
> list = [ 6 ]
You have to put a mutable object into the list - something whose state you can
change. For example this works, because temp and lst[0] are references to the
same mutable (changeable) list:
>>> temp = [6]
>>> lst = [temp]
>>> lst
[[6]]
>>> temp[0] = 5
>>> lst
[[5]]
Kent
--
http://mail.python.org/mailman/listinfo/python-list
d it shows up ( no x value found)
>
> how should i proceed?
Convert one of the values to a float? What are your time and value numbers?
Kent
--
http://mail.python.org/mailman/listinfo/python-list
a3a3c287e8e2a3?hl=en&;
Kent
>
> ..this is windows by the way.
>
> For example:
> tmp = os.popen("hostname").read()
>
> ...works as expected.
>
> however,
>
> tmp = os.popen("cmd").read()
> ...i would like to have access to the cmd proc
have seen (on
small bits of code) is 3:1.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ws.get('color', 'BLUE')
In general when you subclass an immutable type you have to override __new__
rather than __init__. There is some explanation and example here:
http://www.python.org/2.2.3/descrintro.html#__new__
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Ugh. The code generated by jythonc is *nothing like* the code you would write
by hand to do the same thing. This is a meaningless comparison.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
mething:
import oneMod as theMod
else:
import orTheOtherMod as theMod
helper.theMod = theMod
import aModule
# in aModule
import helper.theMod as theMod
theMod.someFunction()
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ender()
ditto
In this example it doesn't make any difference but with a deeper inheritance
hierachy it does. See
http://www.python.org/2.2.3/descrintro.html#cooperation
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ow."
>
> Oh wait! Yes I do... the setter doesn't actually take an argument to set
> the property too. Is that it, or have a missed a cunningly hidden deeper
> problem?
Derived.getFoo() will not override the use of Base.getFoo() to access the
attribute foo.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
(from the pickaxe book):
File.open("testfile") do |file|
file.each_line { |line| puts line }
end
Kent
>
> Alex Martelli wrote:
>
>>[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>>
>>>could someone enlighten me what is the advantage of bloc
= os.listdir('.')
Python has built-in support for many file manipulations, see the os, os.path
and shutil modules.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
ies of HELP commands to cmd.exe, captures
the output of the commands and saves it to a file.
What did I miss?
Kent
>
>
> Kent Johnson wrote:
>
>>jas wrote:
>>
>>>I would like to redirect the output from os.system to a variable, but
>>>am having tr
asically I was opening to send the "ipconfig" command to cmd.exe and
> store the result in the "result" variable. But you can see there was
> an error with result.
This works for me:
import subprocess as sp
p = sp.Popen("ipconfig", stdout=sp.PIPE)
result = p.communicate()[0]
print result
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Istvan Albert wrote:
> All I can add to this is:
>
> - don't use SAX unless your document is huge
> - don't use DOM unless someone is putting a gun to your head
+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> I want to scan a file byte for byte for occurences of the the four byte
> pattern 0x0100.
data = sys.stdin.read()
print data.count('\x00\x00\x01\x00')
Kent
--
http://mail.python.org/mailman/listinfo/python-list
n Python is driven from the command line. However,
>>they
>
>
> The "MS-DOS" command window tends to use a different character
> encoding than full "Windows" widgets.
You can chaneg the encoding used by the command window with the chcp command.
Kent
--
http://mail.python.org/mailman/listinfo/python-list
(not tested):
inf = open('input.txt')
out = open('output.txt', 'w')
skips = [
'xxx xx x xxx',
'y yy yyy yy y yyy',
]
for line in inf:
for skip in skips:
if skip in line:
continue
out.write(line)
inf.close()
out.close()
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
. 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
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
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
.
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
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
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
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
0b19b37ac48deaa/e599041de4b8feb0?rnum=22#e599041de4b8feb0
Kent
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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 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
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
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
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
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
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
% ('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
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
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
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
> "
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
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
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
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
= 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
://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
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
:
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
ripts, but has no
> formal programming training.
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
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
nt
binaries for this package?
Thanks,
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
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
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
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
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
, 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
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
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
>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
('\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
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
1 - 100 of 792 matches
Mail list logo