> Oh wait, I know: let's all start writing code in MS Word .doc
format!
> Arial for functions, Times New Roman for classes. Who's with me?
;-)
So you've been looking at Eiffel then?
:-)
Alan G.
___
Tutor maillist - Tutor@python.org
http://mail.pytho
I'm going to look more in to import hooks. I am only looking for
syntactic sugar, at least at this point. It's not really my ambition
to
make more efficient code.
To Ryan. I looked at COG before (not in this case but general
looking
at python packages) it doesn't really do what I was thinki
Chad Crabtree wrote:
> Ok I'll explain what I've done so far.
[...]
> I hope I made myself clearer.
Yes. To add new stuff to the language you would have to work at the
interpreter level. Probably you can avoid going too deep using import
hooks, as it has already been suggested, to modify what's
Tony Meyer said unto the world upon 2005-01-27 21:46:
[Sean Perry]
And now, for the pedant in me. I would recommend against naming
functions with initial capital letters. In many languages, this
implies a new type (like your Water class). so
CombineWater should be combineWater.
[Brian van den B
Kent Johnson said unto the world upon 2005-01-27 16:08:
Brian van den Broek wrote:
Finally, in the first instance, I was aiming for the OP's stated end.
To make this more general and reusable, I think I'd do:
def get_list_dup_dict(a_list, threshold=1):
items_dict, dup_dict = {}, {} # Ques
[Sean Perry]
>> And now, for the pedant in me. I would recommend against naming
>> functions with initial capital letters. In many languages, this
>> implies a new type (like your Water class). so
>> CombineWater should be combineWater.
[Brian van den Broek]
> Do you mean implies by the dominan
Try this
def findfile(thefile,
toplevel="C:\\windows",findcount=-1,subdirectories=True,returnlist=False):
results = []
t = 0
if subdirectories:
for root,dirs,files in os.walk(toplevel):
for x in files:
fullname = os.path.join(root,x)
if x.lo
I've used something along the lines for Pythoncard, but the names are
generated within strict rules and expectations.
i.e.
first off รข
#Some code that uses regExs, finds all headings, and
# a asterisk to indicate a date value, returns a iterable object
reHead using finditer()
#which contai
Check out COG (http://www.nedbatchelder.com/code/cog/), a macro system for any
language created by Ned Batchelder
(http://www.nedbatchelder.com/).
I'm not sure if that's what you're looking for, but allows some good macro
capabilities.
Thanks,
Ryan
-Original Message-
From: [EMAIL PROT
Well I don't think that it would really require that. I could just
define macro's in a module and just do it like so
import macro
import defined_macros as m
macro.expand(m.with(),m.assert())
I just thought it would be best to have definitions at the head of a
script, or at least to have the o
Chad Crabtree wrote:
I'm trying to make a macro system that's work by just doing this
import macro
# [...]
Perhaps you could turn things around, and make your macro preprocessor
into an import hook? I.E., you'd use it like --
import macro
module = macro.import("module_with_macros"[, macr
Brian van den Broek wrote:
incorporating some of Wolfram's and Kent's (hope I've missed no one)
suggestions:
def dups_in_list_report(a_list):
'''Prints a duplication report for a list.'''
items_dict = {}
for i in a_list:
items_dict[i] = items_dict.get(i, 0) + 1
for k, v i
Try a simple bubble sort. This will not have great performance on
big
files at a worst case scenario it will take n-1 loops to sort. This
is
not very general and would require a substantially different
implementation.
def bublesort(l1,l2,l3):
modified=True
while modified:
modif
Kent Johnson said unto the world upon 2005-01-27 05:57:
Brian van den Broek wrote:
Wolfram Kraus said unto the world upon 2005-01-27 03:24:
This whole part can be rewritten (without sorting, but in Py2.4 you
can use sorted() for this) with a list comprehension (Old Python2.1
style, with a newer
Ok I'll explain what I've done so far. I'm using tokenize to take
the
file that imports macro; found by using stack inspection and then
tokenize it. I look at all the string tokens to see if they match
they
pattern a macro should have. Then I pass the macro string through
the
tokenizer agai
On Thu, 27 Jan 2005, Miles Stevenson wrote:
> I'm trying to practice safe coding techniques. I just want to make sure
> that a user can't supply a massive argument to my script and cause
> trouble. I'm just trying only accept about 256 bytes:
>
> buffer(sys.argv[1], 0, 256)
^^
Hi Miles,
On Jan 27, 2005, at 18:17, Bill Mill wrote:
I've never used buffer(); in fact, I didn't even know it existed, and
I've been using python for a while now.
Instead of using buffer, just do:
sys.argv[1] = sys.argv[1][:255]
This says "Set the second element of sys.argv equal to its first 256
characters
Miles,
On Thu, 27 Jan 2005 13:08:05 -0500, Miles Stevenson
<[EMAIL PROTECTED]> wrote:
> Newbie question.
>
> I'm trying to practice safe coding techniques. I just want to make sure that a
> user can't supply a massive argument to my script and cause trouble. I'm just
> trying only accept about 2
Newbie question.
I'm trying to practice safe coding techniques. I just want to make sure that a
user can't supply a massive argument to my script and cause trouble. I'm just
trying only accept about 256 bytes:
buffer(sys.argv[1], 0, 256)
searchpath = sys.argv[1]
The script runs successfully, b
> I'm trying to make a macro system that's work by just doing this
OK, But to get your acros to use a language extension to python
(the with syntax) you are going to have to write your own
language interpreter/parser. Even if that just turns the 'with'
stuff into Python.
So why is the """ ma
Srinivas,
You can't sort a string, since it's immutable. You can, however, sort
a list. To sort your table by the third element, you can do something
like this:
>>> table = (("apple", "fruit", "denmark"),
... ("mummy", "antique", "egypt"),
... ("taj", "wonder", "india"),
... ("f-16", "fighter", "
I'm trying to make a macro system that's work by just doing this
import macro
class withMacro(prefixMacro):
pass
mac=withMacro()
mac.pattern("item key")
macro.expand()
g=[]
"""
with g:
.append('a')
.append('b')
.append(123)
"""
I would like to not have to use the comment strings
Dear Danny, thank you for ur help. But a basic
question ?
In a table, more specifically a matrix 3X3,
AppleFruitDenmark
F-16 Fighter USA
Taj Wonder India
MummyAntique Egypt
IF I have to sort on country, it should be
AppleFruitDenmark
MummyAntique Egypt
Taj
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Are there any example programs depicting Clustering
algorithms such as agglomerative, complete link,
partional , squared error clustering, k-means or
clustering algos based on Neural networks or genetic
algorithm. although I just learned python, (to m
Kumar,
On Wed, 26 Jan 2005 22:35:59 -0800 (PST), kumar s <[EMAIL PROTECTED]> wrote:
> Hi:
>
> I am still trying to learn the OOPs side of python.
> however, things/circumstances dont seems to stop until
> I finish my practise and attaing higher understanding.
> may be, i am being pushed by circum
If your program is written so it doesn't do anything when imported, you could
use
> python -c "import myprogram"
myprogram.py should have a structure like this:
def main():
# do something...
if __name__ == '__main__':
main()
The "if __name__ ..." prevents the module from doing anything when i
-Original message-
From: "Alan Gauld" [EMAIL PROTECTED]
Date: Thu, 27 Jan 2005 05:08:07 -0500
To: "Chad Crabtree" [EMAIL PROTECTED]
Subject: Re: [Tutor] Syntax Check
> > Does anyone happen to know how to turn of the syntax checking in
> > python? I've been working on a module driven prep
Chad Crabtree wrote:
> Does anyone happen to know how to turn of the syntax checking in
> python? I've been working on a module driven preprocessor but I'd
> like to not have to use comment strings.
I don't think that's possible. What would the compiler do with code
with an invalid syntax?
W
Google is your friend: Googling 'python clustering algorithm' gives many hits that seem to have what
you are looking for.
Kent
kumar s wrote:
Hi:
I am still trying to learn the OOPs side of python.
however, things/circumstances dont seems to stop until
I finish my practise and attaing higher und
Brian van den Broek wrote:
Wolfram Kraus said unto the world upon 2005-01-27 03:24:
Brian van den Broek wrote:
for key in items_dict.copy(): # Try it without the .copy()
if items_dict[key] == 1:# and see what happens.
del items_dict[key]
dict_keys = items_dict.key
> Does anyone happen to know how to turn of the syntax checking in
> python? I've been working on a module driven preprocessor but I'd
> like to not have to use comment strings.
So don't use them! They aren't mandatory.
I'm not sure I understand youir problem? Why would turning
off syntax check
> > functions with initial capital letters. In many languages, this
implies
> > a new type (like your Water class). so CombineWater should be
combineWater.
>
> Do you mean implies by the dominant coding conventions, or by
language
> syntax? (Indulging the curious pedant in me.)
Coding convention.
> for i in range(len(a)):
> for k in range(len(a)):
for k in range(i,len(a)):
is faster, and if you calculate len before starting the
loops that will speed it up too. (You calculate len for
each iteration of each loop!)
> if i != k:
> if a[i] == a[k]:
> print a[i]
> break
HTH
Alan G.
___
> I hear that Alan Gauld's tutorial is also very good, but geared more
> towards people new to programming.
Yes, I try to take folks to the point where they can understand the
official tutor (well maybe a wee bit further than that, but that
was the original target...)
> (which itself should be in
> Greetings all, I'm new to python and thought I'd pop in here for
advice.
Good decisions both :-)
> I've done object oriented design and programmed in perl, java, c++,
basic, etc.
> ...
> I'm curious about good tutorial websites and books to buy.
With your background the standard Python tutoria
> This is something I've been trying to figure out for some time. Is
> there a way in Python to take a string [say something from a
> raw_input] and make that string a variable name? I want to to this
so
> that I can create class instances on-the-fly, using a user-entered
> string as the instance
Does anyone happen to know how to turn of the syntax checking in
python? I've been working on a module driven preprocessor but I'd
like
to not have to use comment strings.
__
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection
Wolfram Kraus said unto the world upon 2005-01-27 03:24:
Brian van den Broek wrote:
Thanks Wolfram,
I knew someone would improve what I posted. (It can always be done ;-)
for i in a_list:
if i in items_dict:
items_dict[i] = items_dict[i] + 1
else:
items_
Chad Crabtree wrote:
Ok you got me thinking. I used the same thing I posted before but
created a one liner that as a side affect makes adict like before.
[adict.__setitem__(x,adict.get(x,0)+1) for x in l]
I think it's kinda funny and ugly, ohh and not particuarly clear
about what it does.
Uhh
Ok you got me thinking. I used the same thing I posted before but
created a one liner that as a side affect makes adict like before.
[adict.__setitem__(x,adict.get(x,0)+1) for x in l]
I think it's kinda funny and ugly, ohh and not particuarly clear
about
what it does.
Wolfram Kraus wrote:
> g
Brian van den Broek wrote:
[...]
Hi Srini,
for the task of finding out which items are repeated and how many times,
I'd do this:
def dups_in_list_report(a_list):
'''Prints a duplication report for a list.'''
items_dict = {}
for i in a_list:
if i in items_dict:
ite
Brian van den Broek wrote:
Sean Perry said unto the world upon 2005-01-27 02:13:
And now, for the pedant in me. I would recommend against naming
functions with initial capital letters. In many languages, this implies
a new type (like your Water class). so CombineWater should be
combineWater.
Do
42 matches
Mail list logo