Re: Question

2008-07-19 Thread Paddy
On Jul 19, 10:27 am, [EMAIL PROTECTED] wrote:
> Why is Perl so much better than python?

Coz its endorsed by:
 Chernobble valve controls.
 Barings Bank.
 The society of the Mortgage Brokers of America.
 The Bush Disaster relief fund for the Southern States.

And, of course, is the tool of choice when looking for weapons of mass
destruction in Iraq.


- Paddy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread Raymond Hettinger
On Jul 19, 2:27 am, [EMAIL PROTECTED] wrote:
> Why is Perl so much better than python?

Because dollar signs are a superior form of punctuation.


Raymond
--
http://mail.python.org/mailman/listinfo/python-list


Re: MethodChain

2008-07-19 Thread Paul McGuire
On Jul 20, 12:01 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> The methods are a problem IMHO.  You can't add an own method/function with
> the name `fire()` or `toFunction()`.  `MethodChain` has to know all
> functions/methods in advance.  You can add the methods of whole classes at
> once and there are over 300 pre-added, this begs for name clashes.
>
> Ciao,
>         Marc 'BlackJack' Rintsch

If you shift the syntax just a bit, instead of writing a.b.c, pass a,
b, and c as the args to a MethodChain object.  Here's a rough stab at
the problem:

class MethodChain(object):
def __init__(self, *fns):
self.fns = fns[:]
def __call__(self,*args):
if self.fns:
for f in self.fns:
args = (f(*args),)
return args[0]

def dncase(s):
return s.lower()

def upcase(s):
return s.upper()

def stripVowels(s):
return "".join( c for c in s if c not in "aeiou" )

def selectItems(items,s):
return "".join(c for i,c in enumerate(s) if i in items)

from functools import partial

chn = MethodChain(
dncase,
stripVowels,
upcase,
partial(selectItems,(0,2))
)

print chn("FoO Bar")


-- Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-19 Thread John Machin
On Jul 20, 11:14 am, Andrew Freeman <[EMAIL PROTECTED]> wrote:
> John Machin wrote:

> (4) I highly doubt that this code was actually to be used in an
> interactive session,

The offending code is a nonsense wherever it is used.

> the False/True output was truncated intentionally,

What meaning are you attaching to "truncated"?

> it's an obvious, but superfluous output (unless you were to rely on this
> by attaching it to a variable which might lead to sorting issues).
>
> I put together a generic matcher that returns either a list of True data
> (if the input is a list or tuple) or a boolean value:
>
> def match(ex, var):
> "ex is the regular expression to match for, var the iterable or
> string to return a list of matching items or a boolean value respectively."
> ex = re.compile(ex).match

You lose clarity by rebinding ex like that, and you gain nothing.


> if isinstance(var, (list, tuple)):
> return filter(ex, var)
> else:
> return bool(ex(var))
>
> I believe this is fairly clean and succinct code, it would help my
> learning immensely if you feel there is a more succinct, generic way of
> writing this function.

You have created a function which does two quite different things
depending on whether one of the arguments is one of only two of the
many kinds of iterables and which has a rather generic (match what?)
and misleading (something which filters matches is called "match"??)
name. The loss of clarity and ease of understanding caused by the
readers having to find the code for the function so that they can
puzzle through it means that the most succinct, generic and
*recommended* way of writing this function would be not to write it at
all.

Write a function which returns a MatchObject. In the unlikely event
that that anyone really wants to put bools in a list and sort them,
then they can wrap bool() around it. Give it a meaningful name e.g.
match_LRM.

You want to check if a single variable refers to a valid LRM string?
Use match_LRM(the_variable). Nice and clear.

You want to filter out of some iterable all the occurrences of valid
LRM strings? Use filter (whose name indicates its task) or a generator
or list comprehension ... what [x for x in some_iterable if
match_LRM(x)] does should be screamingly obvious i.e. have less chance
than filter of needing a trip to the manual.

HTH,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: checking if an object IS in a list

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 13:13:40 -0700, nicolas.pourcelot wrote:

> On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote:
>> > So, I use something like this in 'sheet.objects.__setattr__(self,
>> > name, value)':
>> > if type(value) == Polygon:
>> >     for edge in value.edges:
>> >         if edge is_in sheet.objects.__dict__.itervalues():
>> >             object.__setattr__(self, self.__new_name(), edge)
>>
>> > Ok, I suppose it's confused, but it's difficult to sum up. ;-)
>>
>> You are setting attributes with computed names?  How do you access them?
>> Always with `gettattr()` or via the `__dict__`?  If the answer is yes, why
>> don't you put the objects the into a dictionary instead of the extra
>> redirection of an objects `__dict__`?
>>
> 
> Yes, I may subclass dict, and change its __getitem__ and __setitem__
> methods, instead of changing objets __setattr__ and __getattr__... But
> I prefer
 sheet.objects.A = Point(0, 0)
> than
 sheet.objects["A"] = Point(0, 0)

But with computed names isn't the difference more like

setattr(sheet.objects, name, Point(0, 0))
vs.
sheet.objects[name] = Point(0, 0)

and

getattr(sheet.objects, name)
vs.
sheet.objects[name]

Or do you really have ``sheet.objects.A`` in your code, in the hope that
an attribute named 'A' exists?

>> Oh and the `type()` test smells like you are implementing polymorphism
>> in a way that should be replaced by OOP techniques.
> 
> I wrote 'type' here by mistake, but I used 'isinstance' in my code. ;-)

Doesn't change the "code smell".  OOP approach would be a method on the
geometric objects that know what to do instead of a type test to decide
what to do with each type of geometric object.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Re: Best Python packages?

2008-07-19 Thread Kay Schluehr
On 20 Jul., 05:54, "Python Nutter" <[EMAIL PROTECTED]> wrote:
> I think the hidden gems in multimedia/game production are Pyglet and
> Rabbyt. Whereas PyGame is the older api, its large and bloated and has
> of course a heavy dependency on SDL. Pyglet and Rabbyt are
> lightweight, efficient, have some amazing functions and hit native
> OpenGL in all the major OS distributions and Bruce The Presentation
> Tool utilizes the former to take on MS PowerPoint to show what you can
> do besides games =)
>
> Pyglet:http://pyglet.org/
> Rabbyt:http://matthewmarshall.org/projects/rabbyt/
> Bruce The Presentation Tool:http://code.google.com/p/bruce-tpt/
>
> Cheers,
> PN
>
>
>
> > In the original post you asked for "hidden gems" and now it seems you
> > just want to know about Madonna or Justin Timberlake.
>
> > Maybe a look on this collection helps
>
> >http://wiki.python.org/moin/UsefulModules
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Maybe someone starts a blog with the title "Hidden Pythons"?

Just one short remark about Python game toolkits. The single reason I
won't use them is browser accessibility. It doesn't matter to me where
Python scripts are running but less so where applications are
executed. Right now I'm stuck with AS3/Flash.

Given Adobes recent OSS commitments and PyPys efforts in translating
RPython to several backends I'm not too pessimistic that we'll see
Python in the Flashplayer in a year or two from now.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Not entirely serious: recursive lambda?

2008-07-19 Thread Paul McGuire
On Jul 19, 11:49 pm, Miles <[EMAIL PROTECTED]> wrote:
> On Sat, Jul 19, 2008 at 10:43 PM, Michael Tobis <[EMAIL PROTECTED]> wrote:
> > Can a lambda call itself without giving itself a name?
>
> Kind of.  There's a couple ways I know of.
>
> The functional way, which involves the lambda receiving itself as an argument:
>
> (lambda f: f(10, f))(lambda n, f: n and (sys.stdout.write("%d\n" % n)
> or f(n-1,f)))
>
> The stack frame examination way:
>
> import sys, inspect, new
> (lambda:sys.stdout.write('recurse\n') or
> new.function(inspect.currentframe().f_code, globals())())()
>
> The functional way is probably harder to grok unless you've studied
> lambda calculus or had experience with "real" functional languages (I
> haven't).  For fun, try throwing a Y combinator in there.
>
> -Miles

Here is Michael Tobis's original program, using the functional
approach:

print (lambda f:f(("",reduce(lambda
c,m:c*95+''.join(map(chr,range(32,127))).index(m),
 "!b)'1Mgh0z+fYQ]g::i^<&y~g)cnE-d=K&{GMNQ1gx
+ooY<~L##N'X]P2<@XYXwX3z",
0),f)))(lambda (r,N,f):N and f((" acdefijlmnopqrstuv"[N%19]+r,N/
19,f))or(r,N,f))[0]

Très assombri! (according to Babelfish...).

-- Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: MethodChain

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 13:57:33 -0700, bearophileHUGS wrote:

> Marc 'BlackJack' Rintsch:
>> What's called `MethodChain` there seems to be function composition in
>> functional languages.  Maybe `functools` could grow a `compose()` function.
> 
> To me it looks like a quite more "refined" thing, it's an object, it
> has some special methods, etc. I think it's not too much difficult to
> implement it with Python.

The methods are a problem IMHO.  You can't add an own method/function with
the name `fire()` or `toFunction()`.  `MethodChain` has to know all
functions/methods in advance.  You can add the methods of whole classes at
once and there are over 300 pre-added, this begs for name clashes.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: atan2 weirdness

2008-07-19 Thread Raymond Hettinger
On Jul 19, 9:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> hi
>
> atan2 is supposed to return the angle to x-axis when given y and x, I
> suppose if I take [x,y] to one full circle, I should get 0-360 degree
> back but no, I get 3 full revolutions!
> maybe my understanding is wrong.
>
> from math import *
>
> def f(ang):
>  a=ang
>  if a>360: a-=360
>  if a>360: a-=360
>  if a<0: a+=360
>  if a<0: a+=360
>  return round(a)
>
> for i in range(0,360):
>  t=2*pi*i/360.0
>  print i,f(atan2(sin(t),cos(t))*180.0)

The "*180.0" part should be "*180/pi".

Do yourself some favors. First use the degrees and radians functions
in the math module. Second, when in doubt, print the intermediate
results (that would have made the error obvious). Third, pick just one
line of the result and compute it with your calculator by hand (to
make sure you know what your program is doing.  Lastly, when working
with trig functions, always check the docs to make sure you know the
ranges of values returned (i.e. atan2 returns from -pi to +pi).
Here's a proposed revision:

from math import pi, atan2, radians, degrees, cos, sin

for i in range(360):
t = radians(i)
x = cos(t)
y = sin(t)
a = degrees(atan2(y, x))
print i, t, x, y, a


Raymond



--
http://mail.python.org/mailman/listinfo/python-list


Re: Not entirely serious: recursive lambda?

2008-07-19 Thread Miles
On Sat, Jul 19, 2008 at 10:43 PM, Michael Tobis <[EMAIL PROTECTED]> wrote:
> Can a lambda call itself without giving itself a name?

Kind of.  There's a couple ways I know of.

The functional way, which involves the lambda receiving itself as an argument:

(lambda f: f(10, f))(lambda n, f: n and (sys.stdout.write("%d\n" % n)
or f(n-1,f)))

The stack frame examination way:

import sys, inspect, new
(lambda:sys.stdout.write('recurse\n') or
new.function(inspect.currentframe().f_code, globals())())()

The functional way is probably harder to grok unless you've studied
lambda calculus or had experience with "real" functional languages (I
haven't).  For fun, try throwing a Y combinator in there.

-Miles
--
http://mail.python.org/mailman/listinfo/python-list


Re: atan2 weirdness

2008-07-19 Thread Carsten Haese

[EMAIL PROTECTED] wrote:

hi

atan2 is supposed to return the angle to x-axis when given y and x, I
suppose if I take [x,y] to one full circle, I should get 0-360 degree
back but no, I get 3 full revolutions!
maybe my understanding is wrong.

from math import *

def f(ang):
 a=ang
 if a>360: a-=360
 if a>360: a-=360
 if a<0: a+=360
 if a<0: a+=360
 return round(a)

for i in range(0,360):
 t=2*pi*i/360.0
 print i,f(atan2(sin(t),cos(t))*180.0)


Your understanding of atan2 is correct, but your conversion from radians 
to degrees is off by a factor of pi. Since pi is close to 3, you're 
getting what appears to be three full revolutions.


HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any Game Developers here?

2008-07-19 Thread Michael Lubker
Rabbyt is developed by one of my colleagues.

I'm currently using Python-Ogre and Anims (for 3D animation, broken
off from Rabbyt by Matthew) for my game, SnowballZ.

Thanks
Michael

On Sat, Jul 19, 2008 at 10:33 PM, Python Nutter <[EMAIL PROTECTED]> wrote:
> I used to use PyGame but the horrible delay waiting for OS X binaries
> put me off.
>
> I now use Pyglet extensively, and combine Pyglet + Rabbyt to get
> amazing sprite handling speeds.
>
> Pyglet/Rabbyt make use of OpenGL which comes installed on all the
> major systems out there.
>
> PyGame requires the installation of the SDL library to work so is a
> lot larger installation requirement.
>
> There are two books I know of currently in print on game programming,
> both use PyGame as it was out first. One book is horrible and only
> worth for cleaning yourself up after you use the bathroom. The second
> is really well written (The L express game programming book) and
> highly recommended if you need to get some basic game design and
> programming under your belt in Python.
>
> That said its stupidly easy to port examples to work on Pyglet/Rabbyt
> so you won't do yourself a dis-service if you want to buy the book but
> want to develop later in Pyglet/Rabbyt.
>
> Cheers,
> PN
>
> P.S. Since you've likely found Pyglet and PyGame already, the only
> other reference URL you need is for Rabbyt so go here for that:
> http://matthewmarshall.org/projects/rabbyt/
>
>
> 2008/7/19 Michael Lubker <[EMAIL PROTECTED]>:
>> Any people that use Python as the predominant language for their game
>> development here?
>>
>> ~Michael
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>



-- 
~ "The world hates change, yet it is the only thing that has brought
progress." ~ Charles Kettering

http://snowballz.joey101.net
--
http://mail.python.org/mailman/listinfo/python-list


atan2 weirdness

2008-07-19 Thread [EMAIL PROTECTED]
hi

atan2 is supposed to return the angle to x-axis when given y and x, I
suppose if I take [x,y] to one full circle, I should get 0-360 degree
back but no, I get 3 full revolutions!
maybe my understanding is wrong.

from math import *

def f(ang):
 a=ang
 if a>360: a-=360
 if a>360: a-=360
 if a<0: a+=360
 if a<0: a+=360
 return round(a)

for i in range(0,360):
 t=2*pi*i/360.0
 print i,f(atan2(sin(t),cos(t))*180.0)

0 0.0
1 3.0
2 6.0
3 9.0
4 13.0
5 16.0
6 19.0
7 22.0
8 25.0
9 28.0
10 31.0
11 35.0
12 38.0
13 41.0
14 44.0
15 47.0
16 50.0
17 53.0
18 57.0
19 60.0
20 63.0
21 66.0
22 69.0
23 72.0
24 75.0
25 79.0
26 82.0
27 85.0
28 88.0
29 91.0
30 94.0
31 97.0
32 101.0
33 104.0
34 107.0
35 110.0
36 113.0
37 116.0
38 119.0
39 123.0
40 126.0
41 129.0
42 132.0
43 135.0
44 138.0
45 141.0
46 145.0
47 148.0
48 151.0
49 154.0
50 157.0
51 160.0
52 163.0
53 167.0
54 170.0
55 173.0
56 176.0
57 179.0
58 182.0
59 185.0
60 188.0
61 192.0
62 195.0
63 198.0
64 201.0
65 204.0
66 207.0
67 210.0
68 214.0
69 217.0
70 220.0
71 223.0
72 226.0
73 229.0
74 232.0
75 236.0
76 239.0
77 242.0
78 245.0
79 248.0
80 251.0
81 254.0
82 258.0
83 261.0
84 264.0
85 267.0
86 270.0
87 273.0
88 276.0
89 280.0
90 283.0
91 286.0
92 289.0
93 292.0
94 295.0
95 298.0
96 302.0
97 305.0
98 308.0
99 311.0
100 314.0
101 317.0
102 320.0
103 324.0
104 327.0
105 330.0
106 333.0
107 336.0
108 339.0
109 342.0
110 346.0
111 349.0
112 352.0
113 355.0
114 358.0
115 1.0
116 4.0
117 8.0
118 11.0
119 14.0
120 17.0
121 20.0
122 23.0
123 26.0
124 30.0
125 33.0
126 36.0
127 39.0
128 42.0
129 45.0
130 48.0
131 52.0
132 55.0
133 58.0
134 61.0
135 64.0
136 67.0
137 70.0
138 74.0
139 77.0
140 80.0
141 83.0
142 86.0
143 89.0
144 92.0
145 96.0
146 99.0
147 102.0
148 105.0
149 108.0
150 111.0
151 114.0
152 118.0
153 121.0
154 124.0
155 127.0
156 130.0
157 133.0
158 136.0
159 140.0
160 143.0
161 146.0
162 149.0
163 152.0
164 155.0
165 158.0
166 162.0
167 165.0
168 168.0
169 171.0
170 174.0
171 177.0
172 180.0
173 183.0
174 187.0
175 190.0
176 193.0
177 196.0
178 199.0
179 202.0
180 205.0
181 158.0
182 161.0
183 164.0
184 167.0
185 170.0
186 173.0
187 177.0
188 180.0
189 183.0
190 186.0
191 189.0
192 192.0
193 195.0
194 198.0
195 202.0
196 205.0
197 208.0
198 211.0
199 214.0
200 217.0
201 220.0
202 224.0
203 227.0
204 230.0
205 233.0
206 236.0
207 239.0
208 242.0
209 246.0
210 249.0
211 252.0
212 255.0
213 258.0
214 261.0
215 264.0
216 268.0
217 271.0
218 274.0
219 277.0
220 280.0
221 283.0
222 286.0
223 290.0
224 293.0
225 296.0
226 299.0
227 302.0
228 305.0
229 308.0
230 312.0
231 315.0
232 318.0
233 321.0
234 324.0
235 327.0
236 330.0
237 334.0
238 337.0
239 340.0
240 343.0
241 346.0
242 349.0
243 352.0
244 356.0
245 359.0
246 2.0
247 5.0
248 8.0
249 11.0
250 14.0
251 18.0
252 21.0
253 24.0
254 27.0
255 30.0
256 33.0
257 36.0
258 40.0
259 43.0
260 46.0
261 49.0
262 52.0
263 55.0
264 58.0
265 62.0
266 65.0
267 68.0
268 71.0
269 74.0
270 77.0
271 80.0
272 84.0
273 87.0
274 90.0
275 93.0
276 96.0
277 99.0
278 102.0
279 106.0
280 109.0
281 112.0
282 115.0
283 118.0
284 121.0
285 124.0
286 128.0
287 131.0
288 134.0
289 137.0
290 140.0
291 143.0
292 146.0
293 150.0
294 153.0
295 156.0
296 159.0
297 162.0
298 165.0
299 168.0
300 172.0
301 175.0
302 178.0
303 181.0
304 184.0
305 187.0
306 190.0
307 193.0
308 197.0
309 200.0
310 203.0
311 206.0
312 209.0
313 212.0
314 215.0
315 219.0
316 222.0
317 225.0
318 228.0
319 231.0
320 234.0
321 237.0
322 241.0
323 244.0
324 247.0
325 250.0
326 253.0
327 256.0
328 259.0
329 263.0
330 266.0
331 269.0
332 272.0
333 275.0
334 278.0
335 281.0
336 285.0
337 288.0
338 291.0
339 294.0
340 297.0
341 300.0
342 303.0
343 307.0
344 310.0
345 313.0
346 316.0
347 319.0
348 322.0
349 325.0
350 329.0
351 332.0
352 335.0
353 338.0
354 341.0
355 344.0
356 347.0
357 351.0
358 354.0
359 357.0


--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python packages?

2008-07-19 Thread Python Nutter
I think the hidden gems in multimedia/game production are Pyglet and
Rabbyt. Whereas PyGame is the older api, its large and bloated and has
of course a heavy dependency on SDL. Pyglet and Rabbyt are
lightweight, efficient, have some amazing functions and hit native
OpenGL in all the major OS distributions and Bruce The Presentation
Tool utilizes the former to take on MS PowerPoint to show what you can
do besides games =)

Pyglet: http://pyglet.org/
Rabbyt: http://matthewmarshall.org/projects/rabbyt/
Bruce The Presentation Tool: http://code.google.com/p/bruce-tpt/

Cheers,
PN

>
> In the original post you asked for "hidden gems" and now it seems you
> just want to know about Madonna or Justin Timberlake.
>
> Maybe a look on this collection helps
>
> http://wiki.python.org/moin/UsefulModules
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any Game Developers here?

2008-07-19 Thread Python Nutter
PS. To see some real games developed under pressure/time constraints
in Python you should visit PyWeek to see what individuals and teams
can create in only a weeks time!

http://pyweek.org/


2008/7/19 Michael Lubker <[EMAIL PROTECTED]>:
> Any people that use Python as the predominant language for their game
> development here?
>
> ~Michael
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any Game Developers here?

2008-07-19 Thread Python Nutter
I used to use PyGame but the horrible delay waiting for OS X binaries
put me off.

I now use Pyglet extensively, and combine Pyglet + Rabbyt to get
amazing sprite handling speeds.

Pyglet/Rabbyt make use of OpenGL which comes installed on all the
major systems out there.

PyGame requires the installation of the SDL library to work so is a
lot larger installation requirement.

There are two books I know of currently in print on game programming,
both use PyGame as it was out first. One book is horrible and only
worth for cleaning yourself up after you use the bathroom. The second
is really well written (The L express game programming book) and
highly recommended if you need to get some basic game design and
programming under your belt in Python.

That said its stupidly easy to port examples to work on Pyglet/Rabbyt
so you won't do yourself a dis-service if you want to buy the book but
want to develop later in Pyglet/Rabbyt.

Cheers,
PN

P.S. Since you've likely found Pyglet and PyGame already, the only
other reference URL you need is for Rabbyt so go here for that:
http://matthewmarshall.org/projects/rabbyt/


2008/7/19 Michael Lubker <[EMAIL PROTECTED]>:
> Any people that use Python as the predominant language for their game
> development here?
>
> ~Michael
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Not entirely serious: recursive lambda?

2008-07-19 Thread Michael Tobis
I came across the "japh" concept today and decided to do one of my
own, obviously, interpreting the 'p' somewhat loosely,

http://en.wikipedia.org/wiki/JAPH

but I'm not entirely satisfied with it:


# japh, for certain values of 'p'

f=lambda(r,N):N and f((" acdefijlmnopqrstuv"[N%19]+r,N/19))or(r,N)
print f( ("",reduce(lambda
c,m:c*95+''.join(map(chr,range(32,127))).index(m),
 "!b)'1Mgh0z+fYQ]g::i^<&y~g)cnE-d=K&{GMNQ1gx+ooY<~L##N'X]P2<@XYXwX3z",
0)))[0]



it bothers me that there are two statements. (In case you are
wondering what they do, it's all essentially about changing from base
95 to base 19. It's based loosely on this fine, simple recipe by Drew
Perttula which I have found to be useful on several occasions:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286
)

Anyway, I'd much prefer an even uglier japh like this:

# does not work
print (lambda(r,N):N and ((" acdefijlmnopqrstuv"[N%19]+r,N/
19))or(r,N))(
("",reduce(lambda c,m:c*95+''.join(map(chr,range(32,127))).index(m),
 "!b)'1Mgh0z+fYQ]g::i^<&y~g)cnE-d=K&{GMNQ1gx+ooY<~L##N'X]P2<@XYXwX3z",
0)))[0]

but what would  be for an unnamed function to call itself?

I realize that lambda is something of an orphan and was arguably a bad
idea for anything besides obfuscation, but obfuscation is exactly my
purpose here. Can a lambda call itself without giving itself a name?
Google was not my friend on this one, and I suspect there is no
answer. Relax, I am not going to submit a PEP about it.

mt
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-19 Thread Andrew Freeman

John Machin wrote:

On Jul 20, 5:00 am, Andrew Freeman <[EMAIL PROTECTED]> wrote:
  

Andrew Freeman wrote:


John Machin wrote:
  

A couple of points:
(1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...)
(2) You need to choose your end-anchor correctly; your pattern is
permitting a newline at the end:


I forgot to change search to match. This should be better:

def match(var):
if re.match(r'[LRM]*\Z', var):
return True
else:
return False



A bit wordy ...

if blahblah:
   return True
else:
   return False

can in total generality be replaced by:

return blahblah


  

I was also thinking if you had a list of these items needing to be
verified you could use this:



You could, but I suggest you don't use it in a job interview :-)

  

 >>> l = ['LLMMRR', '00thLL', 'L', '\n']



(1) Don't use 'L'.lower() as a name; it slows down reading as people
need to fire up their mental parser to distinguish it from the result
of 3 - 2

  

 >>> out = []
 >>> map(lambda i: match(i)==False or out.append(i), l)


(2) Read PEP 8
(3) blahblah == False ==> not blahblah
(4) You didn't show the output from map() i.e. something like [None,
True, None, True]
(5) or out.append(...) is a baroque use of a side-effect, and is quite
unnecessary. If you feel inexorably drawn to following the map way,
read up on the filter and reduce functions. Otherwise learn about list
comprehensions and generators.

  

 >>> print out
['LLMMRR', 'L']




Consider this:

  

import re
alist = ['LLMMRR', '00thLL', 'L', '\n']
zeroplusLRM = re.compile(r'[LRM]*\Z').match
filter(zeroplusLRM, alist)


['LLMMRR', 'L']
  

[x for x in alist if zeroplusLRM(x)]


['LLMMRR', 'L']
  


Thank you for the pointers!
(1) Depending on the typeface I totally agree, Courier New has a nearly 
indistinguishable 1 and l, I'm using Dejavu Sans Mono (Bitstream Vera 
based). I was just thinking of it as a generic variable name for some 
input. I'm fairly new to python and programming in general, it's more of 
a hobby.


(2-3) This is actually the first time I've used map, maybe I should not 
give extra examples, I was actually using it as a learning tool for 
myself. I'm very thankful the mailing list has such skilled 
contributers, such as yourself, but I assume that it can't hurt to give 
working code, even though the style is less than perfect.


(3) Personally I think map(lambda i: match(i)==False or out.append(i), 
l) is a little more readable than map(lambda i: not match(i) or 
out.append(i), l) even if "baroque", your use of filter is obviously 
much clearer than either.


(4) I highly doubt that this code was actually to be used in an 
interactive session, the False/True output was truncated intentionally, 
it's an obvious, but superfluous output (unless you were to rely on this 
by attaching it to a variable which might lead to sorting issues).


(5) Thank you very much, I've read of the filter and reduce functions, 
but haven't used them enough to recognize their usefulness.


I did realize that a list comprehension would be useful, but wanted to 
try map()
I put together a generic matcher that returns either a list of True data 
(if the input is a list or tuple) or a boolean value:


def match(ex, var):
   "ex is the regular expression to match for, var the iterable or 
string to return a list of matching items or a boolean value respectively."

   ex = re.compile(ex).match
   if isinstance(var, (list, tuple)):
   return filter(ex, var)
   else:
   return bool(ex(var))

I believe this is fairly clean and succinct code, it would help my 
learning immensely if you feel there is a more succinct, generic way of 
writing this function.

--
Andrew
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-19 Thread Michiel Overtoom
On Saturday 19 July 2008 22:30:29 Dennis Lee Bieber wrote:

>   I still wonder who came up with the Commodore PET -- Personal
> Electronic Transactor... yeesh... But the "Personal" was already in play
> way back then.

Probably Chuck Peddle, Jack Tramiel or Leonard Tramiel.

For your amusement: http://en.wikipedia.org/wiki/PET_2001

Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Vallopillil 
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: __del__ methods

2008-07-19 Thread Ben Finney
"Robert Rawlins" <[EMAIL PROTECTED]> writes:

> What is the benefit of extending the base 'object' class? What does that
> give me that en empty, non subclassed object doesn't?

In Python 2.x, "classic" classes (which are not part of the unified
type hierarchy) are deprecated, and exist only for backward
compatibility with old code.

You need to create "new-style" classes
http://www.python.org/doc/newstyle/> by inheriting from some
class that is part of the unified type hierarchy; if there is no
obvious candidate, 'object' is the recommended choice.

In Python 3.0, classic classes are no longer supported and this issue
goes away.

-- 
 \ Q: “I've heard that Linux causes cancer...” Torvalds: “That's a |
  `\ filthy lie. Besides, it was only in rats and has not been |
_o__)   reproduced in humans.” —Linus Torvalds |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Help Tracing urllib2 Error, Please?

2008-07-19 Thread Larry Hale
Since it seems I have a "unique" problem, I wonder if anyone could
point me in the general/right direction for tracking down the issue
and resolving it myself.

See my prior post @ 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/44775994a6b55161?hl=en#
for more info.  (Python 2.5.2 on Win XP 64 ==>> Squid Proxy requiring
Authentication ==>> Internet not working.)

I've looked the urllib2 source over, but am having trouble following
it.  As previously mentioned, urllib2 initiates the request, Squid
replies "407 error" that auth's required, and then urllib2 just stops,
throwing error 407.

Any though(s) on what to check out?

It's frustrating (to say the least) that it seems so many are
successfully accomplishing this task, and all's working perfectly for
them, but I'm failing miserably.

Would any quotes viewed in the HTTP traffic help?  (Wireshark shows
all!  :)  I don't even know what other info could help.

Any info to get about Squid's configuration that might make it "non
standard" in a way that could cause my problem?  Any question(s) I
should ask my Net Admin to relay info to you all?


As always, any/all help greatly appreciated.  Thanks!  :)

-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Free online computer studies

2008-07-19 Thread Prabhu
Free online computer studies
super visualize study
get all courses,hurry up limited offer
http://vijaydollars.blogspot.com/
http://friendfinder.com/go/g981367
http://amigos.com/go/g981367
--
http://mail.python.org/mailman/listinfo/python-list


Re: checking if an object IS in a list

2008-07-19 Thread John Machin
On Jul 20, 6:13 am, [EMAIL PROTECTED] wrote:
> On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> > On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote:
> > > So, I use something like this in 'sheet.objects.__setattr__(self,
> > > name, value)':
> > > if type(value) == Polygon:
> > > for edge in value.edges:
> > > if edge is_in sheet.objects.__dict__.itervalues():
> > > object.__setattr__(self, self.__new_name(), edge)
>
> > > Ok, I suppose it's confused, but it's difficult to sum up. ;-)
>
> > You are setting attributes with computed names?  How do you access them?
> > Always with `gettattr()` or via the `__dict__`?  If the answer is yes, why
> > don't you put the objects the into a dictionary instead of the extra
> > redirection of an objects `__dict__`?
>
> Yes, I may subclass dict, and change its __getitem__ and __setitem__
> methods, instead of changing objets __setattr__ and __getattr__... But
> I prefer
>
> >>> sheet.objects.A = Point(0, 0)
> than
> >>> sheet.objects["A"] = Point(0, 0)
> > Oh and the `type()` test smells like you are implementing polymorphism
> > in a way that should be replaced by OOP techniques.
>
> I wrote 'type' here by mistake, but I used 'isinstance' in my
> code. ;-)
>
> > If you make Point immutable you might be able to drop the "must not be
>
> referenced twice" requirement.
>
> Yes, but unfortunately I can't (or it would require complete
> redesign...)

(1) You are searching through lists to find float objects by identity,
not by value
(2) Peter says he doesn't understand
(3) Marc thinks it smells

IOW, the indications are that it *already* requires complete redesign.
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex doubts

2008-07-19 Thread John Machin
On Jul 20, 6:35 am, MRAB <[EMAIL PROTECTED]> wrote:
> On Jul 19, 9:12 pm, John Machin <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jul 20, 5:04 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > > Mr SZ wrote:
> > > > I am taking a string as an input from the user and it should only
> > > > contain the chars:L , M or R
>
> > > > I tried the folllowing in kodos but they are still not perfect:
>
> > > > [^A-K,^N-Q,^S-Z,^0-9]
> > > > [L][M][R]
> > > > [LRM]?L?[LRM]? etc but they do not exactly meet what I need.
>
> > > > For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.
>
> > > try "[LRM]+$" (an L or an R or an M, one or more times, all the way to
> > > the end of the string).
>
> > Ummm ... with the default flag settings, shouldn't that be \Z instead
> > of $
> > ?
>
> $ means end of string unless the multiline flag is used, in which case
> it means end of line.

What manual are you quoting that from? What version of Python are you
using? Can you demonstrate that the pattern "[LRM]+$" will fail to
match the string "L\n"?
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-19 Thread John Machin
On Jul 20, 5:00 am, Andrew Freeman <[EMAIL PROTECTED]> wrote:
> Andrew Freeman wrote:
> > John Machin wrote:
> >> A couple of points:
> >> (1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...)
> >> (2) You need to choose your end-anchor correctly; your pattern is
> >> permitting a newline at the end:
>
> I forgot to change search to match. This should be better:
>
> def match(var):
> if re.match(r'[LRM]*\Z', var):
> return True
> else:
> return False

A bit wordy ...

if blahblah:
   return True
else:
   return False

can in total generality be replaced by:

return blahblah


>
> I was also thinking if you had a list of these items needing to be
> verified you could use this:

You could, but I suggest you don't use it in a job interview :-)

>  >>> l = ['LLMMRR', '00thLL', 'L', '\n']

(1) Don't use 'L'.lower() as a name; it slows down reading as people
need to fire up their mental parser to distinguish it from the result
of 3 - 2

>  >>> out = []
>  >>> map(lambda i: match(i)==False or out.append(i), l)
(2) Read PEP 8
(3) blahblah == False ==> not blahblah
(4) You didn't show the output from map() i.e. something like [None,
True, None, True]
(5) or out.append(...) is a baroque use of a side-effect, and is quite
unnecessary. If you feel inexorably drawn to following the map way,
read up on the filter and reduce functions. Otherwise learn about list
comprehensions and generators.

>  >>> print out
> ['LLMMRR', 'L']
>

Consider this:

>>> import re
>>> alist = ['LLMMRR', '00thLL', 'L', '\n']
>>> zeroplusLRM = re.compile(r'[LRM]*\Z').match
>>> filter(zeroplusLRM, alist)
['LLMMRR', 'L']
>>> [x for x in alist if zeroplusLRM(x)]
['LLMMRR', 'L']
>>>

Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: MethodChain

2008-07-19 Thread bearophileHUGS
Marc 'BlackJack' Rintsch:
> What's called `MethodChain` there seems to be function composition in
> functional languages.  Maybe `functools` could grow a `compose()` function.

To me it looks like a quite more "refined" thing, it's an object, it
has some special methods, etc. I think it's not too much difficult to
implement it with Python.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: create instance attributes for every method argument

2008-07-19 Thread Peter Otten
Berco Beute wrote:

> I remember reading somewhere how to create an instance attribute for
> every method argument, but although Google is my friend, I can't seem
> to find it. This could likely be done way more elegant:
> 
> =
> class Test(object):
> 
> def __init__(self, a, b, c, d, e, f):
> self.a = a
> self.b = b
> self.c = c
> self.d = d
> =

http://code.activestate.com/recipes/280381/

Personally, I prefer to spell it out like you did above.

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: create instance attributes for every method argument

2008-07-19 Thread Duncan Booth
Berco Beute <[EMAIL PROTECTED]> wrote:

> I remember reading somewhere how to create an instance attribute for
> every method argument, but although Google is my friend, I can't seem
> to find it. This could likely be done way more elegant:
> 
>=
> class Test(object):
> 
> def __init__(self, a, b, c, d, e, f):
> self.a = a
> self.b = b
> self.c = c
> self.d = d
>=
> 
> 2B

You *could* do something like this:

>>> class Test(object):
def __init__(self, a, b, c, d, e, f):
self.update(locals())

def update(self, adict):
for k in adict:
if k != 'self':
setattr(self, k, adict[k])


>>> c = Test(1, 2, 3, 4, 5, 6)
>>> c.__dict__
{'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'f': 6}
>>> 

but to be honest, your original is much clearer as it expresses the 
intention without any obfuscation and as soon as you want to do anything 
more than simply copying all arguments you'll want to do the assignments 
individually anyway.
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex doubts

2008-07-19 Thread MRAB
On Jul 19, 9:12 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 20, 5:04 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > Mr SZ wrote:
> > > I am taking a string as an input from the user and it should only
> > > contain the chars:L , M or R
>
> > > I tried the folllowing in kodos but they are still not perfect:
>
> > > [^A-K,^N-Q,^S-Z,^0-9]
> > > [L][M][R]
> > > [LRM]?L?[LRM]? etc but they do not exactly meet what I need.
>
> > > For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.
>
> > try "[LRM]+$" (an L or an R or an M, one or more times, all the way to
> > the end of the string).
>
> Ummm ... with the default flag settings, shouldn't that be \Z instead
> of $
> ?

$ means end of string unless the multiline flag is used, in which case
it means end of line.

\Z always means end of string.

Similar remarks apply to ^ and \A.
--
http://mail.python.org/mailman/listinfo/python-list


Re: create instance attributes for every method argument

2008-07-19 Thread Larry Bates

Berco Beute wrote:

I remember reading somewhere how to create an instance attribute for
every method argument, but although Google is my friend, I can't seem
to find it. This could likely be done way more elegant:

=
class Test(object):

def __init__(self, a, b, c, d, e, f):
self.a = a
self.b = b
self.c = c
self.d = d
=

2B


IMHO you can't do much better than that with positional arguments, but you can 
if they are keyword arguments.


class foo(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

-Larry

--
http://mail.python.org/mailman/listinfo/python-list


Re: Determining when a file has finished copying

2008-07-19 Thread Wilbert Berendsen
You could also copy to a different name on the same disk, and when the copying 
has been finished just 'move' (mv) the file to the filename the other 
application expects. E.g. QMail works this way, writing incoming mails in 
folders.

Met vriendelijke groet,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
-- Mahatma Gandhi
--
http://mail.python.org/mailman/listinfo/python-list


Re: checking if an object IS in a list

2008-07-19 Thread nicolas . pourcelot
On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote:
> > So, I use something like this in 'sheet.objects.__setattr__(self,
> > name, value)':
> > if type(value) == Polygon:
> >     for edge in value.edges:
> >         if edge is_in sheet.objects.__dict__.itervalues():
> >             object.__setattr__(self, self.__new_name(), edge)
>
> > Ok, I suppose it's confused, but it's difficult to sum up. ;-)
>
> You are setting attributes with computed names?  How do you access them?
> Always with `gettattr()` or via the `__dict__`?  If the answer is yes, why
> don't you put the objects the into a dictionary instead of the extra
> redirection of an objects `__dict__`?
>

Yes, I may subclass dict, and change its __getitem__ and __setitem__
methods, instead of changing objets __setattr__ and __getattr__... But
I prefer
>>> sheet.objects.A = Point(0, 0)
than
>>> sheet.objects["A"] = Point(0, 0)



> Oh and the `type()` test smells like you are implementing polymorphism
> in a way that should be replaced by OOP techniques.

I wrote 'type' here by mistake, but I used 'isinstance' in my
code. ;-)


> If you make Point immutable you might be able to drop the "must not be
referenced twice" requirement.

Yes, but unfortunately I can't (or it would require complete
redesign...)
--
http://mail.python.org/mailman/listinfo/python-list


Re: regex doubts

2008-07-19 Thread John Machin
On Jul 20, 5:04 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Mr SZ wrote:
> > I am taking a string as an input from the user and it should only
> > contain the chars:L , M or R
>
> > I tried the folllowing in kodos but they are still not perfect:
>
> > [^A-K,^N-Q,^S-Z,^0-9]
> > [L][M][R]
> > [LRM]?L?[LRM]? etc but they do not exactly meet what I need.
>
> > For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.
>
> try "[LRM]+$" (an L or an R or an M, one or more times, all the way to
> the end of the string).

Ummm ... with the default flag settings, shouldn't that be \Z instead
of $
?

--
http://mail.python.org/mailman/listinfo/python-list


Re: win32api not found?

2008-07-19 Thread Fuzzyman
On Jul 19, 8:45 pm, Michiel Overtoom <[EMAIL PROTECTED]> wrote:
> On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote:
>
> > Where can I get the win32api module? I been searching all day on google and
> > nothing, i installed
> >https://sourceforge.net/project/showfiles.php?group_id=78018which requires
> > win32api and its not found...
>

If you have successfully installed the pywin32 extensions then you
*will* be able to import win32api.

What happens if you start the Python interactive interpreter and enter
'import win32api' ?

Michael Foord
http://www.ironpythoninaction.com/


> What are the actions you do and the commands you give, and what is the precise
> error you get?
>
> Greetings,
>
> --
> "The ability of the OSS process to collect and harness
> the collective IQ of thousands of individuals across
> the Internet is simply amazing." - Vinod 
> Vallopillilhttp://www.catb.org/~esr/halloween/halloween4.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: XML Parsing: Expat Error

2008-07-19 Thread Fredrik Lundh

Gerth, William D wrote:

Hey all, I’m simply trying to get my feet wet with XML parsing, and I 
tried to just do something simple with ElementTree, just throw the XML 
tags from a file into a list.  The code is as follows (and may be wrong):


...


xml.parsers.expat.ExpatError: no element found: line 3, column 0

What can I do to fix this, if anything?  My overall goal has been to 
simply get the text of the XML document into a text file, but even that 
has failed (I get naught but gibberish), so any help would be appreciated.


your XML file is broken (note that it's the "parse" function that throws 
this error).




--
http://mail.python.org/mailman/listinfo/python-list


Re: regex doubts

2008-07-19 Thread Fredrik Lundh

Mr SZ wrote:

I am taking a string as an input from the user and it should only 
contain the chars:L , M or R


I tried the folllowing in kodos but they are still not perfect:

[^A-K,^N-Q,^S-Z,^0-9]
[L][M][R]
[LRM]?L?[LRM]? etc but they do not exactly meet what I need.

>

For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.


try "[LRM]+$" (an L or an R or an M, one or more times, all the way to 
the end of the string).




--
http://mail.python.org/mailman/listinfo/python-list


create instance attributes for every method argument

2008-07-19 Thread Berco Beute
I remember reading somewhere how to create an instance attribute for
every method argument, but although Google is my friend, I can't seem
to find it. This could likely be done way more elegant:

=
class Test(object):

def __init__(self, a, b, c, d, e, f):
self.a = a
self.b = b
self.c = c
self.d = d
=

2B
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question on Joining of list

2008-07-19 Thread ptn
On Jul 18, 6:43 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jul 18, 11:42 pm, ptn <[EMAIL PROTECTED]> wrote:
> [snip]
>
> >  Remember C, where i, j,
> > k are indices, p, q, r are pointers, s, t are strings and x, y, z are
> > integers.
>
> Only by convention (even-K&R-v1 C required explicit declarations
> almost everywhere), and x etc being used for integers is news to
> me ... perhaps you were thinking of m and n.
>
> The only language I remember that had implicit typing was FORTRAN (GOD
> is real, but JESUS is an integer).

Yes, I meant by convention.

x is the first name that comes to mind when declaring an unimportant
int.  Perhaps it's just me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> Why is Perl so much better than python?

Smart questions deserve smart answers: Yes.

Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ultimate Prime Sieve -- Sieve Of Zakiya (SoZ)

2008-07-19 Thread jzakiya
On Jun 18, 7:58 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jun 13, 1:12 pm, jzakiya <[EMAIL PROTECTED]> wrote:
>
> > The paper presents benchmarks with Ruby 1.9.0-1 (YARV).  I would love
> > to see my variousprimegenerators benchmarked with optimized
> > implementations in other languages.  I'm hoping Python gurus will do
> > better than I, though the methodology is very very simple, since all I
> > do is additions, multiplications, and array reads/writes.
>
> After playing a little with it, I managed to get a 32-47% improvement
> on average for the pure Python version, and a 230-650% improvement
> with an extra "import psyco; psyco.full()" (pasted 
> athttp://codepad.org/C2nQ8syr)
> The changes are:
>
> - Replaced range() with xrange()
> - Replaced x**2 with x*x
> - Replaced (a,b) = (c,d) with a=c; b=d
> - Replaced generator expressions with list comprehensions. This was
> the big one for letting psyco do its magic.
>
> I also tried adding type declarations and running it through Cython
> but the improvement was much less impressive than Psyco. I'm not a
> Pyrex/Cython expert though so I may have missed something obvious.
>
> George

George,

I took your code and included more efficient/optimized versions of
SoZ versions P3, P5, P7, and P11.

I ran the code on my PCLinuxOS, Intel P4, Python 2.4.3 system and
noted this. The SoZ code run much faster than the SoA in pure Python.
When psyco is used the SoA is significantly faster than the
pure Python version. The SoZ versions are faster too, but now
they are slower than the SoA. You can download the code from


http://www.4shared.com/dir/7467736/97bd7b71/sharing.html

It would be interesting to see how this code runs in newer versions
of Python (Psyco).

FYI, someone else coded P7 in C on a QuadCore Intel 9650 3.67GHz
overclocked cpu, using multiple threads, and got it to be faster
than the SoA, SoE, Here's some of his results (times in seconds).

Case  nPrime7x nPrime7x nPrime7x nPrime7x
 Atkin Zakiya  Eratosthenes Zakiya (8 core
2.5ghz)

100 billion 52.58 44.27 50.56

200 b  110.14 92.38108.99 88.01

300 b  169.81140.92167.47

400 b  232.34190.84228.08177.72

500 b  297.44241.84291.28

600 b  364.84293.92355.27273.04

700 b  434.33346.97420.41

800 b  506.67400.97486.72373.29

900 b  579.58456.53555.09

1 trillion 654.03513.11624.00479.22


Jabari
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32api not found?

2008-07-19 Thread Michiel Overtoom
On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote:

> Where can I get the win32api module? I been searching all day on google and
> nothing, i installed
> https://sourceforge.net/project/showfiles.php?group_id=78018 which requires
> win32api and its not found...

What are the actions you do and the commands you give, and what is the precise 
error you get?

Greetings, 

-- 
"The ability of the OSS process to collect and harness 
the collective IQ of thousands of individuals across 
the Internet is simply amazing." - Vinod Vallopillil 
http://www.catb.org/~esr/halloween/halloween4.html
--
http://mail.python.org/mailman/listinfo/python-list


win32api not found?

2008-07-19 Thread Lamonte Harris
Where can I get the win32api module? I been searching all day on google and
nothing, i installed
https://sourceforge.net/project/showfiles.php?group_id=78018 which requires
win32api and its not found...
--
http://mail.python.org/mailman/listinfo/python-list

Re: How do you check if a program/process is running using python?

2008-07-19 Thread Venky K Shankar
On Sunday 20 July 2008 12:08:49 am Lamonte Harris wrote:
> How do you check if a program or process is running when using python? 
> What I want to do is have an infinite loop to check if a program is running
> or not and send data to my web server to check yes or no.  Is this
> possible? If so how?

you can execute OS system call.

here i execute ps -ef and grep the required process name (or you can grep by 
pid on that particular column using awk)

import os
os.system("ps -ef | grep -v grep | grep ")  

in my system it gives result 0 if the process is running

>>> a = os.system("ps -ef | grep -v grep | grep python")
root  8749  5331  0 Jul19 pts/100:00:00 python
>>> a
0

else gives non 0 :

>>> a = os.system("ps -ef | grep -v grep | grep python123")
>>> a
256

you can check this inside while True:

I am sure there should be a far better solution that this in python.

-Venky
--
http://mail.python.org/mailman/listinfo/python-list


matplotlib: Plotting a graph against time

2008-07-19 Thread Durand
Hi,

I'm trying to plot a simple graph against date or time using matplotlib. I've 
read about date_plot but I'm not really sure how to use it. At the moment, I 
have some data arranged into lists, where list1 contains x values (time) and 
list2 contains y values just like is needed for the normal plot function. The 
time values are simply the output of datetime.date.today(), etc which I don't 
mind changing the format of.

My question is, how do I plot the graph with list1 on the x axis and list2 on 
the y axis. Using plot and unixtime I get a very ugly scale as is to be 
expected so I want to know how to use the date_plot function efficiently. At 
the moment, I'm only concerned about the actual plotting but help with Locater 
Ticks (Months and Years) is also very appreciated.

Thanks a lot!
--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-19 Thread Andrew Freeman

Andrew Freeman wrote:

John Machin wrote:

A couple of points:
(1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...)
(2) You need to choose your end-anchor correctly; your pattern is
permitting a newline at the end:

I forgot to change search to match. This should be better:

def match(var):
   if re.match(r'[LRM]*\Z', var):
   return True
   else:
   return False

I was also thinking if you had a list of these items needing to be 
verified you could use this:

>>> l = ['LLMMRR', '00thLL', 'L', '\n']
>>> out = []
>>> map(lambda i: match(i)==False or out.append(i), l)
>>> print out
['LLMMRR', 'L']

--
Andrew
--
http://mail.python.org/mailman/listinfo/python-list


How do you check if a program/process is running using python?

2008-07-19 Thread Lamonte Harris
How do you check if a program or process is running when using python?  What
I want to do is have an infinite loop to check if a program is running or
not and send data to my web server to check yes or no.  Is this possible? If
so how?
--
http://mail.python.org/mailman/listinfo/python-list

Re: Change PC to Win or Windows

2008-07-19 Thread Duncan Booth
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> On Sat, 19 Jul 2008 11:02:51 -0500, Grant Edwards wrote:
> 
>> On 2008-07-19, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>>
>>> Which term applied to the TRS-80, the Apple II, Altair even...
>> 
>> Not that I remember.  I had a homebrew S-100 bus system, worked
>> with varioius Commodore machines, a few Apples, and some other
>> CP/M systems. I never heard any of them called a 'PC'.  My
>> recollection is that 'PC' was a term that IBM coined.
> 
> The C64 that still sits on my desk has a label on it saying
> “commodore 64 - personal computer”.
> 
and I cut my programming teeth on a Sharp MZ80K personal computer.

http://www.sharpmz.org/mz-80k/images/mz80kade1_1.jpg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python packages?

2008-07-19 Thread Kay Schluehr
On 18 Jul., 12:23, Ben Sizer <[EMAIL PROTECTED]> wrote:
> On Jul 16, 3:31 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > Ben Sizer wrote:
> > > make my development a lot easier.
>
> > Knowing what kind of development you do might help, of course.  Some
> > libraries are excellent in some contexts and suck badly in others...
>
> Sure. Mostly I'm just interested in what's out there though. In C++
> you have Boost which everybody knows are a source of high quality
> libraries, covering a fairly wide set of applications. Obviously
> that's more low-level and less application specific, and the Python
> standard libs do pretty much everything that is in Boost, but it's
> that sort of peer-reviewed and widely-applicable list that I'd like to
> see.
>
> I (attempt to) use TurboGears for web development and that depends on
> a whole bunch of libraries - SQLObject, PyProtocols, RuleDispatch,
> SimpleJson, FormEncode, etc - and I would never have heard of these if
> TurboGears' exposure of its internals wasn't so common. Some of these
> are web-specific but some are not. And I'd never know to look for them
> specificially, because in many cases it wouldn't occur to me that they
> exist. (eg. Object-Relational Mappers like SQLObject may be obvious if
> you come from certain areas of IT, but I'd never heard of them before
> I started with TurboGears.)
>
> For what it's worth, my main areas of interest are gaming, multimedia,
> and web development. But I just like to hear about anything that
> people might use which makes their life a lot easier and which perhaps
> is not application specific - like ORMs or something similar.
>
> > Looking at things that larger projects and distributions use can also be
> > a good idea.  For example, if you're doing scientific stuff, go directly
> > to enthought.com.  If you're doing web stuff, look at the libraries big
> > Django applications use.  Etc.
>
> Sadly, I know just as little about what major applications are out
> there as I do about what libraries are out there!
>
> --
> Ben Sizer

In the original post you asked for "hidden gems" and now it seems you
just want to know about Madonna or Justin Timberlake.

Maybe a look on this collection helps

http://wiki.python.org/moin/UsefulModules
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 11:02:51 -0500, Grant Edwards wrote:

> On 2008-07-19, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>
>> Which term applied to the TRS-80, the Apple II, Altair even...
> 
> Not that I remember.  I had a homebrew S-100 bus system, worked
> with varioius Commodore machines, a few Apples, and some other
> CP/M systems. I never heard any of them called a 'PC'.  My
> recollection is that 'PC' was a term that IBM coined.

The C64 that still sits on my desk has a label on it saying “commodore 64
- personal computer”.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Re: MethodChain

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 08:55:23 -0700, bearophileHUGS wrote:

> Found from Reddit, it's for e ECMA(Java)Script, but something similar
> may be useful for Python too:
> 
> http://jsclass.jcoglan.com/methodchain.html
> http://blog.jcoglan.com/2008/07/16/where-did-all-my-code-go-using-ojay-chains-to-express-yourself-clearly/

What's called `MethodChain` there seems to be function composition in
functional languages.  Maybe `functools` could grow a `compose()` function.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-19 Thread Sebastian Beßler

Grant Edwards schrieb:

Not that I remember.  I had a homebrew S-100 bus system, worked
with varioius Commodore machines,


My C64 has a label that says "Personal Computer" on it.
So a C64 is a PC.

Sebastian
--
http://mail.python.org/mailman/listinfo/python-list


RE: __del__ methods

2008-07-19 Thread Duncan Booth
"Robert Rawlins" <[EMAIL PROTECTED]> wrote:
> I like this idea, I can definitely see the benefits to working with
> this concept. One things I will take this quick opportunity to ask,
> even though it's a little OT:
> 
> What is the benefit of extending the base 'object' class? What does
> that give me that en empty, non subclassed object doesn't?
> 
Habit: certain things (such as properties) don't work properly with
old-style classes, so it is good practice always to use new-style
classes and that way you won't forget to do it when it really does
matter. 

>> You can use gc.get_referrers() to find everything that references a 
>> particular objects and gradually trace backwards until you find the
> problem 
>> reference (it is tricky though as any code which does this needs to
>> ignore 
> 
>> its own references to the object in question).
> 
> Yes, that's a very nice concept and like you say gives you quite a
> nice visual reference of what objects are and aren't being destroyed.
> 
See
http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/394ba5b48f83ebfb/237dc92f3629dd9a#237dc92f3629dd9a
 

for the code (although I seem to remember that there are some problems
with that code so caveat emptor).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-19 Thread Grant Edwards
On 2008-07-19, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Fri, 18 Jul 2008 19:14:43 -0400, Derek Martin <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>> On Fri, Jul 18, 2008 at 03:46:13PM -0700, Joel Teichroeb wrote:
>> > Calling Windows PC seems to be something that Apple did so they would 
>> > not have to directly mention Windows. 
>> 
>> Actually it's something IBM did when they created the IBM PC.  Of
>
>   Bah... PC was short for Personal Computer...

I had never heard PC or "Personal Computer" until the IBM-PC.
Before that, such compturs were called "micro computers"

> Which term applied to the TRS-80, the Apple II, Altair even...

Not that I remember.  I had a homebrew S-100 bus system, worked
with varioius Commodore machines, a few Apples, and some other
CP/M systems. I never heard any of them called a 'PC'.  My
recollection is that 'PC' was a term that IBM coined.

> Being a computer small enough to be single-user ("personal")
> vs a department-wide mini, or company-wide mainframe...

I remember those being called microcomputers.  A "PC" meant an IBM.

-- 
Grant

--
http://mail.python.org/mailman/listinfo/python-list


MethodChain

2008-07-19 Thread bearophileHUGS
Found from Reddit, it's for e ECMA(Java)Script, but something similar
may be useful for Python too:

http://jsclass.jcoglan.com/methodchain.html
http://blog.jcoglan.com/2008/07/16/where-did-all-my-code-go-using-ojay-chains-to-express-yourself-clearly/

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


scanf in python

2008-07-19 Thread André Michel Descombes
Hello,

I often need to parse strings which contain a mix of characters, integers
and floats, the C-language scanf function is very practical for this
purpose.
I've been looking for such a feature and I have been quite surprised to find
that it has been discussed as far back as 2001 but never implemented. The
recommended approach seems to be to use split and then atoi or atof or to
use regex and then atoi and atof. Both approaches seem to be a lot less
natural and much more cumbersome than scanf. If python already has a %
string operator that behaves like printf, why not implement either a %% or
<< string operator to behave like scanf, use could be like the followng:

a, b, c = "%d %f %5c" %% "1 2.0 abcde"

or

a, b, c = "%d %f %5c" << "1 2.0 abcde"

%% is closer to the % operator

<< seems more intuitive

either of this methods seems to me much simpler than:

lst = "1 2;0 abcde".split()
a = int(lst[0])
b = float(lst[1])
c = lst[2]

or even worse when using regular expressions to parse such simple input.

I like python because it is concise and easy to read and I really think it
could use such an operator.

I know this has been discussed before and many times, but all previous
threads I found seem to be dead and I would like to invite further
investigation of this topic.

Best Regards,

André M. Descombes
--
http://mail.python.org/mailman/listinfo/python-list

Re: Question

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 10:27:28 +0100, perl_wizard wrote:

> Why is Perl so much better than python?

You are so much better than python?

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread David M Lemcoe Jr.

Hello [EMAIL PROTECTED],

No language is better than another because Python is not intended for the 
same uses and/or people. 
Your question has no place here.


David

-=___=-
David M Lemcoe Jr.
Roswell, Georgia
http://www.davidlemcoe.com/
[EMAIL PROTECTED]
QRZ: KI4YJL
AIM: lemcoe9
YIM: lemcoe9
GTalk: [EMAIL PROTECTED]
MSN: [EMAIL PROTECTED]
Xfire: shawtylo1
ICQ: 359114839
Alternate e-mail: [EMAIL PROTECTED]
-=___=-


Why is Perl so much better than python?




--
http://mail.python.org/mailman/listinfo/python-list


RE: __del__ methods

2008-07-19 Thread Robert Rawlins
Hi Duncan,

> That sounds like an appropriate use for __del__: it won't matter that it 
> may not be called when your app exits.

Ok, well that's good to know. :-)

> Yes, but there is an easy work-around. If you want to track destruction of

> objects of type C then don't add a __del__ method to the C objects.
Instead 
> create a separate class which does nothing but track it's own desctruction

> and reference that from the class which may be leaking.
>
> >>> class Track(object):
>   def __init__(self, parent):
>   self.parentid = id(parent)
>   self.parenttype = type(parent).__name__
>   def __del__(self):
>   print "Destroyed <%s object at %s>" % (self.parenttype, 
> self.parentid)
>
>   
> >>> class C(object):
>   def __init__(self):
>   self._track = Track(self)
>

I like this idea, I can definitely see the benefits to working with this
concept. One things I will take this quick opportunity to ask, even though
it's a little OT:

What is the benefit of extending the base 'object' class? What does that
give me that en empty, non subclassed object doesn't?

> However you should also consider that __del__ only lets you log when 
> objects are destroyed. Using weak references may be a more useful option
as 
> it will let you track which objects are not being destroyed: you can
easily 
> keep a dictionary of weak references to all existing objects of interest. 
> Check its length periodically to see whether objects are being leaked and 
> then inspect the objects themselves to see which ones have leaked.
>
> You can use gc.get_referrers() to find everything that references a 
> particular objects and gradually trace backwards until you find the
problem 
> reference (it is tricky though as any code which does this needs to ignore

> its own references to the object in question).

Yes, that's a very nice concept and like you say gives you quite a nice
visual reference of what objects are and aren't being destroyed.

Cheers Duncan,

Robert

--
http://mail.python.org/mailman/listinfo/python-list


Re: trying to match a string

2008-07-19 Thread Andrew Freeman

John Machin wrote:

On Jul 19, 12:04 pm, Andrew Freeman <[EMAIL PROTECTED]> wrote:
  

To show if valid:

if re.search(r'^[LRM]*$', 'LM'):
print 'Valid'




A couple of points:
(1) Instead of search(r'^blahblah', ...) use match(r'blahblah', ...)
(2) You need to choose your end-anchor correctly; your pattern is
permitting a newline at the end:

  

re.search(r'^[LRM]*$', 'LM\n')


<_sre.SRE_Match object at 0x00B9E528>
  
--

http://mail.python.org/mailman/listinfo/python-list
  

Thanks for your pointers, however have a question regarding the first:

>>> import re
>>> def my_match(var):# my original
>>> if re.search(r'^[LRM]*$', var):
>>> print 'Valid'
>>> else:
>>> print 'invalid'
>>> def other_match(var):   # your suggestion, I believe
>>> if re.search(r'[LRM]*$', var):
>>> print 'Valid'
>>> else:
>>> print 'Invalid'
>>>
>>> eg = 'LRLRLRLRLM'
>>> fg = 'LRLRLRNL'
>>> my_match(eg)
Valid# correct!
>>> my_match(fg)
Invaild  # correct!
>>>
>>> other_match(eg)
Valid # correct!
>>> other_match(fg)
Vaild # INCORRECT, please explain

I believe other_match was your suggestion; to remove the ^
my_match is just a renamed version of my original function

Point 2:
Yes, I totally agree with you on point 2, let me try to combine my 
knowledge and make a satisfactory function.


>>> def final_match(var):
>>> if re.search(r'^[LRM]*\Z', var): # replace $ with \Z to limit 
newlines

... print 'Valid'
... else:
... print 'Invalid'
>>>  final_match(eg)
Valid
>>> final_match(fg)
Invalid
>>> final_match(eg + '\n')
Invalid

So, in conclusion, is this function satisfactory?

def match(var):
   if re.search(r'^[LRM]*\Z', var):
   print 'Valid'
   else:
   print 'Invalid'
--
Andrew
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with displaying images in CherryPy

2008-07-19 Thread paul

David Lyon schrieb:
...
All I want is a sample configuration file that will allow me to display 
a page with a jpeg on it.



This really should only take a few minutes for somebody who has done 
this in CherryPy before and I would certainly appreciate the assistance 
because it doesn't seem covered in any documentation that i could find.


Whats wrong with this page?
http://www.cherrypy.org/wiki/StaticContent

cheers
 Paul

--
http://mail.python.org/mailman/listinfo/python-list


RE: __del__ methods

2008-07-19 Thread Duncan Booth
"Robert Rawlins" <[EMAIL PROTECTED]> wrote:

> I've just recently (in the past week) started using the __del__ method
> to log class instance destruction so I can keep a track of when
> objects are created and destroyed, in order to help me trace and fix
> memory leaks. 

That sounds like an appropriate use for __del__: it won't matter that it 
may not be called when your app exits.

> 
> Are you saying that on the adverse side to this, __del__ may in fact
> be the CAUSE of a memory leak within my application?

Yes, but there is an easy work-around. If you want to track destruction of 
objects of type C then don't add a __del__ method to the C objects. Instead 
create a separate class which does nothing but track it's own desctruction 
and reference that from the class which may be leaking.

>>> class Track(object):
def __init__(self, parent):
self.parentid = id(parent)
self.parenttype = type(parent).__name__
def __del__(self):
print "Destroyed <%s object at %s>" % (self.parenttype, 
self.parentid)


>>> class C(object):
def __init__(self):
self._track = Track(self)


>>> a = C()
>>> b = C()
>>> a.b = b
>>> b.a = a
>>> del a
>>> del b
>>> gc.collect()
Destroyed 
Destroyed 
19


> If this is the case and __del__ creates such a vulnerability within
> the application, and apparently isn't all that reliable anyway, why is
> it still part of the python platform?
> 
Because it does have a very few cases where it is useful. Tracking memory 
leaks may be one.

However you should also consider that __del__ only lets you log when 
objects are destroyed. Using weak references may be a more useful option as 
it will let you track which objects are not being destroyed: you can easily 
keep a dictionary of weak references to all existing objects of interest. 
Check its length periodically to see whether objects are being leaked and 
then inspect the objects themselves to see which ones have leaked.

You can use gc.get_referrers() to find everything that references a 
particular objects and gradually trace backwards until you find the problem 
reference (it is tricky though as any code which does this needs to ignore 
its own references to the object in question).

--
http://mail.python.org/mailman/listinfo/python-list


regex doubts

2008-07-19 Thread Mr SZ
Hi,

I am taking a string as an input from the user and it should only contain the 
chars:L , M or R

I tried the folllowing in kodos but they are still not perfect:

[^A-K,^N-Q,^S-Z,^0-9]
[L][M][R]
[LRM]?L?[LRM]? etc but they do not exactly meet what I need.

For eg: LRLRLRLRLM is ok but LRLRLRNL is not as it has 'N' .like that.

regards,
SZ

The string may or may not have all the three chars.


" life isn't heavy enough,it flies away and floats far above action"


  Start at the new Yahoo!7 for a better online experience. www.yahoo7.com.au--
http://mail.python.org/mailman/listinfo/python-list

Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-19 Thread Paul Boddie
On 17 Jul, 11:09, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> (and the "stable release" and "much will change" stuff is pure FUD, of
> course.  what competing project will I find if I google your name?)

That's a bit unfair. Maybe the guy was stung by previous experiences
with books and certain other frameworks. It seems to me that the
Django people have been quite cautious with the APIs and with their
own book, but it isn't as if nothing has been changing with respect to
the APIs and the preferred ways of doing things in Django.

And I have to add that books which refer the reader to various Web
sites in order to find out the status of the code, qualifying the
prose with "by the time you read this", don't give a great impression.
I can't say that the book referenced here does that, although short of
a 1.0 release, I find it unlikely that the author could avoid it.

Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-19 Thread Torsten Bronger
Hallöchen!

Bruno Desthuilliers writes:

> Torsten Bronger a écrit :
>
>> [EMAIL PROTECTED] writes:
>>
>>> On 16 juil, 10:35, Stefan Scholl <[EMAIL PROTECTED]> wrote:
>>>
 Dave U. Random <[EMAIL PROTECTED]> wrote:

> http://snipr.com/PracticalDjango

 June 2008 is a bit too early. Django isn't ready.
>>>
>>> Oh, really ? Too bad. But, wait... If Django isn't ready, what's
>>> that framework I've been using for almost three years now, then
>>> ???
>>
>> Before writing sarcastic comments, reading the thread would be
>> really polite.
>
> You may not have notice, but applied to a piece of software,
> "ready" is usually understood as "ready for production use". Which
> Django is, and has been for years now.

Yes, so Stefan used the wrong English word.  The rest of the thread
had already revealed it when you made your statement.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-19 Thread Bruno Desthuilliers

Torsten Bronger a écrit :

Hallöchen!

[EMAIL PROTECTED] writes:


On 16 juil, 10:35, Stefan Scholl <[EMAIL PROTECTED]> wrote:


Dave U. Random <[EMAIL PROTECTED]> wrote:


http://snipr.com/PracticalDjango

June 2008 is a bit too early. Django isn't ready.

Oh, really ? Too bad. But, wait... If Django isn't ready, what's
that framework I've been using for almost three years now, then
???


Before writing sarcastic comments, reading the thread would be
really polite.


You may not have notice, but applied to a piece of software, "ready" is 
usually understood as "ready for production use". Which Django is, and 
has been for years now.


--
http://mail.python.org/mailman/listinfo/python-list


Help with displaying images in CherryPy

2008-07-19 Thread David Lyon

Hi all,

I have a very simple question about configuration under CherryPy - it is 
such a simple one but I have been struggling to find an answer for a few 
days.


All I want is a sample configuration file that will allow me to display 
a page with a jpeg on it.


Whilst there are some examples in the CherryPy examples, they are mixed 
with so many other concepts that it is difficult for me (a newbie) to 
figure it out. None actually show me where to put image files.


This really should only take a few minutes for somebody who has done 
this in CherryPy before and I would certainly appreciate the assistance 
because it doesn't seem covered in any documentation that i could find.


Regards

David




--
http://mail.python.org/mailman/listinfo/python-list


Missing sqlite3.h Error when Building Debug Python -- Windows Vista

2008-07-19 Thread Bev in TX
I am a complete newbie at building Python.  I am trying to build it
under MS Windows Vista (64-bit AMD) with MS VS2005.  I'm doing that
because I need debug libraries, which I did not see in the standard
distribution.

I downloaded the source and found the MSVS8 solution/project files.
However, when I tried to build it I got the following error:

...\python-2.5.2\modules\_sqlite\connection.h(33) : fatal error C1083:
Cannot open include file: 'sqlite3.h': No such file or directory

I searched on the web, and at one place it said I would just need to
download sqlite3.h from sqlite.org.  I looked around there, but I
could not find the source for sqlite 3.3.4.  I went back and reread
the PCbuild8\readme.txt file, and it mentions using the following
command to download the sqlite:

svn export http://svn.python.org/projects/external/sqlite-source-3.3.4

Do I really need to get the whole thing, or will just sqlite3.h
resolve the build problem.  As far as I know, I don't really need
sqlite.  If I do need to execute that svn command, how do I execute
that under MS Windows?

Or is there some other way in which to circumvent this error?

Thanks,
Bev in TX
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread Bruno Desthuilliers

Peter Otten a écrit :

[EMAIL PROTECTED] wrote:


Why is Perl so much better than python?


Because you have the video:

http://mail.python.org/pipermail/python-list/2004-March/253370.html



KEYBOARD !-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: ftdi chip + ctypes + ftd2xx... need help with reading chipid! (now with the right source code!)

2008-07-19 Thread Egor Zindy

Egor Zindy wrote:

Dear List,

This one is way beyond my comprehension skills, I just don't 
understand what I'm doing wrong.


I am trying to read the chipid from an FTDI chip based USB key 
(DLP-D,  http://www.ftdichip.com/Products/EvaluationKits/DLP-D.htm ), 
using:


- the ftd2xx module http://pypi.python.org/pypi/ftd2xx/0.1
- the ftd2xx.dll which comes with the driver install
- the chipid dll (1.1.0) from here: 
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
- a ctypes interface I wrote by hand (only 7 functions to wrap, I 
thought it'd be easy!)


The ftd2xx is used for testing, to open / close the device.

My Problem is that neither of the following two wrapped functions 
(with the exact same arguments) return the right result (full 
chipid.py library attached):


   def FTID_GetDeviceLocationID(DeviceIndex):
   n = DWORD()
   status = ftchipid.FTID_GetDeviceLocationID(DeviceIndex, 
ctypes.byref(n))


   if status != FTID_SUCCESS:
   raise DeviceError,FTID_GetErrorCodeString("EN",status)

   return n.value

   def FTID_GetDeviceChipID(DeviceIndex):
   n = DWORD()
   status = ftchipid.FTID_GetDeviceChipID(DeviceIndex, 
ctypes.byref(n))


   if status != FTID_SUCCESS:
   raise DeviceError,FTID_GetErrorCodeString("EN",status)

   return n.value

* On my machine (XP, 32 bits), if I plug two keys in, I can get the 
device chip id from the device with index=1. The one with index=0 
always gives the message "Invalid device handle."

* I get the wrong location id as well, 0 instead of 0x21...
* the FTID_GetNumDevices function also uses a byref, c_ulong and works.
* FTDI's win32 console example returns the right results (and uses c 
unsigned longs) - available from 
http://www.ftdichip.com/Projects/FTDIChip-ID.htm


Any help appreciated!

Regards,
Egor



#!/usr/bin/env python

"""
A generic chipid library based on ctypes

This module handles most of the functions in FTChipID.dll

PROBLEM:
FTID_GetDeviceLocationID doesn't work...
FTID_GetDeviceChipID doesn't work...
Well, not exactly true.
Works with 2 devices plugged in and for device with id 1.
Does not work for device with id 0... What am I doing wrong?!?!?!?!?!?!

How does it work?

relies on ctypes and ftchipid.dll, was only tested in windows XP
the chipid dll (1.1.0) from here: 
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
for testing, need the the ftd2xx module http://pypi.python.org/pypi/ftd2xx/0.1
and the ftd2xx.dll, which comes with the driver install


The latest version of this file is stored in my google code repository:
http://code.google.com/p/ezwidgets/

Copyright (c) 2008 Egor Zindy <[EMAIL PROTECTED]>

Released under the MIT licence.
"""
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

__author__ = "Egor Zindy <[EMAIL PROTECTED]>"
__copyright__ = "Copyright (c) 2008 Egor Zindy"
__license__ = "MIT"
__version__ = "0.1"
__date= "2008-07-10"
__status__ = "Alpha"

import ctypes
import ctypes.wintypes
import sys

STRING = ctypes.c_char_p

if sys.platform == 'win32':
DWORD = ctypes.wintypes.DWORD
else:
DWORD = ctypes.c_ulong

#calling the dll
ftchipid=ctypes.windll.ftchipid

class DeviceError(Exception):
"""Exception class for status messages"""
def __init__(self, value):
self.value = value

def __str__(self):
return repr(self.value)

def FTID_GetNumDevices():
n = DWORD()
status = ftchipid.FTID_GetNumDevices(ctypes.byref(n))

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return n.value

def FTID_GetDeviceSerialNumber(DeviceIndex):
s = ctypes.create_string_buffer(256)
status = ftchipid.FTID_GetDeviceSerialNumber(DeviceIndex, s, 256)

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return s.value

def FTID_GetDeviceLocationID(DeviceIndex):
n = DWORD()
status = ftchipid.FTID_GetDeviceLocationID(DeviceIndex, ctypes.byref(

ftdi chip + ctypes + ftd2xx... need help with reading chipid!

2008-07-19 Thread Egor Zindy

Dear List,

This one is way beyond my comprehension skills, I just don't understand 
what I'm doing wrong.


I am trying to read the chipid from an FTDI chip based USB key (DLP-D,  
http://www.ftdichip.com/Products/EvaluationKits/DLP-D.htm ), using:


- the ftd2xx module http://pypi.python.org/pypi/ftd2xx/0.1
- the ftd2xx.dll which comes with the driver install
- the chipid dll (1.1.0) from here: 
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
- a ctypes interface I wrote by hand (only 7 functions to wrap, I 
thought it'd be easy!)


The ftd2xx is used for testing, to open / close the device.

My Problem is that neither of the following two wrapped functions (with 
the exact same arguments) return the right result (full chipid.py 
library attached):


  def FTID_GetDeviceLocationID(DeviceIndex):
  n = DWORD()
  status = ftchipid.FTID_GetDeviceLocationID(DeviceIndex, 
ctypes.byref(n))


  if status != FTID_SUCCESS:
  raise DeviceError,FTID_GetErrorCodeString("EN",status)

  return n.value

  def FTID_GetDeviceChipID(DeviceIndex):
  n = DWORD()
  status = ftchipid.FTID_GetDeviceChipID(DeviceIndex, ctypes.byref(n))

  if status != FTID_SUCCESS:
  raise DeviceError,FTID_GetErrorCodeString("EN",status)

  return n.value

* On my machine (XP, 32 bits), if I plug two keys in, I can get the 
device chip id from the device with index=1. The one with index=0 always 
gives the message "Invalid device handle."

* I get the wrong location id as well, 0 instead of 0x21...
* the FTID_GetNumDevices function also uses a byref, c_ulong and works.
* FTDI's win32 console example returns the right results (and uses c 
unsigned longs) - available from 
http://www.ftdichip.com/Projects/FTDIChip-ID.htm


Any help appreciated!

Regards,
Egor

#-
#
#Encoder card device driver module
#
#-
#
#Revision History.
#
#V1.020031023 first module (translated from the VB header file)
#
#-
# XXX Make use of python exceptions?

import ctypes
import ctypes.wintypes
import sys

STRING = ctypes.c_char_p

if sys.platform == 'win32':
DWORD = ctypes.wintypes.DWORD
else:
DWORD = ctypes.c_ulong

#calling the dll
ftchipid=ctypes.windll.ftchipid

class DeviceError(Exception):
"""Exception class for status messages"""
def __init__(self, value):
self.value = value

def __str__(self):
return repr(self.value)

def FTID_GetNumDevices():
arg1 = DWORD()
status = ftchipid.FTID_GetNumDevices(ctypes.byref(arg1))

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg1.value

def FTID_GetDeviceSerialNumber(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = ctypes.create_string_buffer(256)
arg3 = DWORD(256)

status = ftchipid.FTID_GetDeviceSerialNumber(arg1, arg2, arg3)

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg2.value

def FTID_GetDeviceLocationID(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = DWORD()

status = ftchipid.FTID_GetDeviceLocationID(arg1, ctypes.byref(arg2))

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg2.value

def FTID_GetDeviceChipID(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = DWORD()

status = ftchipid.FTID_GetDeviceChipID(ctypes.c_long(0), ctypes.byref(arg2))

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg2.value

def FTID_GetDeviceDescription(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = ctypes.create_string_buffer(256)
arg3 = DWORD(256)

status = ftchipid.FTID_GetDeviceDescription(arg1, arg2, arg3)

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg2.value

def FTID_GetDllVersion():
arg1 = ctypes.create_string_buffer(256)
arg2 = DWORD(256)

status = ftchipid.FTID_GetDllVersion(arg1, arg2)

if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)

return arg1.value 

def FTID_GetErrorCodeString(lpLanguage, ErrorCode):
arg1 = STRING(lpLanguage)
arg2 = DWORD(ErrorCode)
arg3 = ctypes.create_string_buffer(256)
arg4 = DWORD(256)
status = ftchipid.FTID_GetErrorCodeString(arg1,arg2,arg3,arg4)
return arg3.value

#ChipID returns...
FTID_SUCCESS = 0
FTID_INVALID_HANDLE = 1
FTID_DEVICE_NOT_FOUND = 2
FTID_DEVICE_NOT_OPENED = 3
FTID_IO_ERROR = 4
FTID_INSUFFICIENT_RESOURCES = 5

FTID_BUFER_SIZE_TOO_SMALL = 20
FTID_PASSED_NULL_POINTER = 21
FTID_INVALID_LANGUAGE_CODE = 22
FTID_INVALID_STATUS_CODE = 0x

if __name__ == '__main__':
import ftd2xx
#test things...
device = ftd2xx

Re: How to process a very large (4Gb) tarfile from python?

2008-07-19 Thread Lars Gustäbel
On Thu, Jul 17, 2008 at 11:41:50PM -0700, Uwe Schmitt wrote:
> On 17 Jul., 22:21, Lars Gustäbel <[EMAIL PROTECTED]> wrote:
> >
> > > Maybe we should post this issue to python-dev mailing list.
> > > Parsing large tar-files is not uncommon.
> >
> > This issue is known and was fixed for Python 3.0, 
> > seehttp://bugs.python.org/issue2058.
> 
> The proposed patch does not avoid caching the previous values of the
> iterator, it just reduces the size of each cached object.
> It would be nice to be able to avoid caching on demand, which would
> make iteration independent of the size of the tar file.

The size of the archive doesn't matter, it's the number of members. And I
wouldn't call it caching either. The members are stored in order to have a
table of contents and to allow random access. Also, the members list is
required for resolving hard links within the archive. It cannot be dropped
without side-effects.

-- 
Lars Gustäbel
[EMAIL PROTECTED]

Those who would give up essential liberty, to purchase a little
temporary safety, deserve neither liberty nor safety.
(Benjamin Franklin)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread Venky K Shankar
On Saturday 19 July 2008 03:14:20 pm Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
> > Why is Perl so much better than python?
>
> Because you have the video:
>
> http://mail.python.org/pipermail/python-list/2004-March/253370.html

>> what about this ? i feel python's better :)
>> http://www.monstersandcritics.com/people/news/article_1339060.php
>
> --
> http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list

Re: Rotating a cube

2008-07-19 Thread David Lyon

Lie wrote:

On Jul 17, 3:11 pm, J-Burns <[EMAIL PROTECTED]> wrote:
  

On Jul 17, 12:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:



J-Burns wrote:
  

Is there a built in Python function for this?


for answering questions that have nothing to do with programming, and
looks quite a bit like homework?  don't think they've added that one yet.
  
maybe you should look for a geometry newsgroup/forum?
  

  

I meant to ask how would you do this in Python... :S



The same as you do it in any other languages. This question is marked
correctly as having no relationship to python whatsoever. You'd get a
better answer if you asked in mathematics/geometry group, many
mathematician are adept programmer as well.
-


But is the question about display graphics ?

ie rotating a cube using a python framework ?

With something like python and OpenGL ? or Python and PovRay... or 
perphaps python and imagemagick ?


If so... i would have thought he should be able to ask that question 
here


David


--
http://mail.python.org/mailman/listinfo/python-list

Re: Change PC to Win or Windows

2008-07-19 Thread Lie
On Jul 19, 6:14 am, Derek Martin <[EMAIL PROTECTED]> wrote:
> On Fri, Jul 18, 2008 at 03:46:13PM -0700, Joel Teichroeb wrote:
> > Calling Windows PC seems to be something that Apple did so they would
> > not have to directly mention Windows.
>
> Actually it's something IBM did when they created the IBM PC.  Of
> course, all IBM PCs ran MS-DOS, since that's how IBM sold them...
> Then others started to build copies the IBM PC based on Intel
> hardware, and the resulting class of computers was called,
> collectively, "PC Clones" -- shortened to PCs -- by the industry and
> its market.  Then companies like AMD and Cyrix started building
> Intel-compatible CPUs, and the term PC was extended to include systems
> built using those architectures.  Eventually Windows was released, and
> PCs became Windows boxen running on Intel-compatible hardware, and I
> personally know no one who doesn't use the term that way...
>
> Much like the English word "bank" (and numerous others), the term "PC"
> has come to have several meanings, one of which is the above.  You may
> not like it, but we're pretty much stuck with the term, so you may as
> well get used to it.
>
> --
> Derek D. Martinhttp://www.pizzashack.org/
> GPG Key ID: 0x81CFE75D
>
>  application_pgp-signature_part
> 1KDownload

That's not the point, PC is personal computer, a computer that is
owned personally, instead of being owned by a department, a company, a
government, etc. IBM PC is one of the first computers that ordinary
people could possess, when IBM-clones appeared on the market, they're
referred as PCs too because they are Personal Computer, a computer
that is designed for personal use. The brand of the computer, the type
of processors, Operating System, etc doesn't qualify a computer as PC
or not-PC, what qualify a computer as a PC is its design and marketing
and popular usage. Design: a computer that is designed to be small,
cheap, and easy-to-use to be owned personally. Marketing: how the
computer is marketed as, the marketing people generally follows the
designer on what to mark a computer as. Popular Usage: What the people
who bought the computer used it for, this generally follows the
marketing terms used on the computer.

In short, Apple's computers (Mac, OSX) are PC too, and is not less PC
than any other PCs. In fact any computers owned and used by a person
(instead of a group of persons) is a personal computer. This way
saying windows-based computer as PC is correct, however badmouthing PC
while advertising itself is the same as badmouthing itself in its own
advertisement.

In a more programming term:

class PC(object):
def who(self):
print('I am a PC')

class IBMPC(PC):
def who(self):
super(IBMPC, self).who()
print 'My brand is IBM'

class Windows(PC):
def who(self):
super(Windows, self).who()
print 'My OS is Windows'

class Mac(PC):
def who(self):
super(Mac, self).who()

# denies thyself
print 'but I do not want to be called as PC'

print 'My OS is Mac'

Apple is an ungrateful son (http://en.wikipedia.org/wiki/
Malin_Kundang ). May they turns back to realize themselves before they
turned into a stone.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2008-07-19 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Why is Perl so much better than python?

Because you have the video:

http://mail.python.org/pipermail/python-list/2004-March/253370.html

--
http://mail.python.org/mailman/listinfo/python-list


RE: __del__ methods

2008-07-19 Thread Robert Rawlins
> Yes.
>
> "Objects that have __del__() methods and are part of a reference cycle
> cause the entire reference cycle to be uncollectable, including
> objects not necessarily in the cycle but reachable only from it.
> Python doesn't collect such cycles automatically because, in general,
> it isn't possible for Python to guess a safe order in which to run the
> __del__() methods."
>
> The uncollectable objects are stored in gc.garbage and will not be
> freed until their reference cycles are broken and they are removed
> from that list.

Ok, guys,

I've just recently (in the past week) started using the __del__ method to
log class instance destruction so I can keep a track of when objects are
created and destroyed, in order to help me trace and fix memory leaks.

Are you saying that on the adverse side to this, __del__ may in fact be the
CAUSE of a memory leak within my application?

If this is the case and __del__ creates such a vulnerability within the
application, and apparently isn't all that reliable anyway, why is it still
part of the python platform?

Cheers,

Robert

--
http://mail.python.org/mailman/listinfo/python-list


Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-19 Thread Stefan Scholl
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> (and the "stable release" and "much will change" stuff is pure FUD, of 
> course.  what competing project will I find if I google your name?)

Found something? Maybe this could help me to choose a web
framework.


-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
--
http://mail.python.org/mailman/listinfo/python-list


Question

2008-07-19 Thread perl_wizard
Why is Perl so much better than python?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Rotating a cube

2008-07-19 Thread Lie
On Jul 17, 3:11 pm, J-Burns <[EMAIL PROTECTED]> wrote:
> On Jul 17, 12:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> > J-Burns wrote:
> > > Is there a built in Python function for this?
>
> > for answering questions that have nothing to do with programming, and
> > looks quite a bit like homework?  don't think they've added that one yet.
>
> > maybe you should look for a geometry newsgroup/forum?
>
> > 
>
> I meant to ask how would you do this in Python... :S

The same as you do it in any other languages. This question is marked
correctly as having no relationship to python whatsoever. You'd get a
better answer if you asked in mathematics/geometry group, many
mathematician are adept programmer as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python packages?

2008-07-19 Thread Iain King
On Jul 19, 8:56 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Iain King wrote:
> > Well, if you're looking for a list of excellent 3rd party Python
> > libraries, then I can give you the ones I like and use a lot:
> [...]
> > BeautifulSoup : for real-world (i.e. not-at-all-recommendation-
> > compliant) HTML processing
>
> You forgot lxml.html, which is much faster, more memory friendly and more
> feature-rich than BS.
>
> Stefan

Never heard of it :)

Iain
--
http://mail.python.org/mailman/listinfo/python-list


Your win 10, 000$ in my groups Pls register your name and address in below of the website http://www.geocities.com/cathrina39 http://namithawithyou.blogspot.com/

2008-07-19 Thread hot rathi
Your win 10,000$ in my groups


Pls register your  name and address
in below of the website


http://www.geocities.com/cathrina39


http://namithawithyou.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Python packages?

2008-07-19 Thread Stefan Behnel
Iain King wrote:
> Well, if you're looking for a list of excellent 3rd party Python
> libraries, then I can give you the ones I like and use a lot:
[...]
> BeautifulSoup : for real-world (i.e. not-at-all-recommendation-
> compliant) HTML processing

You forgot lxml.html, which is much faster, more memory friendly and more
feature-rich than BS.

Stefan
--
http://mail.python.org/mailman/listinfo/python-list


Buy/sell/trade your used stuff and promote your small business to people in california

2008-07-19 Thread busybeejoe
Buy/sell/trade your used stuff and promote your small business to
people in california

I created a NEW forum where you can buy/sell/trade your used stuff
and for small business owners to
promote their services to others in their area...
Its a simple and easy way to let everyone know about your
company and services you offerand its free to join
http://www.yansbb.com/
--
http://mail.python.org/mailman/listinfo/python-list