Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread D'Arcy J.M. Cain
On Wed, 12 Dec 2012 17:44:24 +1100
Chris Angelico  wrote:
> On Wed, Dec 12, 2012 at 5:34 PM, Steven D'Aprano
>  wrote:
> > and you consider this "not productive, not worth my time". Code
> > review with you must be *all* sorts of fun.
> 
> He never asked for code review :)

I think by posting it he sort of did.  He should probably grow a
thicker skin before he does so again though.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
IM: da...@vex.net
-- 
http://mail.python.org/mailman/listinfo/python-list


The Prototype Master

2012-12-12 Thread Bart Thate
*PROTOTYPE MASTER*

they call me the prototype master over here. I dive into the unkown and get
some code working in a problem domain i dont know. As fast as possible i
need to write code that 1) is running 2) does something in that domain

This all so i can learn from all that went wrong. so i can see where my not
knowing the problem domain leads me too.

Thing is i have been prototyping in my domain for more than 10 years now.
Bots are what i have been doing all that time, recycling version after
version, name after name, trying to improving stuff, most of the time
meaning dropping too much code and spending waay to much time to add the
functionality back in.

So no sorry still no unittests yet ;] I promised i test the core first, but
if i don't know  what the core is going to look like, it is no use of
testing - yet -
I do have a ./bin/life-test in the git repo know that can launch unittests,
but i need to go forward to have at least the IRC bot running.

So here is version 3 of the  L I F E ;]

It does run a IRC bot, but only primary functionality is there, connect and
join a channel and do some commands. The console bot seems more stable now,
as is the zero-key stuff. All hopes though can only test stuff here for
myself, looks good so far as in "easy_install3 -U life" works here.

try something like ";start irc #channel"
 in the console. basically the thing is forming into a framework with 1 top
heay base class and in object typeing for easier conversions, ummm yeaah
well ;]

And then there is the issue of colors.. My deep apology to those who have
been using shell and IRC from the earlier days, i just need to have my
colors in my shell ;] For me it makes the output more parsable.

So wrap up, target of one release a week seems to work, still need to start
my massive unittest stuff, but it seems core is progressing well.

Do take note though:

 'Development Status :: 2 - Pre-Alpha',



https://github.com/feedbackflow/life

http://pypi.python.org/pypi/life/3
-- 
http://mail.python.org/mailman/listinfo/python-list


Error .. Please Help

2012-12-12 Thread inshu chauhan
In this code :

import cv
g = open("PointCloudmitClass.txt", "w")
image = cv.LoadImageM("Z:/modules/intensity_01.tif",
cv.CV_LOAD_IMAGE_UNCHANGED)
print image
for y in xrange(0,image.height):
for x in xrange(0,image.width):
color = image[y,x]
if color == (0.0,0.0,0.0):
continue
else :

if color == (0.0,255.0,0.0):
classification = 1
elif color == (128.0, 0.0, 255.0):
classification = 2
elif color == (255.0,0.0,0.0):
classification = 3
elif color == (128.0, 128.0, 128.0):
classification = 4
elif color == (128.0, 64.0, 0.0):
classification = 5
elif color == (0.0, 0.0, 255.0):
classification = 6
elif color == (255.0, 0.0, 255.0):
classification = 7

print >> g, x , y , color, classification


I am getting the following error..

Traceback (most recent call last):
  File "Z:\modules\Get_Classification.py", line 27, in 
print >> g, x , y , color, classification
NameError: name 'classification' is not defined

Its simple error of name but m not getting why it should come as I have
already defined Classification in between if-else loop ??

Thanks in Advance !!!


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


Re: Error .. Please Help

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 2:00 AM, inshu chauhan  wrote:
> In this code :
>
> import cv
> if color == (0.0,255.0,0.0):
> classification = 1
> ...
> elif color == (255.0, 0.0, 255.0):
> classification = 7
>
> print >> g, x , y , color, classification
>

What happens if the color isn't one of the ones you picked? You may
need an 'else' clause on your if/elif/elif block, and some
classification value meaning "other".

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


Re: forking and avoiding zombies!

2012-12-12 Thread Nobody
On Tue, 11 Dec 2012 13:25:36 +, andrea crotti wrote:

> But actually why do I need to move away from the current directory of the
> parent process?

It's not required, it's just "best practice".

Often, the current directory is simply whichever directory it happened to
inherit from the shell which spawned it. So long as that directory
continues to be used as the daemon's current directory, the filesystem
on which it resides cannot be unmounted. So daemons normally change to the
root directory (or to some other directory, e.g. one which they actually
need to use) in order to "release" the directory from which they were
initially started.

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


Re: Error .. Please Help

2012-12-12 Thread Dave Angel
On 12/12/2012 10:00 AM, inshu chauhan wrote:
> In this code :
>
> import cv
> g = open("PointCloudmitClass.txt", "w")
> image = cv.LoadImageM("Z:/modules/intensity_01.tif",
> cv.CV_LOAD_IMAGE_UNCHANGED)
> print image
> for y in xrange(0,image.height):
> for x in xrange(0,image.width):
> color = image[y,x]
> if color == (0.0,0.0,0.0):
> continue
> else :
>
> if color == (0.0,255.0,0.0):
> classification = 1
> elif color == (128.0, 0.0, 255.0):
> classification = 2
> elif color == (255.0,0.0,0.0):
> classification = 3
> elif color == (128.0, 128.0, 128.0):
> classification = 4
> elif color == (128.0, 64.0, 0.0):
> classification = 5
> elif color == (0.0, 0.0, 255.0):
> classification = 6
> elif color == (255.0, 0.0, 255.0):
> classification = 7
>
> print >> g, x , y , color, classification
>
>
> I am getting the following error..
>
> Traceback (most recent call last):
>   File "Z:\modules\Get_Classification.py", line 27, in 
> print >> g, x , y , color, classification
> NameError: name 'classification' is not defined
>
> Its simple error of name but m not getting why it should come as I have
> already defined Classification in between if-else loop ??
>
if-else doesn't define a loop, but each of the for statements do.

You have defined a classification for 8 of the possible colors, leaving
millions of them undefined.  If the first time through the loop you
manage to hit one of those undefined ones, you'll have no value for
classification.  So you get an exception.

Worse, if you manage to get past that first pixel with a valid
classification, then for remaining pixels, you'll be using the last
'valid' classification encountered.  This is the kind of "quiet failure"
that programmers dread.  Something that seems to work, but isn't even close.

If you're going to print (to file) on each iteration through the loop
(except 0,0,0), you need to make sure there's always a valid value.  So
you need at least one more classification value, and an else clause to
assign it, as ChrisA pointed out.

Do you have a reason for treating (0,0,0) specially?  When that value is
seen, the logic skips the print as well, since continue skips to the
next loop iteration.

Are you really getting floating point values, or are they always going
to be equal to an integer?  Those if/elif statements might be a problem
if you ever need to compare to a value like (128.4, 255.0, 255.0).

-- 

DaveA

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


Re: Error .. Please Help

2012-12-12 Thread Ulrich Eckhardt

Am 12.12.2012 16:00, schrieb inshu chauhan:

 color = image[y,x]
 if color == (0.0,0.0,0.0):
 continue
 else :
 if color == (0.0,255.0,0.0):
 classification = 1
 elif color == (128.0, 0.0, 255.0):
 classification = 2
 elif color == (255.0,0.0,0.0):
 classification = 3
 elif color == (128.0, 128.0, 128.0):
 classification = 4
 elif color == (128.0, 64.0, 0.0):
 classification = 5
 elif color == (0.0, 0.0, 255.0):
 classification = 6
 elif color == (255.0, 0.0, 255.0):
 classification = 7



Use a dict for this, it probably makes things clearer. Something like:

  cclasses = {(  0.0,   0.0,   0.0): None,
  (  0.0, 255.0,   0.0): 1,
  (128.0,   0.0, 255.0): 2, }

  if cclasses[color] is not None:
  print >> g, x , y , color, cclasses[color]


Some notes:
 * Some people (and I think PEP8) frown upon the table formatting of 
the dict.
 * d[color] will raise an exception if there is no mapping, but it's 
not clear what you want to do with those inputs anyway.
 * Comparing floating-point values for equality is always a bit tricky, 
as most operations have some rounding. This could mean that you need to 
use ranges instead of fixed values. A good approach is to round the 
input to integral values first.
 * Are you sure that the input uses floating point values but uses 
typical 8-bit ranges 0-255? I would expect floating point values between 
0 and 1 or integral values between 0 and 255, but not such a mixture.
 * Try g.write('{} {} {} {}\n'.format(x, y, color, classification)) to 
get code that you will be able to reuse in Python 3. Also, consider 
upgrading anyway.




I am getting the following error..

Traceback (most recent call last):
   File "Z:\modules\Get_Classification.py", line 27, in 
 print >> g, x , y , color, classification
NameError: name 'classification' is not defined

Its simple error of name but m not getting why it should come as I have
already defined Classification in between if-else loop ??


One comment here: If you don't define "classification" in this loop 
iteration, the one from the previous iteration will be used. 
Effectively, this tells me that the first pixel unequal to (0,0,0) 
already doesn't fit your expectations. Use "import pdb" and 
"pdb.set_trace()" to get into debugging mode, which is a useful skill 
anyway.


Good luck!

Uli


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


Re: problem with usbtmc-communication

2012-12-12 Thread Jean Dubois
On 12 dec, 01:49, Jerry Hill  wrote:
> On Tue, Dec 11, 2012 at 1:58 AM, Jean Dubois  wrote:
>
> > I found examples in theusbtmckernel driver documentation (the
> > examples there are given in C):
> >http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?&cc=BE&l...
>
> Thanks for that link.  I think it explains how the driver works pretty
> well.  I haven't done any work with devices like this, but I see a few
> things in those docs that might help.
>
> In their example code, they open the device with: open(“/dev/usbtmc1”,O_RDWR);
>
> That's not exactly the same as what you've been doing.  I would try
> opening the file this way in python:
> usb_device = open('/dev/usbtmc1', 'w+', buffering=0)
>
> That truncates the file after it opening it, and disables any
> buffering that might be going on.
>
> Then, I would try writing to the device with usb_device.write() and
> usb_device.read().  read() attempts to read to end-of-file, and based
> on the docs, the driver will work okay that way.  Doing that, along
> with turning off buffering when you open the file, should eliminate
> any issues with the driver failing to emit newlines someplace.
>
> Personally, I would probably try playing with the device from python's
> interactive interpreter.  I think that could shed a lot of light on
> the behavior you're seeing.
>
> --
> Jerry

Thanks a thousand times Jerry!!!, the buffering issue has disappeared
after following your recommendations. The test program now looks like
below and performs as expected.

#!/usr/bin/python
import time
import os
import sys
timesleepdefault=5
print "Enter name of data file",
filename = raw_input()
#the following line is very important, especially the buffering=0
usbkeith = open('/dev/usbtmc1','w+', buffering=0)
usbkeith.write("*IDN?\n")
identification=usbkeith.read().strip()
print 'Found device: ',identification
usbkeith.write("SYST:REM" + "\n")
usbkeith.write(":SENS:VOLT:PROT 1.5\n")
keithdata = open(filename,'w')
usbkeith.write(":OUTP:STAT ON\n")
for number, current_in in enumerate(('0.025', '0.050', '0.075',
'0.100'), 1):
   usbkeith.write(":SOUR:CURR %s\n" % current_in)
   time.sleep(timesleepdefault)
   usbkeith.write(":MEAS:CURR?\n")
   measurementcurr=usbkeith.read()
   print 'Measured current %d: ' % number, measurementcurr
   usbkeith.write(":MEAS:VOLT?\n")
   measurementvolt=usbkeith.read()
   print 'Measured voltage %d: ' % number, measurementvolt
   keithdata.write(measurementcurr.strip()+' '+measurementvolt)
usbkeith.write(":OUTP:STAT OFF\n")
print "Goodbye, data logged in file:"
print filename
usbkeith.close()
keithdata.close()

regards,
Jean
-- 
http://mail.python.org/mailman/listinfo/python-list


Hollow square program

2012-12-12 Thread siimnurges
Hey, I need to write a program that prints out a square, which is empty on the 
inside. So far, I've made a program that outputs a square, which is full on the 
inside.
P.S. Between every asterisk there needs to be a space(" ")
Here's my code:

print("Rows: ")
rows = int(input())
for i in range(rows):
for j in range(rows):
print("* ", end="")
print("")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hollow square program

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 3:48 AM,   wrote:
> Hey, I need to write a program that prints out a square, which is empty on 
> the inside. So far, I've made a program that outputs a square, which is full 
> on the inside.
> P.S. Between every asterisk there needs to be a space(" ")
> Here's my code:
>
> print("Rows: ")
> rows = int(input())
> for i in range(rows):
> for j in range(rows):
> print("* ", end="")
> print("")

You're going to need some kind of special handling of the beginning
and end of each row, except for the first and last rows. Since you
have i and j counting up from 0 to (rows-1), you can do this by simply
checking those two variables and then decide whether to print out a
star or a space (or, since there's spaces after the stars, whether to
print out a star and a space or two spaces).

Since you're being taught loops, I'm confident your course will have
already taught you how to make a decision in your code. It's another
Python statement.

Next time, by the way, you may want to explicitly state that this is
part of a course you're studying. Otherwise, you may come across as
sneakily trying to cheat your way through the course, which I'm sure
you would never do, would you? :) We're happy to provide hints to help
you understand Python, but not to simply give you the code (and if
anybody does, I hope you have the integrity, and desire to learn, to
ignore that post and work it out for yourself).

Have fun!

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


Re: Hollow square program

2012-12-12 Thread Mitya Sirenef

On 12/12/2012 11:48 AM, siimnur...@gmail.com wrote:
Hey, I need to write a program  that prints out a square, which is empty on the inside. So far, I've 

made a program that outputs a square, which is full on the inside.
> P.S. Between every asterisk there needs to be a space(" ")
> Here's my code:
>
> print("Rows: ")
> rows = int(input())
> for i in range(rows):
> for j in range(rows):
> print("* ", end="")
> print("")


Small note: print("") is the same as print()

The general idea is: make a string that represents top/bottom of the
square, make a string for the middle part, print out the first string,
then print out middle part n-2 times, then print out first string again.

Did you know you can multiply strings? e.g.:

space  = ' '
border = '*'
line   = border + space*70

 -m

--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: Hollow square program

2012-12-12 Thread siimnurges
Well, I did some modifications and got a hollow square, but the columns aren't 
perfectly aligned with the rows (at least if input is 5. Thanks for the help :)

rows = int(input())
s1="* "*rows
s2="*"+(rows-2)*" "+"*"
print(s1)
for s in range(rows-2):
print(s2)
print(s1)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hollow square program

2012-12-12 Thread siimnurges
Well, I did some modifications, but the columns aren't perfectly aligned with 
the rows. 

rows = int(input())
s1="* "*rows
s2="*"+(rows-2)*" "+"*"
print(s1)
for s in range(rows-2):
print(s2)
print(s1) 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JSON logging ?

2012-12-12 Thread Chris Rebert
On Dec 11, 2012 7:33 AM, "Bart Thate"  wrote:

> pickle uses eval still ? or is is considered safe now ? i was told not to
use eval() stuff on data.

I don't believe pickle uses eval() per se, but per the red warning box in
its docs, it's still not safe when given untrusted input. IIRC, among other
things, in order to unpickle non-built-in classes, it is capable of
performing imports; this feature is rife for abuse by an adversary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hollow square program

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 10:22 AM,   wrote:
> Well, I did some modifications and got a hollow square, but the columns 
> aren't perfectly aligned with the rows (at least if input is 5. Thanks for 
> the help :)
>
> rows = int(input())
> s1="* "*rows
> s2="*"+(rows-2)*" "+"*"
> print(s1)
> for s in range(rows-2):
> print(s2)
> print(s1)

The (rows-2)*" " in s2 is only enough spaces to account for the
(rows-2) inner * characters in s1.  You also need additional spaces in
s2 to match up with for the (rows-1) space characters in between the *
characters in s1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hollow square program

2012-12-12 Thread Peter Otten
siimnur...@gmail.com wrote:

> Well, I did some modifications and got a hollow square, but the columns
> aren't perfectly aligned with the rows (at least if input is 5. Thanks for
> the help :)
> 
> rows = int(input())
> s1="* "*rows
> s2="*"+(rows-2)*" "+"*"
> print(s1)
> for s in range(rows-2):
> print(s2)
> print(s1)

The first and last row have an extra space between the asterisks. For the 
square to look like a square you need to add these to the other rows (and 
thus s2), too.

Also note that your code prints a minimum of two rows.

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


How to import module whose filename starts number

2012-12-12 Thread Yong Hu
I have a few scripts whose file names start with numbers. For example, 
01_step1.py, 02_step2.py

I tried to import them in another script by "import 01_step1" or "from 01_step1 
import *". Both failed, saying "SyntaxError: invalid syntax"

Is there anyway to import those files? The file name must start with characters?
-- 
http://mail.python.org/mailman/listinfo/python-list


samba 4 release

2012-12-12 Thread peter

Hellou.

   Samba4 first release, with python interface for the internals api, 
and a implementation of the DC in python :).


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


Re: Hollow square program

2012-12-12 Thread siimnurges
Thanks, got it now :)

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


Re: samba 4 release

2012-12-12 Thread peter

On 12/12/2012 02:38 PM, peter wrote:

Hellou.

   Samba4 first release, with python interface for the internals api, 
and a implementation of the DC in python :).


Viva la python

I forgot to put the link of the good news

https://www.samba.org/samba/history/samba-4.0.0.html

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


Re: How to import module whose filename starts number

2012-12-12 Thread Dave Angel
On 12/12/2012 12:42 PM, Yong Hu wrote:
> I have a few scripts whose file names start with numbers. For example, 
> 01_step1.py, 02_step2.py
>
> I tried to import them in another script by "import 01_step1" or "from 
> 01_step1 import *". Both failed, saying "SyntaxError: invalid syntax"
>
> Is there anyway to import those files? The file name must start with 
> characters?

A module name is like any other symbol in Python.  It must start with a
letter (one of a hundred thousand or so), and have only letters or
digits within it.  Plus underscore, and maybe a couple more special
characters.

mv would be your best bet.  But if you HAVE to have a strange name, try
using the __import__() function.



-- 

DaveA

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


Re: How to import module whose filename starts number

2012-12-12 Thread Peter Otten
Yong Hu wrote:

> I have a few scripts whose file names start with numbers. For example,
> 01_step1.py, 02_step2.py
> 
> I tried to import them in another script by "import 01_step1" or "from
> 01_step1 import *". Both failed, saying "SyntaxError: invalid syntax"
> 
> Is there anyway to import those files? The file name must start with
> characters?

Or an underscore. The module name must be a valid identifier. In CPython you 
can hack around that restriction with 

step01 = __import__("01_step1")

but this "solution" is not portable and I recommend that you rename your 
scripts instead.

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


Re: How to import module whose filename starts number

2012-12-12 Thread Benjamin Kaplan
On Dec 12, 2012 9:47 AM, "Yong Hu"  wrote:
>
> I have a few scripts whose file names start with numbers. For example,
01_step1.py, 02_step2.py
>
> I tried to import them in another script by "import 01_step1" or "from
01_step1 import *". Both failed, saying "SyntaxError: invalid syntax"
>
> Is there anyway to import those files? The file name must start with
characters?
> --

I believe the restriction is that the module names must be valid
identifiers. You may still be able to import them using __import__ and then
assign the resulting module object to a valid name.
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 05:25:11 D'Arcy J.M. Cain wrote:

As a 16yr OSS vet I know that for every 1 person that that actually creates 
something there will always be 2000 people to bitch about it. My skin isn't 
thin, I just don't give a shit to listen to anyone one that doesn't get it.

The point to Thesaurus for those that want to pay attention:
The concept in these ~25 lines of code have changed the way I program Python
and reduced existing functionally identical code up to 30%...and I like the 
code better.

If that doesn't peak your interest, then move on...nothing here for you to 
see.

If you feel it needs to be expanded/corrected, do it and share it. If you can 
do it better, re-implement it. That's why I sent it to the mailing list.


> On Wed, 12 Dec 2012 17:44:24 +1100
> 
> Chris Angelico  wrote:
> > On Wed, Dec 12, 2012 at 5:34 PM, Steven D'Aprano
> > 
> >  wrote:
> > > and you consider this "not productive, not worth my time". Code
> > > review with you must be *all* sorts of fun.
> > 
> > He never asked for code review :)
> 
> I think by posting it he sort of did.  He should probably grow a
> thicker skin before he does so again though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python parser problem

2012-12-12 Thread RCU

  Hello.
I would like to report a parser bug manifesting on Python 2.5, 2.7 (but not on 2.2) 
and 3.3.

Please see the attached script.
Basically this bug appeared after applying PythonTidy on a valid script.

More exactly, when running:
python -c "import iCam_GIT5_5"
  I get:
Traceback (most recent call last):
  File "", line 1, in 
  File "iCam_GIT5_5.py", line 60

^
SyntaxError: invalid syntax

Actually, the error reported by Python is a bug, as far as I see: the line 60 
reported in the script does not actually contain the text reported in the error, and this 
makes quite difficult locating the so-called error.
In fact the error is at script line 30: we should have all the code on one line, like 
this
	playlistToUse = youtubeClient.AddPlaylist(playlistTitle, playlistTitle, 
playlist_private=False).
The "\" used in the script to break the line in 2 is a reminiscence of running 
PythonTidy-1.22.python (so fixing this bug would be directly relevant when using PythonTidy).


With this occasion I would like to ask also what are the limits of the Python 2.x and 
3.x parser. Where can I find what are the limits on the size/lines of the parsed script?


  Best regards,
Alex
CURRENT_RELEASE_TIME = '2012_12_10_13_00_00'

NEW_BT_FORMAT_TO_ALLOW_PLAYING_FILE_EVEN_IN_INBOX = True

def SendAlarmMessageToYouTubePlaylist(message):

global youtubeClient, youtubeClientAlreadyConnected

global YOUTUBE_TEST_CLIENT_ID, googleUsername, youtubeDeveloperKey

global uploadMediaToYouTube

global deviceId

if MY_DEBUG_STDOUT:

print 'Entered SendAlarmMessageToYouTubePlaylist() at %s.' % 
GetCurrentDateTimeStringWithMilliseconds()

sys.stdout.flush()

if uploadMediaToYouTube == 0:

uploadMediaToYouTube = 1

if youtubeClientAlreadyConnected == False:

if gdataModulesImported == False:

ImportGdataModules()

connResult = ConnectToYouTubeGData()

try:

playlistTitle = 'iCam_alarm_' + deviceId

if False:

playlistDescription = playlistTitle

playlistToUse = None

feed = youtubeClient.GetYouTubePlaylistFeed()

for myEntry in feed.entry:

myEntryTitle = myEntry.title.text

myEntryIdStr = myEntry.id.text.split('/')[-1]

if playlistTitle == myEntryTitle:

playlistToUse = myEntry

break

if playlistToUse is None:

playlistToUse = \

youtubeClient.AddPlaylist(playlistTitle, playlistTitle, 
playlist_private=False)

playlistDescription = ''

newPlaylistDescription = 'Alarm... motion degree... audio degree... 
%s.' % message

playlistToUse = None

feed = youtubeClient.GetYouTubePlaylistFeed()

for myEntry in feed.entry:

myEntryTitle = myEntry.title.text

myEntryIdStr = myEntry.id.text.split('/')[-1]

if myEntryTitle == playlistTitle:

if MY_DEBUG_STDOUT:

print 'SendAlarmMessageToYouTubePlaylist(): Feed matched 
myEntry =', myEntry

print 'SendAlarmMessageToYouTubePlaylist(): myEntry.content 
=', myEntry.content

print 'SendAlarmMessageToYouTubePlaylist(): 
myEntry.description = %s' % str(myEntry.description)

sys.stdout.flush()

playlistDescription = 
str(myEntry.description).split('>')[-2].split('-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JSON logging ?

2012-12-12 Thread Bart Thate
Thanks for your reply Chris,

good to be updated on the pickle stuff, too bad it is still not safe for
use. But hee i prefer JSON above pickle anyways so ;]

As to using the logging package to send JSON dict over, the logging stuff
should be able to be converted to handle that. Just 2 things that need to
be changes. The logging package basically sends over an dict as well..

makePickle on the SocketHandler in order to send JSON instead of pickled
stuff

def makePickle(self, record):
"""
Pickles the record in binary format with a length prefix, and
returns it ready for transmission across the socket.
"""
ei = record.exc_info
if ei:
# just to get traceback text into record.exc_text ...
dummy = self.format(record)
# See issue #14436: If msg or args are objects, they may not be
# available on the receiving end. So we convert the msg % args
# to a string, save it as msg and zap the args.
d = dict(record.__dict__)
d['msg'] = record.getMessage()
d['args'] = None
d['exc_info'] = None
s = pickle.dumps(d, 1)
slen = struct.pack(">L", len(s))
return slen + s

and this function on the receiving end to convert the JSON stuff back to a
logging record (want to hook more stuff into this function, such that the
send JSON is converted into an events that gets send to my callback
handlers.)

def makeLogRecord(dict):
"""
Make a LogRecord whose attributes are defined by the specified
dictionary,
This function is useful for converting a logging event received over
a socket connection (which is sent as a dictionary) into a LogRecord
instance.
"""
rv = _logRecordFactory(None, None, "", 0, "", (), None, None)
rv.__dict__.update(dict)
return rv

What i don't see though is where the receiving code recides ?
How am i supposed to handle logrecords that are coming from remote, as
better phrased maybe .. where can i hook my (changed) makeLogRecord into ?

Thnx for the reply dude, helps me enormously ;]

Bart



On Wed, Dec 12, 2012 at 6:33 PM, Chris Rebert  wrote:

> On Dec 11, 2012 7:33 AM, "Bart Thate"  wrote:
> 
>
> > pickle uses eval still ? or is is considered safe now ? i was told not
> to use eval() stuff on data.
>
> I don't believe pickle uses eval() per se, but per the red warning box in
> its docs, it's still not safe when given untrusted input. IIRC, among other
> things, in order to unpickle non-built-in classes, it is capable of
> performing imports; this feature is rife for abuse by an adversary.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JSON logging ?

2012-12-12 Thread Bart Thate
Ha ! spoke too soon.

Was reading this:
http://docs.python.org/2/howto/logging-cookbook.htm
which
explains it all ;]

Place to be is the LogRecordStreamHandler ;]

Something to play with, first trying out to get a communication channel
running over DCC CHAT ...



On Wed, Dec 12, 2012 at 8:17 PM, Bart Thate  wrote:

> Thanks for your reply Chris,
>
> good to be updated on the pickle stuff, too bad it is still not safe for
> use. But hee i prefer JSON above pickle anyways so ;]
>
> As to using the logging package to send JSON dict over, the logging stuff
> should be able to be converted to handle that. Just 2 things that need to
> be changes. The logging package basically sends over an dict as well..
>
> makePickle on the SocketHandler in order to send JSON instead of pickled
> stuff
>
> def makePickle(self, record):
> """
> Pickles the record in binary format with a length prefix, and
> returns it ready for transmission across the socket.
> """
> ei = record.exc_info
> if ei:
> # just to get traceback text into record.exc_text ...
> dummy = self.format(record)
> # See issue #14436: If msg or args are objects, they may not be
> # available on the receiving end. So we convert the msg % args
> # to a string, save it as msg and zap the args.
> d = dict(record.__dict__)
> d['msg'] = record.getMessage()
> d['args'] = None
> d['exc_info'] = None
> s = pickle.dumps(d, 1)
> slen = struct.pack(">L", len(s))
> return slen + s
>
> and this function on the receiving end to convert the JSON stuff back to a
> logging record (want to hook more stuff into this function, such that the
> send JSON is converted into an events that gets send to my callback
> handlers.)
>
> def makeLogRecord(dict):
> """
> Make a LogRecord whose attributes are defined by the specified
> dictionary,
> This function is useful for converting a logging event received over
> a socket connection (which is sent as a dictionary) into a LogRecord
> instance.
> """
> rv = _logRecordFactory(None, None, "", 0, "", (), None, None)
> rv.__dict__.update(dict)
> return rv
>
> What i don't see though is where the receiving code recides ?
> How am i supposed to handle logrecords that are coming from remote, as
> better phrased maybe .. where can i hook my (changed) makeLogRecord into ?
>
> Thnx for the reply dude, helps me enormously ;]
>
> Bart
>
>
>
> On Wed, Dec 12, 2012 at 6:33 PM, Chris Rebert  wrote:
>
>> On Dec 11, 2012 7:33 AM, "Bart Thate"  wrote:
>> 
>>
>> > pickle uses eval still ? or is is considered safe now ? i was told not
>> to use eval() stuff on data.
>>
>> I don't believe pickle uses eval() per se, but per the red warning box in
>> its docs, it's still not safe when given untrusted input. IIRC, among other
>> things, in order to unpickle non-built-in classes, it is capable of
>> performing imports; this feature is rife for abuse by an adversary.
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Dave Cinege
On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote:

> I have a few critiques on the code.  First, you might want to use
> __getattribute__ instead of __getattr__.  Otherwise you'll end up

  File "/home/dcinege/src/thesaurus/thesaurus.py", line 84, in 
__getattribute__
return self.__getitem__(name)
RuntimeError: maximum recursion depth exceeded while calling a Python object

This takes me into the same hell as when I was trying to implement this as a 
class. Someone else would have to take the time to do this. __getattr__ doing 
what I expect it to do, for what i do.

Dave


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


Re: Python parser problem

2012-12-12 Thread Dave Angel
On 12/12/2012 02:10 PM, RCU wrote:
>   Hello.
> I would like to report a parser bug manifesting on Python 2.5, 2.7
> (but not on 2.2) and 3.3.
> Please see the attached script.
> Basically this bug appeared after applying PythonTidy on a valid
> script.
>
> More exactly, when running:
> python -c "import iCam_GIT5_5"
>   I get:
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "iCam_GIT5_5.py", line 60
>
> ^
> SyntaxError: invalid syntax
>
> Actually, the error reported by Python is a bug, as far as I see:
> the line 60 reported in the script does not actually contain the text
> reported in the error, and this makes quite difficult locating the
> so-called error.

No, the error is on line 60.  You have blank line between each line, but
your editor apparently doesn't show you that.

Your line-endings are messed up.  Here's a dump of the first two lines. 
(using hexdump -C)

  43 55 52 52 45 4e 54 5f  52 45 4c 45 41 53 45 5f 
|CURRENT_RELEASE_|
0010  54 49 4d 45 20 3d 20 27  32 30 31 32 5f 31 32 5f  |TIME =
'2012_12_|
0020  31 30 5f 31 33 5f 30 30  5f 30 30 27 0d 0d 0a 4e 
|10_13_00_00'...N|

Notice that the line ends with 0d0d0a, or \r\r\n.  That's not valid. 
Apparently python's logic considers that as a line ending with \r,
followed by a blank line ending with\r\n.


> In fact the error is at script line 30: we should have all the
> code on one line, like this
> playlistToUse = youtubeClient.AddPlaylist(playlistTitle,
> playlistTitle, playlist_private=False).
> The "\" used in the script to break the line in 2 is a
> reminiscence of running PythonTidy-1.22.python (so fixing this bug
> would be directly relevant when using PythonTidy).

Nothing wrong with ending with a backslash for continuation.  Backslash
continues the line onto the next one, which is blank.  Remove the extra
\r there and it'll be fine.

>
> With this occasion I would like to ask also what are the limits of
> the Python 2.x and 3.x parser. Where can I find what are the limits on
> the size/lines of the parsed script?
>
Can't help there.




-- 

DaveA

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


Preventing tread collisions

2012-12-12 Thread Wanderer
I have a program that has a main GUI and a camera. In the main GUI, you can 
manipulate the images taken by the camera. You can also use the menu to check 
the camera's settings. Images are taken by the camera in a separate thread, so 
the long exposures don't block the GUI. I block conflicts between the camera 
snapshot thread and the main thread by setting a flag called self.cameraActive. 
I check to see if the cameraActive flag is false and set the cameraActive to 
True just before starting the thread. I generate an event on exiting the thread 
which sets the cameraActive flag to False. I also check and set and reset the 
flag in all the menu commands that access the camera. Like this.

def onProperties(self, event):
""" Display a message window with the camera properties
event -- The camera properties menu event
"""
# Update the temperature
if not self.cameraActive:
self.cameraActive = True
self.camera.getTemperature()
camDict = self.camera.getPropertyDict()
self.cameraActive = False
else:
camDict = {'Error': 'Camera Busy'}
dictMessage(camDict, 'Camera Properties')

This works but my question is, is there a better way using semaphores, locks or 
something else to prevent collisions between threads?

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


Re: Python parser problem

2012-12-12 Thread Jerry Hill
On Wed, Dec 12, 2012 at 2:10 PM, RCU  wrote:
> With this occasion I would like to ask also what are the limits of the
> Python 2.x and 3.x parser. Where can I find what are the limits on the
> size/lines of the parsed script?

The Python Language Reference is probably what you're looking for:
http://docs.python.org/2/reference/index.html

See, particularly, section 2 about lexical analysis and possibly
section 9 for the grammar.  The short answer though, is that python
doesn't have any limits on the line length or the size of a script,
other than that execution will obviously fail if you run out of memory
while parsing or compiling the script.

PEP 8 (http://www.python.org/dev/peps/pep-0008/) is the Python style
guide, and it does have some recommendations about line length
(http://www.python.org/dev/peps/pep-0008/#maximum-line-length).  That
document suggests a maximum length of 79 characters per line, and
that's probably what PythonTidy was trying to accomplish by splitting
your line.

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


Re: Preventing tread collisions

2012-12-12 Thread Dave Angel
On 12/12/2012 03:11 PM, Wanderer wrote:
> I have a program that has a main GUI and a camera. In the main GUI, you can 
> manipulate the images taken by the camera. You can also use the menu to check 
> the camera's settings. Images are taken by the camera in a separate thread, 
> so the long exposures don't block the GUI. I block conflicts between the 
> camera snapshot thread and the main thread by setting a flag called 
> self.cameraActive. I check to see if the cameraActive flag is false and set 
> the cameraActive to True just before starting the thread. I generate an event 
> on exiting the thread which sets the cameraActive flag to False. I also check 
> and set and reset the flag in all the menu commands that access the camera. 
> Like this.
>
> def onProperties(self, event):
> """ Display a message window with the camera properties
> event -- The camera properties menu event
> """
> # Update the temperature
> if not self.cameraActive:
> self.cameraActive = True
> self.camera.getTemperature()
> camDict = self.camera.getPropertyDict()
> self.cameraActive = False
> else:
> camDict = {'Error': 'Camera Busy'}
> dictMessage(camDict, 'Camera Properties')
>
> This works 

I don't think so.  in between the if and the assignment, another thread
could get in there and also set the flag.  Then when either one of them
finishes, it'll clear the flag and the other code is unprotected.

For semaphores between multiple threads, you either have to define only
a single thread at any given moment being permitted to modify it, or you
have to use lower-level primitives, sometimes called test+set operation.

i don't know the "right" way to do this in Python, but this isn't it.
> but my question is, is there a better way using semaphores, locks or 
> something else to prevent collisions between threads?
>
> Thanks


-- 

DaveA

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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 12:20 PM, Dave Cinege  wrote:
> On Tuesday 11 December 2012 01:41:38 Ian Kelly wrote:
>
>> I have a few critiques on the code.  First, you might want to use
>> __getattribute__ instead of __getattr__.  Otherwise you'll end up
>
>   File "/home/dcinege/src/thesaurus/thesaurus.py", line 84, in
> __getattribute__
> return self.__getitem__(name)
> RuntimeError: maximum recursion depth exceeded while calling a Python object
>
> This takes me into the same hell as when I was trying to implement this as a
> class. Someone else would have to take the time to do this. __getattr__ doing
> what I expect it to do, for what i do.

def __getattribute__(self, name):
if name.startswith('__') and name.endswith('__'):
return super(Thesaurus, self).__getattribute__(name)
return self.__getitem__(name)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing tread collisions

2012-12-12 Thread MRAB

On 2012-12-12 20:11, Wanderer wrote:

I have a program that has a main GUI and a camera. In the main GUI, you can 
manipulate the images taken by the camera. You can also use the menu to check 
the camera's settings. Images are taken by the camera in a separate thread, so 
the long exposures don't block the GUI. I block conflicts between the camera 
snapshot thread and the main thread by setting a flag called self.cameraActive. 
I check to see if the cameraActive flag is false and set the cameraActive to 
True just before starting the thread. I generate an event on exiting the thread 
which sets the cameraActive flag to False. I also check and set and reset the 
flag in all the menu commands that access the camera. Like this.

 def onProperties(self, event):
 """ Display a message window with the camera properties
 event -- The camera properties menu event
 """
 # Update the temperature
 if not self.cameraActive:
 self.cameraActive = True
 self.camera.getTemperature()
 camDict = self.camera.getPropertyDict()
 self.cameraActive = False
 else:
 camDict = {'Error': 'Camera Busy'}
 dictMessage(camDict, 'Camera Properties')

This works but my question is, is there a better way using semaphores, locks or 
something else to prevent collisions between threads?


That suffers from a race condition in that self.cameraActive might be
False when it's checked in the 'if' condition but set to True just
afterwards by the other thread.

You could try a non-blocking semaphore:

def __init__(self):
self.cameraActive = Semaphore()

def onProperties(self, event):
""" Display a message window with the camera properties
event -- The camera properties menu event
"""
# Update the temperature
if self.cameraActive.acquire(False): # Non-blocking
# Successfully acquired the semaphore, so the camera wasn't active
self.camera.getTemperature()
camDict = self.camera.getPropertyDict()
self.cameraActive.release()
else:
camDict = {'Error': 'Camera Busy'}

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


Re: Preventing tread collisions

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 1:53 PM, MRAB  wrote:
> You could try a non-blocking semaphore:
>
> def __init__(self):
> self.cameraActive = Semaphore()

Why a Semaphore and not just a plain old Lock?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing tread collisions

2012-12-12 Thread MRAB

On 2012-12-12 20:58, Ian Kelly wrote:

On Wed, Dec 12, 2012 at 1:53 PM, MRAB  wrote:

You could try a non-blocking semaphore:

def __init__(self):
self.cameraActive = Semaphore()


Why a Semaphore and not just a plain old Lock?


Good point. I probably thought of a semaphore because the OP mentioned
it first. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote:

> def __getattribute__(self, name):
> if name.startswith('__') and name.endswith('__'):
> return super(Thesaurus, self).__getattribute__(name)
> return self.__getitem__(name)

Ian,

Tested, and works as you advertised.

Isn't super() depreciated? I've replaced it with this:
-return super(Thesaurus, self).__getattribute__(name)
+return dict.__getattribute__(self, name)

Aside from a more palatable result in the python shell for otherwise bad 
code...does this get me anything else? Is it really worth the performance hit 
of 2 string comparisons for every getattribute call?

I also just reviewed all your original comments again:

In general: The recursion code is nothing special to me and I finally settled 
on the nested try's as something simple that 'just works good for now'. 

I think the concept of what I'm doing here is the big idea.

Should the idea of implementing what Thesaurus does in mainline python ever 
happen, those 10 lines of code will likely spark a 3 month jihad about how to 
properly do in python which up until now hasn't been something you do in 
python.

To me for i in range(len(l)) seems like simpler, faster, tighter code for this 
now. It's duly noted that enumerate() is more python and I'm an old fart that 
still thinks too much in state machine. I've add except Exception per your 
advise.

What I'd really like to hear is that someone reading was curious enough to 
convert some existing code and their joy or displeasure with the experience.

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


Using regexes versus "in" membership test?

2012-12-12 Thread Victor Hooi
Hi,

I have a script that trawls through log files looking for certain error 
conditions. These are identified via certain keywords (all different) in those 
lines

I then process those lines using regex groups to extract certain fields.

Currently, I'm using a for loop to iterate through the file, and a dict of 
regexes:

breaches = {
'type1': re.compile(r'some_regex_expression'),
'type2': re.compile(r'some_regex_expression'),
'type3': re.compile(r'some_regex_expression'),
'type4': re.compile(r'some_regex_expression'),
'type5': re.compile(r'some_regex_expression'),
}
...
with open('blah.log', 'r') as f:
for line in f:
for breach in breaches:
results = breaches[breach].search(line)
if results:
self.logger.info('We found an error - {0} - 
{1}'.format(results.group('errorcode'), results.group('errormsg'))
# We do other things with other regex groups as well.

(This isn't the *exact* code, but it shows the logic/flow fairly closely).

For completeness, the actual regexes look something like this:

Also, my regexs could possibly be tuned, they look something like this:


(?P\d{2}:\d{2}:\d{2}.\d{9})\s*\[(?P\w+)\s*\]\s*\[(?P\w+)\s*\]\s*\[{0,1}\]{0,1}\s*\[(?P\w+)\s*\]\s*level\(\d\)
 
broadcast\s*\(\[(?P\w+)\]\s*\[(?P\w+)\]\s*(?P\w{4}):(?P\w+)
 failed order: (?P\w+) (?P\d+) @ (?P[\d.]+), error on 
update \(\d+ : Some error string. Active Orders=(?P\d+) 
Limit=(?P\d+)\)\)

(Feel free to suggest any tuning, if you think they need it).

My question is - I've heard that using the "in" membership operator is 
substantially faster than using Python regexes.

Is this true? What is the technical explanation for this? And what sort of 
performance characteristics are there between the two?

(I couldn't find much in the way of docs for "in", just the brief mention here 
- http://docs.python.org/2/reference/expressions.html#not-in )

Would I be substantially better off using a list of strings and using "in" 
against each line, then using a second pass of regex only on the matched lines?

(Log files are compressed, I'm actually using bz2 to read them in, uncompressed 
size is around 40-50 Gb).



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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Ian Kelly
On Wed, Dec 12, 2012 at 3:20 PM, Dave Cinege  wrote:
> On Wednesday 12 December 2012 15:42:36 Ian Kelly wrote:
>
>> def __getattribute__(self, name):
>> if name.startswith('__') and name.endswith('__'):
>> return super(Thesaurus, self).__getattribute__(name)
>> return self.__getitem__(name)
>
> Ian,
>
> Tested, and works as you advertised.
>
> Isn't super() depreciated? I've replaced it with this:
> -return super(Thesaurus, self).__getattribute__(name)
> +return dict.__getattribute__(self, name)

It's not deprecated.  Some people consider it harmful, and others
disagree.  I was once in the former camp but have shifted somewhat
toward the latter.

> Aside from a more palatable result in the python shell for otherwise bad
> code...does this get me anything else? Is it really worth the performance hit
> of 2 string comparisons for every getattribute call?

It could affect real code, not just interactive code.  Any time you
unthinkingly choose an attribute name that happens to be the name of a
dict method (e.g. 'items', which otherwise seems like a rather
innocent variable name), that's a potential bug.  Depending on how
that attribute is subsequently accessed, the bug might not even be
noticed immediately.

The performance hit compared to the __getattr__ version on my system
is about 1.3 microseconds per call, as measured by timeit, or around
40%.  For comparison, the performance hit of using the __getattr__
version versus just using a global variable is about 1.7 microseconds
per call, or around 4000%.  For my own use, I don't consider that
substantial enough to worry about, as I'm not in the business of
writing code that would be making hundreds of thousands of accesses
per second.

> Should the idea of implementing what Thesaurus does in mainline python ever
> happen, those 10 lines of code will likely spark a 3 month jihad about how to
> properly do in python which up until now hasn't been something you do in
> python.

The basic idea of proxying attribute access on a dict to key lookup is
pretty common, actually.  It likely won't ever make it into the
standard library because 1) there's no clear agreement on what it
should look like; 2) it's easy to roll your own; and 3) it looks too
much like JavaScript.  That last probably isn't valid; attribute
proxying is annoying and cumbersome when it automatically happens on
every single object in the language; it's much more manageable when
you have a single type like Thesaurus that you can use only in the
instances where you actually want it.

> To me for i in range(len(l)) seems like simpler, faster, tighter code for this
> now. It's duly noted that enumerate() is more python and I'm an old fart that
> still thinks too much in state machine. I've add except Exception per your
> advise.

Your intuition about what "seems faster" can lead you astray.  Using Python 2.7:

>>> timerD = timeit.Timer('for i in range(len(seq)): x = seq[i]', 'seq = 
>>> range(5)')
>>> timerE = timeit.Timer('for i, x in enumerate(seq): pass', 'seq = range(5)')
>>> min(timerD.repeat(3))
0.8711640725291545
>>> min(timerE.repeat(3))
0.7172601545726138

Of course, that's running each loop a million times, so the difference
here really is pretty negligible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with Python/ArcPy

2012-12-12 Thread Michelle Couden
Does anyone know of a website or forum  where there is help for ArcPY (Python) 
programmers? ESRI's (GIS) resource center Forums are very busy and my questions 
go days without an answer. Any suggestions would be great. Thanks!!



Michelle Couden
TPP-T GIS Cartographer
Certified GIS Analyst
(512) 486-5136
Fax (512)486-5153
michelle.cou...@txdot.gov

Mind the road, not your business.
[Logo]




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


Re: samba 4 release

2012-12-12 Thread Mark Lawrence

On 12/12/2012 17:39, peter wrote:

On 12/12/2012 02:38 PM, peter wrote:

Hellou.

   Samba4 first release, with python interface for the internals api,
and a implementation of the DC in python :).

Viva la python

I forgot to put the link of the good news

https://www.samba.org/samba/history/samba-4.0.0.html



Awesome!!!  But what the  is it???

--
Cheers.

Mark Lawrence.

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


Re: Help with Python/ArcPy

2012-12-12 Thread Xavier Ho
You can always try http://stackoverflow.com/search?q=ArcPY, or post your
question there.

Cheers,
Xav



On 13 December 2012 08:07, Michelle Couden wrote:

>  Does anyone know of a website or forum  where there is help for ArcPY
> (Python) programmers? ESRI’s (GIS) resource center Forums are very busy and
> my questions go days without an answer. Any suggestions would be great.
> Thanks!!
>
> ** **
>
> ** **
>
> ** **
>
> *Michelle Couden*
>
> TPP-T GIS Cartographer
>
> Certified GIS Analyst
>
> (512) 486-5136
>
> Fax (512)486-5153
>
> michelle.cou...@txdot.gov
>
> ** **
>
> Mind the road, not your business.
>
> [image: Logo]
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
<>-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hollow square program

2012-12-12 Thread Mark Lawrence

On 12/12/2012 17:52, siimnur...@gmail.com wrote:

Thanks, got it now :)



Please quote something in context for future readers.  Roughly translated



THE ONLY GOOD GOOGLE USER IS A DEAD GOOGLE USER



--
Cheers.

Mark Lawrence.

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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Mark Lawrence

On 12/12/2012 18:13, Dave Cinege wrote:

On Wednesday 12 December 2012 05:25:11 D'Arcy J.M. Cain wrote:

As a 16yr OSS vet I know that for every 1 person that that actually creates
something there will always be 2000 people to bitch about it. My skin isn't
thin, I just don't give a shit to listen to anyone one that doesn't get it.

The point to Thesaurus for those that want to pay attention:
The concept in these ~25 lines of code have changed the way I program Python
and reduced existing functionally identical code up to 30%...and I like the
code better.

If that doesn't peak your interest, then move on...nothing here for you to
see.


Please don't place responses like this.  The Python community prides 
itself on tolerance.  If you don't wish to follow that recommendation 
please go to an alternative site.


--
Cheers.

Mark Lawrence.

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


Re: Hollow square program

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 23:47:20 +, Mark Lawrence wrote:

> THE ONLY GOOD GOOGLE USER IS A DEAD GOOGLE USER
> 
> 

I say, that's a bit much. That crosses a line from a friendly contempt 
for ignorant Gmail users to something rather nasty. Preemptive apology or 
not, I don't think that is acceptable here.


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


Re: Python parser problem

2012-12-12 Thread Terry Reedy

On 12/12/2012 2:10 PM, RCU wrote:

 I would like to report a parser bug manifesting on Python 2.5, 2.7
(but not on 2.2) and 3.3.


You are not the first to erroneously attribute a problem to Python 
itself. But seriously, the interpreter itself is so thoroughly tested on 
a daily basis that you should assume that a reported SyntaxError is real.



 Please see the attached script.
 Basically this bug appeared after applying PythonTidy on a valid
script.


PythonTidy is much more likely to be buggy than Python itself.


 More exactly, when running:
 python -c "import iCam_GIT5_5"
   I get:
 Traceback (most recent call last):
   File "", line 1, in 
   File "iCam_GIT5_5.py", line 60

 ^
 SyntaxError: invalid syntax


SyntaxErrors are sometimes reported on the line after they occur, 
especially when the error is at the very end of the line and not obvious 
until /n is read.



 The "\" used in the script to break the line in 2 is a reminiscence
of running PythonTidy-1.22.python (so fixing this bug would be directly
relevant when using PythonTidy).


A '\' used to break a line MUST be the last character in the line. Dave 
explained how your editor and PythonTidy together made a bug.



 With this occasion I would like to ask also what are the limits of
the Python 2.x and 3.x parser. Where can I find what are the limits on
the size/lines of the parsed script?


Python, the language has no limits. Implementations will, but they are 
larger than you will every write by hand. Auto-generated code that, for 
instance, nests a tuple more than 2**16 levels deep may have problems.


--
Terry Jan Reedy

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


Re: samba 4 release

2012-12-12 Thread Michael Torrie
On 12/12/2012 04:40 PM, Mark Lawrence wrote:
> Awesome!!!  But what the  is it???

Are you serious?  You honestly don't know what one of the oldest, most
widely used piece of open source software it and what it does?  Samba is
at least as well-known and important as Apache, if not more so.

You can be forgiven if you don't know what a DC is... That's a "Domain
Controller" and it forms the central core of an MS Active Directory
setup (users/group info, authentication, user/group policies, client
machine policies.

Now if we could just get an Exchange replacement that actually doesn't
suck...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 23:56:24 +, Mark Lawrence wrote:

> Please don't place responses like this.  The Python community prides
> itself on tolerance.  If you don't wish to follow that recommendation
> please go to an alternative site.

Well, I must say, I think that you've just won an award for Most 
Cognitive Dissonance Exhibited In The Shortest Time. I'm not sure how you 
can yell at somebody that Google users should be dead in one post, and 
then nine minutes later say this.



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


Re: samba 4 release

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 23:40:47 +, Mark Lawrence wrote:

> On 12/12/2012 17:39, peter wrote:
>> On 12/12/2012 02:38 PM, peter wrote:
>>> Hellou.
>>>
>>>Samba4 first release, with python interface for the internals api,
>>> and a implementation of the DC in python :).
>>>
>>> Viva la python
>> I forgot to put the link of the good news
>>
>> https://www.samba.org/samba/history/samba-4.0.0.html
>>
>>
> Awesome!!!  But what the  is it???

You don't have access to the web where you are? :-)

Copied from https://www.samba.org/ 

[quote]
Samba is the standard Windows interoperability suite of programs for 
Linux and Unix. 

Samba is Free Software licensed under the GNU General Public License, the 
Samba project is a member of the Software Freedom Conservancy. 

Since 1992, Samba has provided secure, stable and fast file and print 
services for all clients using the SMB/CIFS protocol, such as all 
versions of DOS and Windows, OS/2, Linux and many others. 

Samba is an important component to seamlessly integrate Linux/Unix 
Servers and Desktops into Active Directory environments using the winbind 
daemon.
[end quote]


-- 
Steven

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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote:

> Isn't super() depreciated? 

Heavens no. super() is the recommended way to do inheritance, and the 
*only* way to correctly do multiple inheritance[1]. What makes you think 
that it has been deprecated?


[...]
> To me for i in range(len(l)) seems like simpler, faster, tighter code
> for this now. 

It's not. It is more complex, slower, less direct code. Python is not C, 
or Fortran, or whatever low-level language you cut your teeth on and get 
your intuitions from.

[steve@ando ~]$ python -m timeit -s "L = list('abcdefghij')" "for i in 
range(len(L)):
c = L[i]
pass"
100 loops, best of 3: 1.67 usec per loop
[steve@ando ~]$ python -m timeit -s "L = list('abcdefghij')" "for i,c in 
enumerate(L):
pass"
100 loops, best of 3: 1.39 usec per loop


That's only a small performance speedup, but the real advantages are:

* the version with enumerate is much more general: it works with 
  data structures where the length is expensive to calculate, lazy 
  data streams where the length is impossible to know up front, 
  and infinite data streams;

* the version with enumerate makes the intent more clear: since we
  care about looping over the items, we should iterate over the 
  items directly, not over their indices;

* it is more readable and maintainable: both loop variables (the
  index and the item) are defined in the same place, the start of 
  the for-loop, instead of one in the header and one in the body.



> What I'd really like to hear is that someone reading was curious enough
> to convert some existing code and their joy or displeasure with the
> experience.

I don't have any code with nested dicts where this would make a 
difference. If I had such code, I would be looking to redesign it so that 
I could avoided the nested dicts, not find a palliative. The Zen of 
Python is a useful guide to general design principles:

py> import this
The Zen of Python, by Tim Peters

[...]
Flat is better than nested.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.

Your Thesaurus class violates too many of these principles for it to be 
of interest to me. Having spent a good hour or so playing around with it 
in the interactive interpreter, it is too hard for me to reason about 
what it is doing (especially since your description of what it does is 
actively misleading), and too hard to predict under what circumstances it 
will fail.

Short code is not necessarily simple code, and I find your class too 
magical and complicated to be interested in using it in production code 
as it stands now.




[1] Well, technically there's another way: one might reimplement the 
functionality of super() in your own code, and avoid using super() while 
having all the usual joys of reinventing the wheel.


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


Re: samba 4 release

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 17:18:43 -0700, Michael Torrie wrote:

> Now if we could just get an Exchange replacement that actually doesn't
> suck...

But but but... if it didn't contain sufficient levels of suckage, it 
would hardly be a replacement for Exchange, would it?!?!?


:-P


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


Re: Help with Python/ArcPy

2012-12-12 Thread George Silva
even better gis.stackexchange.com


On Wed, Dec 12, 2012 at 9:42 PM, Xavier Ho  wrote:

> You can always try http://stackoverflow.com/search?q=ArcPY, or post your
> question there.
>
> Cheers,
> Xav
>
>
>
> On 13 December 2012 08:07, Michelle Couden wrote:
>
>>  Does anyone know of a website or forum  where there is help for ArcPY
>> (Python) programmers? ESRI’s (GIS) resource center Forums are very busy and
>> my questions go days without an answer. Any suggestions would be great.
>> Thanks!!
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> *Michelle Couden*
>>
>> TPP-T GIS Cartographer
>>
>> Certified GIS Analyst
>>
>> (512) 486-5136
>>
>> Fax (512)486-5153
>>
>> michelle.cou...@txdot.gov
>>
>> ** **
>>
>> Mind the road, not your business.
>>
>> [image: Logo]
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> ** **
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net
<>-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using regexes versus "in" membership test?

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 14:35:41 -0800, Victor Hooi wrote:

> Hi,
> 
> I have a script that trawls through log files looking for certain error
> conditions. These are identified via certain keywords (all different) in
> those lines
> 
> I then process those lines using regex groups to extract certain fields.
[...]
> Also, my regexs could possibly be tuned, they look something like this:
> 
> (?P\d{2}:\d{2}:\d{2}.\d{9})\s*\[(?P\w+)\s*
\]\s*\[(?P\w+)\s*\]\s*\[{0,1}\]{0,1}\s*\[(?P\w+)\s*\]
\s*level\(\d\) broadcast\s*\(\[(?P\w+)\]\s*\[(?P\w+)\]
\s*(?P\w{4}):(?P\w+) failed order: (?P\w+) (?
P\d+) @ (?P[\d.]+), error on update \(\d+ : Some error 
string. Active Orders=(?P\d+) Limit=(?P\d+)\)\)
>
> (Feel free to suggest any tuning, if you think they need it).

"Tuning"? I think it needs to be taken out and killed with a stake to the 
heart, then buried in concrete! :-)

An appropriate quote:

Some people, when confronted with a problem, think "I know, 
I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski

Is this actually meant to be a single regex, or did your email somehow 
mangle multiple regexes into a single line?

At the very least, you should write your regexes using the VERBOSE flag, 
so you can use non-significant whitespace and comments. There is no 
performance cost to using VERBOSE once they are compiled, but a huge 
maintainability benefit.


> My question is - I've heard that using the "in" membership operator is
> substantially faster than using Python regexes.
> 
> Is this true? What is the technical explanation for this? And what sort
> of performance characteristics are there between the two?

Yes, it is true. The technical explanation is simple:

* the "in" operator implements simple substring matching, 
  which is trivial to perform and fast;

* regexes are an interpreted mini-language which operate via
  a complex state machine that needs to do a lot of work,
  which is complicated to perform and slow.

Python's regex engine is not as finely tuned as (say) Perl's, but even in 
Perl simple substring matching ought to be faster, simply because you are 
doing less work to match a substring than to run a regex.

But the real advantage to using "in" is readability and maintainability.

As for the performance characteristics, you really need to do your own 
testing. Performance will depend on what you are searching for, where you 
are searching for it, whether it is found or not, your version of Python, 
your operating system, your hardware.

At some level of complexity, you are better off just using a regex rather 
than implementing your own buggy, complicated expression matcher: for 
some matching tasks, there is no reasonable substitute to regexes. But 
for *simple* uses, you should prefer *simple* code:

[steve@ando ~]$ python -m timeit \
> -s "data = 'abcd'*1000 + 'xyz' + 'abcd'*1000" \
> "'xyz' in data"
10 loops, best of 3: 4.17 usec per loop

[steve@ando ~]$ python -m timeit \
> -s "data = 'abcd'*1000 + 'xyz' + 'abcd'*1000" \
> -s "from re import search" \
> "search('xyz', data)"
10 loops, best of 3: 10.9 usec per loop



> (I couldn't find much in the way of docs for "in", just the brief
> mention here -
> http://docs.python.org/2/reference/expressions.html#not-in )
> 
> Would I be substantially better off using a list of strings and using
> "in" against each line, then using a second pass of regex only on the
> matched lines?

That's hard to say. It depends on whether you are matching on a substring 
that will frequently be found close to the start of each line, or 
something else.

Where I expect you *will* see a good benefit is:

* you have many lines to search;
* but only a few actually match the regex;
* the regex is quite complicated, and needs to backtrack a lot;
* but you can eliminate most of the "no match" cases with a simple
  substring match.

If you are in this situation, then very likely you will see a big benefit 
from a two-pass search:

for line in log:
if any(substr in line for substr in list_of_substrings):
# now test against a regex


Otherwise, maybe, maybe not.


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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 11:30 AM, Steven D'Aprano
 wrote:
> On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote:
>> To me for i in range(len(l)) seems like simpler, faster, tighter code
>> for this now.
>
> * the version with enumerate makes the intent more clear: since we
>   care about looping over the items, we should iterate over the
>   items directly, not over their indices;

To add to this: Using enumerate gives the possibility (don't know if
any current interpreter takes advantage or not, but a future one
certainly could) that the enumerate() call could be optimized out.
Yes, it's theoretically possible that someone could redefine
enumerate, which would be broken by such an optimization. But all it'd
take is some kind of directive-based optimization and voila, safe
performance improvements.

Example code used:
>>> def foo(x):
for i,val in enumerate(x):
print("x[%d] = %s"%(i,str(val)))

>>> def foo(x):
for i in range(len(x)):
val=x[i]
print("x[%d] = %s"%(i,str(val)))

A simple look at dis.dis() for the above two functions disproves the
"faster". Steven has already disproven the "simpler" and "tighter".

(I would like, though, to see a key-providing iteration as a standard
feature. Looking at dis.dis() for the above examples and also at a
simple iteration over a dictionary's .items(), I'm seeing what looks
like a lot of effort to deal with the fact that iterators return a
stream of items, rather than a stream of keys and values. But it's
probably not worth changing now.)

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


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Dave Cinege
On Wednesday 12 December 2012 20:14:08 Chris Angelico wrote:

Ok enough already, I'll use the frigging thing!

Be happy I'm at least still not coding for python 1.5.

> To add to this: Using enumerate gives the possibility (don't know if
> any current interpreter takes advantage or not, but a future one
> certainly could) that the enumerate() call could be optimized out.
> Yes, it's theoretically possible that someone could redefine
> enumerate, which would be broken by such an optimization. But all it'd
> take is some kind of directive-based optimization and voila, safe
> performance improvements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Terry Reedy

On 12/12/2012 7:30 PM, Steven D'Aprano wrote:

On Wed, 12 Dec 2012 17:20:53 -0500, Dave Cinege wrote:


Isn't super() depreciated?


Heavens no. super() is the recommended way to do inheritance, and the
*only* way to correctly do multiple inheritance[1].


Indeed. Rather than super() being deprecated, it was made easier to use 
in 3.x by being special cased during compilation. Notice the difference 
of signatures:


2.7: super(type[, object-or-type])
3.3: super([type[, object-or-type]])

"The zero argument form only works inside a class definition, as the 
compiler fills in the necessary details to correctly retrieve the class 
being defined, as well as accessing the current instance for ordinary 
methods."



[1] Well, technically there's another way: one might reimplement the
functionality of super() in your own code, and avoid using super() while
having all the usual joys of reinventing the wheel.


This deeper integration means that it could not be completely 
reimplemented in Python ;-).


--
Terry Jan Reedy

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


ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes - v20121212

2012-12-12 Thread Dave Cinege
Version 20121212
#!/usr/bin/env python
"""
thesaurus.py		2012-12-12

Copyright (c) 2012 Dave Cinege
Licence: PSF Licence, Copyright notice may not be altered.

Thesaurus: A different way to call a dictionary.

Thesaurus is a new a dictionary subclass which allows calling keys as
if they are class attributes and will search through nested objects
recursively when __getitem__ is called.

You will notice that the code is disgusting simple. However I have found that
this has completely changed the way I program in Python. I've re-written some
exiting programs using Thesaurus, and often realized 15-30% code reduction.
Additionally I find the new code much easier to read.

If you find yourself programing with nested dictionaries often, fighting to 
generate output or command lines for external programs, or wish you had 
a dictionary that could act (sort of) like a class, Thesaurus may be for you.

By example:
---
#!/usr/bin/env python

import thesaurus
thes = thesaurus.Thesaurus

# I like to create a master global object called 'g'.
# No more 'global' statements for me.
g = thes()

g.prog = thes()
g['prog']['VERSION'] = '1.0'	# I can do this like a normal nested dictionary
g.prog.VERSION = '1.0'		# But isn't this so much cleaner?
g.prog.NAME = 'Thesaurus'

class TestClass:
	no = 'Class'
	way = 'this'

def main ():

	L = thes()		# Some local varibles

	L.tc = TestClass()	# We can also recurse to class attributes

	L.l = list()		# And recurse to indices too!
	L.l.append('Some')
	L.l.append('objects')
	
	g.L = L		# Easily make these locals global
	
	# Here's the real magic. Creating output without a fight.
	print '''
		When programing python using %(prog.NAME)s, it is very
		easy to access your %(L.l.1)s.
		
		%(L.l.0)s people might say %(prog.NAME)s has no %(L.tc.no)s.
	'''.replace('\t','')[1:-1] % g

	del g.L		# Clean locals up out of global space

	# If I was using a storage class, I must use hasattr() or an ugly eval.
	# But we can still use a str for the key name and 'in' like on any
	# regular dictionary.
	if 'VERSION' in g.prog:
		print 'But I challenge them to write code %(tc.way)s clean without it!' % L


if __name__ == '__main__':
	main()
---
"""

__VERSION__ = 20121212

class Thesaurus (dict):
	def __getattribute__(self, name):
		if name.startswith('__') and name.endswith('__'):
			return dict.__getattribute__(self, name)
		return self.__getitem__(name)
	def __setattr__(self, name, value):
		return dict.__setitem__(self, name, value)
	def __delattr__(self, name):
		return dict.__delitem__(self, name)
	def __getitem__(self, key):
		if '.' not in key:
			return dict.__getitem__(self, key)
		a = self
		l = key.split('.')
		for i,v in enumerate(l):	# Walk keys recursivly
			try:
a = a[v]		# Attempt key
			except Exception:
try:
	a = getattr(a, v)	# Attempt attr
except Exception:
	try:
		a = a[int(v)]	# Attempt indice
	except Exception:
		raise KeyError('%(v)s (%(key)s[%(i)s])' % locals() )
		return a
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Dave Cinege
On Monday 10 December 2012 23:08:24 Jason Friedman wrote:

> 2) Posting your code at ActiveState.com.

If someone wants to please do. I'm back to being completely overloaded with 
normal work now. The v20121212 release based on the last few days comments is 
as far as I will go with this now.

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


Re: samba 4 release

2012-12-12 Thread Terry Reedy

On 12/12/2012 7:18 PM, Steven D'Aprano wrote:

On Wed, 12 Dec 2012 23:40:47 +, Mark Lawrence wrote:


On 12/12/2012 17:39, peter wrote:

On 12/12/2012 02:38 PM, peter wrote:

Hellou.

Samba4 first release, with python interface for the internals api,
and a implementation of the DC in python :).

Viva la python

I forgot to put the link of the good news

https://www.samba.org/samba/history/samba-4.0.0.html


Which has the following:

Python Scripting Interface
==

A new scripting interface has been added to Samba 4, allowing
Python programs to interface to Samba's internals, and many tools and
internal workings of the DC code is now implemented in python.

which is indeed great news for Pythonistas who work with Samba.


> Awesome!!!  But what the  is it???

You don't have access to the web where you are? :-)

Copied from https://www.samba.org/

[quote]
Samba is the standard Windows interoperability suite of programs for
Linux and Unix.

Samba is Free Software licensed under the GNU General Public License, the
Samba project is a member of the Software Freedom Conservancy.

Since 1992, Samba has provided secure, stable and fast file and print
services for all clients using the SMB/CIFS protocol, such as all
versions of DOS and Windows, OS/2, Linux and many others.

Samba is an important component to seamlessly integrate Linux/Unix
Servers and Desktops into Active Directory environments using the winbind
daemon.
[end quote]


As I understand, Active Directory is the center, so to speak, of a 
Windows server universe. The Wikipedia entry may be clearer than some of 
Microsoft's pages.


--
Terry Jan Reedy

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


Re: samba 4 release

2012-12-12 Thread rusi
On Dec 13, 5:18 am, Michael Torrie  wrote:
> On 12/12/2012 04:40 PM, Mark Lawrence wrote:
>
> > Awesome!!!  But what the  is it???
>
> Are you serious?  You honestly don't know what one of the oldest, most
> widely used piece of open source software it and what it does?  Samba is
> at least as well-known and important as Apache, if not more so.

For me, more important than apache is the set
1. Linux
2. Perl (followed by python)
3. Samba
4. Wine


Linux showed that Unix can run on PCs -- seriously. Yeah the
professors writing Minix also did that but Linux stopped being a toy.
Of course Linus was lucky that he was hacking when the 386 came out.

Perl, which was the first to show that a realistic language could be
made whose programs run unchanged on Unix and Dos. [Yeah we
pythonistas take it for granted today. It was incredible 15 years ago]

Samba took Perl's 'polite interoperability' to a new level:
'aggressive cooperation.'
'You may not want to talk to me but I will talk to you anyhow'

What Samba does on the server, wine does on the desktop... Not quite
so successful but getting there

>
> You can be forgiven if you don't know what a DC is... That's a "Domain
> Controller" and it forms the central core of an MS Active Directory
> setup (users/group info, authentication, user/group policies, client
> machine policies.
>
> Now if we could just get an Exchange replacement that actually doesn't
> suck...

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


OOP noob question: Mixin properties

2012-12-12 Thread Micky Hulse
Dear Python Santa gurus, ;D

I have this Django mixin:



...which is used to override render_to_response() so I can output a
JSON response (the above code is pretty much straight from the Django
docs: 
).

The JSONResponseMixin() gets added to my view class like so:

class Api(JSONResponseMixin, BaseDetailView):
# ...

Within my the mixins.py file, at the top of the file, I've added these
constants:

CACHE_TIMEOUT = 86400 # 24 hours.
CACHE_NAME = 'ad_manager_api'

Question(s):

I'd like to convert those constants to properties and make my
JSONResponseMixin() class more generic and portable.

Django aside, could someone provide OOP Python examples of how I could
instantiate a mixin Class and set/override its properties before
passing data to said mixin?

I hope you don't mind that this question involves Django... I'm just
looking to improve my core Python skills (so, generic Python examples
would be cool).

Many thanks in advance!

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


Re: why does dead code costs time?

2012-12-12 Thread Ramchandra Apte
On Sunday, 9 December 2012 22:17:09 UTC+5:30, Mark Lawrence  wrote:
> On 09/12/2012 14:11, Ramchandra Apte wrote:
> 
> >
> 
> > peehole haha
> 
> >
> 
> Double spaced crap from you again not so haha.
> 
> -- 
> 
> Cheers.
> 
> Mark Lawrence.

haha. What does "Cheers" mean?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why does dead code costs time?

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:

>> Cheers.
>> 
>> Mark Lawrence.
> 
> haha. What does "Cheers" mean?

It is an exclamation expressing good wishes. In particular, good wishes 
before drinking. Think of it as a variation on:

"Good health to you"
"Best wishes"
"Sincerest regards"

only less formal.


Does the Internet not work where you are? Googling for "define:cheers" or 
"definition cheers" should have answered that question.



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


Re: Using regexes versus "in" membership test?

2012-12-12 Thread Victor Hooi
Hi,

That was actually *one* regex expression...lol.

And yes, it probably is a bit convoluted.

Thanks for the tip about using VERBOSE - I'll use that, and comment my regex - 
that's a useful tip.

Are there any other general pointers you might give for that regex? The lines 
I'm trying to match look something like this:

07:40:05.793627975 [Info  ] [SOME_MODULE] [SOME_FUNCTION] [SOME_OTHER_FLAG] 
[RequestTag=0 ErrorCode=3 ErrorText="some error message" 
ID=0:0x Foo=1 Bar=5 Joe=5]

Essentially, I'd want to strip out the timestamp, logging-level, module, 
function etc - and possibly the tag-value pairs?

And yes, based on what you said, I probably will use the "in" loop first 
outside the regex - the lines I'm searching for are fairly few compared to the 
overall log size.

Cheers,
Victor

On Thursday, 13 December 2012 12:09:33 UTC+11, Steven D'Aprano  wrote:
> On Wed, 12 Dec 2012 14:35:41 -0800, Victor Hooi wrote:
> 
> 
> 
> > Hi,
> 
> > 
> 
> > I have a script that trawls through log files looking for certain error
> 
> > conditions. These are identified via certain keywords (all different) in
> 
> > those lines
> 
> > 
> 
> > I then process those lines using regex groups to extract certain fields.
> 
> [...]
> 
> > Also, my regexs could possibly be tuned, they look something like this:
> 
> > 
> 
> > (?P\d{2}:\d{2}:\d{2}.\d{9})\s*\[(?P\w+)\s*
> 
> \]\s*\[(?P\w+)\s*\]\s*\[{0,1}\]{0,1}\s*\[(?P\w+)\s*\]
> 
> \s*level\(\d\) broadcast\s*\(\[(?P\w+)\]\s*\[(?P\w+)\]
> 
> \s*(?P\w{4}):(?P\w+) failed order: (?P\w+) (?
> 
> P\d+) @ (?P[\d.]+), error on update \(\d+ : Some error 
> 
> string. Active Orders=(?P\d+) Limit=(?P\d+)\)\)
> 
> >
> 
> > (Feel free to suggest any tuning, if you think they need it).
> 
> 
> 
> "Tuning"? I think it needs to be taken out and killed with a stake to the 
> 
> heart, then buried in concrete! :-)
> 
> 
> 
> An appropriate quote:
> 
> 
> 
> Some people, when confronted with a problem, think "I know, 
> 
> I'll use regular expressions." Now they have two problems.
> 
> -- Jamie Zawinski
> 
> 
> 
> Is this actually meant to be a single regex, or did your email somehow 
> 
> mangle multiple regexes into a single line?
> 
> 
> 
> At the very least, you should write your regexes using the VERBOSE flag, 
> 
> so you can use non-significant whitespace and comments. There is no 
> 
> performance cost to using VERBOSE once they are compiled, but a huge 
> 
> maintainability benefit.
> 
> 
> 
> 
> 
> > My question is - I've heard that using the "in" membership operator is
> 
> > substantially faster than using Python regexes.
> 
> > 
> 
> > Is this true? What is the technical explanation for this? And what sort
> 
> > of performance characteristics are there between the two?
> 
> 
> 
> Yes, it is true. The technical explanation is simple:
> 
> 
> 
> * the "in" operator implements simple substring matching, 
> 
>   which is trivial to perform and fast;
> 
> 
> 
> * regexes are an interpreted mini-language which operate via
> 
>   a complex state machine that needs to do a lot of work,
> 
>   which is complicated to perform and slow.
> 
> 
> 
> Python's regex engine is not as finely tuned as (say) Perl's, but even in 
> 
> Perl simple substring matching ought to be faster, simply because you are 
> 
> doing less work to match a substring than to run a regex.
> 
> 
> 
> But the real advantage to using "in" is readability and maintainability.
> 
> 
> 
> As for the performance characteristics, you really need to do your own 
> 
> testing. Performance will depend on what you are searching for, where you 
> 
> are searching for it, whether it is found or not, your version of Python, 
> 
> your operating system, your hardware.
> 
> 
> 
> At some level of complexity, you are better off just using a regex rather 
> 
> than implementing your own buggy, complicated expression matcher: for 
> 
> some matching tasks, there is no reasonable substitute to regexes. But 
> 
> for *simple* uses, you should prefer *simple* code:
> 
> 
> 
> [steve@ando ~]$ python -m timeit \
> 
> > -s "data = 'abcd'*1000 + 'xyz' + 'abcd'*1000" \
> 
> > "'xyz' in data"
> 
> 10 loops, best of 3: 4.17 usec per loop
> 
> 
> 
> [steve@ando ~]$ python -m timeit \
> 
> > -s "data = 'abcd'*1000 + 'xyz' + 'abcd'*1000" \
> 
> > -s "from re import search" \
> 
> > "search('xyz', data)"
> 
> 10 loops, best of 3: 10.9 usec per loop
> 
> 
> 
> 
> 
> 
> 
> > (I couldn't find much in the way of docs for "in", just the brief
> 
> > mention here -
> 
> > http://docs.python.org/2/reference/expressions.html#not-in )
> 
> > 
> 
> > Would I be substantially better off using a list of strings and using
> 
> > "in" against each line, then using a second pass of regex only on the
> 
> > matched lines?
> 
> 
> 
> That's hard to say. It depends on whether you are matching on a substring 
> 
> that will frequently be found close to the start of each line, or 
> 
> something else.
> 
> 
> 
> Where I expect you *w

Re: Using regexes versus "in" membership test?

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 5:10 PM, Victor Hooi  wrote:
> Are there any other general pointers you might give for that regex? The lines 
> I'm trying to match look something like this:
>
> 07:40:05.793627975 [Info  ] [SOME_MODULE] [SOME_FUNCTION] 
> [SOME_OTHER_FLAG] [RequestTag=0 ErrorCode=3 ErrorText="some error message" 
> ID=0:0x Foo=1 Bar=5 Joe=5]
>
> Essentially, I'd want to strip out the timestamp, logging-level, module, 
> function etc - and possibly the tag-value pairs?

If possible, can you do a simple test to find out whether or not you
want a line and then do more complex parsing to get the info you want
out of it? For instance, perhaps the presence of the word "ErrorCode"
is all you need to check - it wouldn't hurt if you have a few percent
of false positives that get discarded during the parse phase, it'll
still be quicker to do a single string-in-string check than a complex
regex to figure out if you even need to process the line at all.

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


Re: why does dead code costs time?

2012-12-12 Thread rusi
On Dec 13, 11:01 am, Steven D'Aprano  wrote:
> On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:
> >> Cheers.
>
> >> Mark Lawrence.
>
> > haha. What does "Cheers" mean?
>
> It is an exclamation expressing good wishes. In particular, good wishes
> before drinking. Think of it as a variation on:
>
> "Good health to you"
> "Best wishes"
> "Sincerest regards"
>
> only less formal.
>
> Does the Internet not work where you are? Googling for "define:cheers" or
> "definition cheers" should have answered that question.
>
> --
> Steven

One line above the "cheers" (with a double-space ) we find:

> Double spaced crap from you again not so haha.

Do you find the sentiment expressed therein consistent with any of
your three meanings?

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


Re: Using regexes versus "in" membership test?

2012-12-12 Thread Victor Hooi
Heya,

See my original first post =):

> Would I be substantially better off using a list of strings and using "in" 
> against each line, then using a second pass of regex only on the matched 
> lines? 

Based on what Steven said, and what I know about the logs in question, it's 
definitely better to do it that way.

However, I'd still like to fix up the regex, or fix any glaring issues with it 
as well.

Cheers,
Victor

On Thursday, 13 December 2012 17:19:57 UTC+11, Chris Angelico  wrote:
> On Thu, Dec 13, 2012 at 5:10 PM, Victor Hooi  wrote:
> 
> > Are there any other general pointers you might give for that regex? The 
> > lines I'm trying to match look something like this:
> 
> >
> 
> > 07:40:05.793627975 [Info  ] [SOME_MODULE] [SOME_FUNCTION] 
> > [SOME_OTHER_FLAG] [RequestTag=0 ErrorCode=3 ErrorText="some error message" 
> > ID=0:0x Foo=1 Bar=5 Joe=5]
> 
> >
> 
> > Essentially, I'd want to strip out the timestamp, logging-level, module, 
> > function etc - and possibly the tag-value pairs?
> 
> 
> 
> If possible, can you do a simple test to find out whether or not you
> 
> want a line and then do more complex parsing to get the info you want
> 
> out of it? For instance, perhaps the presence of the word "ErrorCode"
> 
> is all you need to check - it wouldn't hurt if you have a few percent
> 
> of false positives that get discarded during the parse phase, it'll
> 
> still be quicker to do a single string-in-string check than a complex
> 
> regex to figure out if you even need to process the line at all.
> 
> 
> 
> ChrisA

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


Re: Using regexes versus "in" membership test?

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 5:35 PM, Victor Hooi  wrote:
> Heya,
>
> See my original first post =):
>

Oops! Mea culpa. Yes, you did say that. And then definitely, if it's a
one-keyword search for each and then the regex to parse, that would be
much more efficient than using the regex to pick lines.

Sorry! I didn't read it properly.

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


Re: why does dead code costs time?

2012-12-12 Thread Cameron Simpson
On 12Dec2012 22:27, rusi  wrote:
| On Dec 13, 11:01 am, Steven D'Aprano  wrote:
| > On Wed, 12 Dec 2012 21:23:47 -0800, Ramchandra Apte wrote:
| > >> Cheers.
| > >> Mark Lawrence.
| >
| > > haha. What does "Cheers" mean?
| >
| > It is an exclamation expressing good wishes. In particular, good wishes
| > before drinking. [...]
|
| One line above the "cheers" (with a double-space ) we find:
| 
| > Double spaced crap from you again not so haha.
| 
| Do you find the sentiment expressed therein consistent with any of
| your three meanings?

Nope. But they're separate sentiments (weasel words:-)

I tend to end messages with "Cheers" myself. Though I also tend to strip
it out if I am being annoyed. As you say, it is inconsistent.

Cheers,
-- 
Cameron Simpson 

It looked good-natured, she thought;  Still it had very long claws and a
great many teeth, so she felt it ought to be treated with respect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why does dead code costs time?

2012-12-12 Thread rusi
On Dec 13, 11:51 am, Cameron Simpson  wrote:
> It looked good-natured, she thought;  Still it had very long claws and a
> great many teeth, so she felt it ought to be treated with respect.

heh!

If only we could respect without such coercion(s)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why does dead code costs time?

2012-12-12 Thread Chris Angelico
On Thu, Dec 13, 2012 at 5:59 PM, rusi  wrote:
> On Dec 13, 11:51 am, Cameron Simpson  wrote:
>> It looked good-natured, she thought;  Still it had very long claws and a
>> great many teeth, so she felt it ought to be treated with respect.
>
> heh!
>
> If only we could respect without such coercion(s)

Even if you don't respect his claws and teeth, you should respect the
fact that, as he says, "we're all mad here"...

But this is quite off topic, both off the thread's subject line and
the list's purpose.

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


Re: MySQLdb compare lower

2012-12-12 Thread Cameron Simpson
On 12Dec2012 02:03, Dennis Lee Bieber  wrote:
|   According to the old "MySQL Language Reference" 
| """
| By default, string comparisons are not case sensitive and will use the
| current character set (ISO-8859-1 Latin1 by default, which also works
| excellently for English).
| """

I'm flabbergasted. [... consults the internets ...] It is still the case
today:-( Ouch.

Thank you for this reality check.
-- 
Cameron Simpson 

Outside of a dog, a book is a man's best friend.  Inside of a dog, it's too
dark to read. - Groucho Marx
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with calling function from dll

2012-12-12 Thread deepblu
I have problem with using function from dll.

import ctypes

b = ctypes.windll.LoadLibrary("kernel32")

a = ""

b.GetComputerNameA(a,20)


But I got exception:

Traceback (most recent call last):
  File "", line 1, in 
b.GetComputerNameA(a,20)
WindowsError: exception: access violation reading 0x0014

Even when I write:
a = ctypes.c_char_p('.' * 20)
I got the same result.

Here I found this function description:
http://sd2cx1.webring.org/l/rd?ring=pbring;id=15;url=http%3A%2F%2Fwww.astercity.net%2F~azakrze3%2Fhtml%2Fwin32_api_functios.html


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