Re: Is Python a commercial proposition ?

2012-08-02 Thread Mark Lawrence

On 02/08/2012 04:10, David wrote:

On 01/08/2012, Stefan Behnel  wrote:


Would you mind taking this slightly off-topic discussion off the list?


I always strive to stay on-topic. In fact immediately this thread went
off topic, 4 messages back, I did try to go off list, but got this
result from the OP:

Delivery to the following recipient failed permanently:
  lip...@yahoo.co.uk
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the
recipient domain. We recommend contacting the other email provider for
further information about the cause of this error. The error that the
other server returned was: 554 554 delivery error: dd This user
doesn't have a yahoo.co.uk account (lip...@yahoo.co.uk) [-5] -
mta1050.mail.ukl.yahoo.com (state 17).
Date: Wed, 1 Aug 2012 09:31:43 +1000
Subject: Re: Is Python a commercial proposition ?
From: David 
To: lipska the kat 

Then, if someone is going to call me an ignoramus on a public list,
they will receive a response in the same forum.

So, I apologise to the list, but please note the unusual circumstances. Thanks.



I'm in stuck record mode here, but one of the things I really enjoy 
about reading here is the way things do go off topic.  IMHO makes for a 
far more interesting experience.  YMMV.


--
Cheers.

Mark Lawrence.

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


Re: Is Python a commercial proposition ?

2012-08-02 Thread lipska the kat

On 02/08/12 04:10, David wrote:

On 01/08/2012, Stefan Behnel  wrote:


Would you mind taking this slightly off-topic discussion off the list?


I always strive to stay on-topic. In fact immediately this thread went
off topic, 4 messages back, I did try to go off list, but got this
result from the OP:

Delivery to the following recipient failed permanently:
  lip...@yahoo.co.uk


snip

This is my fault, I set the reply to address incorrectly. You HAVE 
corresponded successfully with me in the past however... I apologise for 
the inconvenience.


JFTR I did not call you an ignoramus (it's a funny word though isn't it, 
makes me smile anyway).


lipska

--
Lipska the Kat: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
--
http://mail.python.org/mailman/listinfo/python-list


C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
I am implementing a C extension module, during this I saw that when I set the 
global error indicator and error message through PyErr_SetString() API and 
return false.

But it doesn't throw any error when I tried to check the error through 
sys.exc_info() then it returns (NULL, NULL, NULL) tuple. 

When I return NULL through the C extension module's function then it works 
correctly and throws the exception as expected.

The skeleton looks like:

static PyObject* check(PyObject* sef, PyObject* args)
{
PyObject* input = NULL;
if (!PyArg_ParseTuple(args, "O", &input)){
 return NULL;
}
.
.
PyErr_SetString(PyExc_Exception, "Throwing Error through check 
function");
Py_RETURN_FALSE;
}

Any idea on why this is happening? Any help will be appreciated.

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


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 09:57, rahul wrote:
> I am implementing a C extension module, during this I saw that when I
> set the global error indicator and error message through
> PyErr_SetString() API and return false.
> 
> But it doesn't throw any error when I tried to check the error
> through sys.exc_info() then it returns (NULL, NULL, NULL) tuple.
> 
> When I return NULL through the C extension module's function then it
> works correctly and throws the exception as expected.
> 
> The skeleton looks like:
> 
> static PyObject* check(PyObject* sef, PyObject* args) { PyObject*
> input = NULL; if (!PyArg_ParseTuple(args, "O", &input)){ return
> NULL; } . . PyErr_SetString(PyExc_Exception, "Throwing Error
> through check function"); Py_RETURN_FALSE; }
> 
> Any idea on why this is happening? Any help will be appreciated.


Because you're returning False. You should be returning NULL. Which is
why it works when you do :)

Have a look at the first line of this page:

http://docs.python.org/py3k/extending/extending.html#intermezzo-errors-and-exceptions


Which piece of documentation led you to think that returning False was
the thing to do here? Perhaps there's a doc that needs fixing?


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


Re: CRC-checksum failed in gzip

2012-08-02 Thread Ulrich Eckhardt

Am 01.08.2012 19:57, schrieb Laszlo Nagy:

## Open file
lock = threading.Lock()
fin = gzip.open(file_path...)
# Now you can share the file object between threads.

# and do this inside any thread:
## data needed. block until the file object becomes usable.
with lock:
 data = fin.read() # other threads are blocked while I'm reading
## use your data here, meanwhile other threads can read


Technically, that is correct, but IMHO its complete nonsense to share 
the file object between threads in the first place. If you need the data 
in two threads, just read the file once and then share the read-only, 
immutable content. If the file is small or too large to be held in 
memory at once, just open and read it on demand. This also saves you 
from having to rewind the file every time you read it.


Am I missing something?

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


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul

Hi TJG,

The above link also doesn't strictly said that return value should be NULL 
only, it only said that usually NULL pointer used. No where I saw that it is 
nessasory t

At http://docs.python.org/c-api/exceptions.html. it is written that "Most 
functions also return an error indicator, usually NULL if they are supposed to 
return a pointer, or -1 if they return an integer (exception: the PyArg_*() 
functions return 1 for success and 0 for failure)." this also told that usually 
NULL is used but we can change the return error indicator to any value. As like 
PyArg_*() used 0 for error value.

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


Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/1 Steven D'Aprano :
>
> When you start using threads, you have to expect these sorts of
> intermittent bugs unless you are very careful.
>
> My guess is that you have a bug where two threads read from the same file
> at the same time. Since each read shares state (the position of the file
> pointer), you're going to get corruption. Because it depends on timing
> details of which threads do what at exactly which microsecond, the effect
> might as well be random.
>
> Example: suppose the file contains three blocks A B and C, and a
> checksum. Thread 8 starts reading the file, and gets block A and B. Then
> thread 2 starts reading it as well, and gets half of block C. Thread 8
> gets the rest of block C, calculates the checksum, and it doesn't match.
>
> I recommend that you run a file system check on the remote disk. If it
> passes, you can eliminate file system corruption. Also, run some network
> diagnostics, to eliminate corruption introduced in the network layer. But
> I expect that you won't find anything there, and the problem is a simple
> thread bug. Simple, but really, really hard to find.
>
> Good luck.

One last thing I would like to do before I add this fix is to actually
be able to reproduce this behaviour, and I thought I could just do the
following:

import gzip
import threading


class OpenAndRead(threading.Thread):
def run(self):
fz = gzip.open('out2.txt.gz')
fz.read()
fz.close()


if __name__ == '__main__':
for i in range(100):
OpenAndRead().start()


But no matter how many threads I start, I can't reproduce the CRC
error, any idea how I can try to help it happening?

The code in run should be shared by all the threads since there are no
locks, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 10:21, rahul wrote:
> 
> Hi TJG,
> 
> The above link also doesn't strictly said that return value should be
> NULL only, it only said that usually NULL pointer used. No where I
> saw that it is nessasory t
> 
> At http://docs.python.org/c-api/exceptions.html. it is written that
> "Most functions also return an error indicator, usually NULL if they
> are supposed to return a pointer, or -1 if they return an integer
> (exception: the PyArg_*() functions return 1 for success and 0 for
> failure)." this also told that usually NULL is used but we can change
> the return error indicator to any value. As like PyArg_*() used 0 for
> error value.

The docs you quote are very slightly confusing because they're combining
the standard practice (return NULL), the uncommon alternative (return
-1) and a few special cases present in the core functions.

In short, any function you expose in an extension module will be
returning a PyObject* and should return NULL if it is setting or
cascading an exception.

I'm not convinced that the docs need altering here: this is the first
time I've come across anyone who was confused. But if you think some
different wording might help, feel free to propose something.

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


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread rahul
When I use same code base for Python 3.x, then behavior is different. In this 
when I return false then also it throws exception but only when any other 
statement get executed after this 

like below code:
 ...
 ...
   b = None
   try:
 a = testModule.check(None)
   except:
 b = sys.exc_info()
then code execution doesn't come to except block.
But when I add one statement after calling check function then code execution 
goes into except block. 

 ...
 ...
 b = None
 try:
   a = testModule.check(None)
   print( a )
 except:
   b = sys.exc_info()


On Thursday, 2 August 2012 15:07:08 UTC+5:30, Tim Golden  wrote:
> On 02/08/2012 10:21, rahul wrote:
> 
> > 
> 
> > Hi TJG,
> 
> > 
> 
> > The above link also doesn't strictly said that return value should be
> 
> > NULL only, it only said that usually NULL pointer used. No where I
> 
> > saw that it is nessasory t
> 
> > 
> 
> > At http://docs.python.org/c-api/exceptions.html. it is written that
> 
> > "Most functions also return an error indicator, usually NULL if they
> 
> > are supposed to return a pointer, or -1 if they return an integer
> 
> > (exception: the PyArg_*() functions return 1 for success and 0 for
> 
> > failure)." this also told that usually NULL is used but we can change
> 
> > the return error indicator to any value. As like PyArg_*() used 0 for
> 
> > error value.
> 
> 
> 
> The docs you quote are very slightly confusing because they're combining
> 
> the standard practice (return NULL), the uncommon alternative (return
> 
> -1) and a few special cases present in the core functions.
> 
> 
> 
> In short, any function you expose in an extension module will be
> 
> returning a PyObject* and should return NULL if it is setting or
> 
> cascading an exception.
> 
> 
> 
> I'm not convinced that the docs need altering here: this is the first
> 
> time I've come across anyone who was confused. But if you think some
> 
> different wording might help, feel free to propose something.
> 
> 
> 
> TJG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CRC-checksum failed in gzip

2012-08-02 Thread Laszlo Nagy


Technically, that is correct, but IMHO its complete nonsense to share 
the file object between threads in the first place. If you need the 
data in two threads, just read the file once and then share the 
read-only, immutable content. If the file is small or too large to be 
held in memory at once, just open and read it on demand. This also 
saves you from having to rewind the file every time you read it.


Am I missing something?
We suspect that his program reads the same file object from different 
threads. At least this would explain his problem. I agree with you - 
usually it is not a good idea to share a file object between threads. 
This is what I told him the first time. But it is not in our hands - he 
already has a program that needs to be fixed. It might be easier for him 
to protect read() calls with a lock. Because it can be done 
automatically, without thinking too much.

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


consistent input() for Python 2 and 3

2012-08-02 Thread Ulrich Eckhardt

Hi!

I'm trying to write some code that should work with both Python 2 and 3. 
One of the problems there is that the input() function has different 
meanings, I just need the raw_input() behaviour of Python 2.



My approach is to simply do this:

  try:
  # redirect input() to raw_input() like Python 3
  input = raw_input
  except NameError:
  # no raw input, probably running Python 3 already
  pass


What do you think? Any better alternatives?

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


Re: CRC-checksum failed in gzip

2012-08-02 Thread Laszlo Nagy



One last thing I would like to do before I add this fix is to actually
be able to reproduce this behaviour, and I thought I could just do the
following:

import gzip
import threading


class OpenAndRead(threading.Thread):
 def run(self):
 fz = gzip.open('out2.txt.gz')
 fz.read()
 fz.close()


if __name__ == '__main__':
 for i in range(100):
 OpenAndRead().start()


But no matter how many threads I start, I can't reproduce the CRC
error, any idea how I can try to help it happening?
Your example did not share the file object between threads. Here an 
example that does that:


class OpenAndRead(threading.Thread):
def run(self):
global fz
fz.read(100)

if __name__ == '__main__':
   fz = gzip.open('out2.txt.gz')
   for i in range(10):
OpenAndRead().start()

Try this with a huge file. And here is the one that should never throw 
CRC error, because the file object is protected by a lock:


class OpenAndRead(threading.Thread):
def run(self):
global fz
global fl
with fl:
fz.read(100)

if __name__ == '__main__':
   fz = gzip.open('out2.txt.gz')
   fl = threading.Lock()
   for i in range(2):
OpenAndRead().start()



The code in run should be shared by all the threads since there are no
locks, right?
The code is shared but the file object is not. In your example, a new 
file object is created, every time a thread is started.


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


attribute is accessed from Nonetype

2012-08-02 Thread Shanth Kumar
Hi ,All,
I am Shanthkumar. Good to see the mailing list for python programmers.
Please find my query below,

In my source code in a python file e.g xyz.py couple of classes are defined
also there is a wrapper class, a none object is declared in the file e.g
temp=None
from temp some attributes are being accessed in the files that are
importing xyz.py
even though temp is not initialised to any other object still it is none
object attributes are being accessed from None object.Is there any
significance of wrapper class here..?
Can you please help me.

-- 
Regards...,
Shanthkumara O.D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Tim Golden
On 02/08/2012 10:50, rahul wrote:
> When I use same code base for Python 3.x, then behavior is different. In this 
> when I return false then also it throws exception but only when any other 
> statement get executed after this 
> 
> like below code:
>  ...
>  ...
>b = None
>try:
>  a = testModule.check(None)
>except:
>  b = sys.exc_info()
> then code execution doesn't come to except block.
> But when I add one statement after calling check function then code execution 
> goes into except block. 
> 
>  ...
>  ...
>  b = None
>  try:
>a = testModule.check(None)
>print( a )
>  except:
>b = sys.exc_info()


Sounds like you're entering into undefined behaviour. If you set an
exception and don't return NULL, you're leaving Python's internals in an
inconsistent state. I don't know the internal code paths, but presumably
in one version it just ignored the exception state while in the other it
noticed it but in a different point in the code at which point it raised
the exception. Or something.

Long-and-short: return NULL from an extension module function once
you've raised (or are cascading) an exception condition. Anything else
is undefined unless you know *exactly* what you're doing.


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


Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

2012-08-02 Thread Stefan Behnel
rahul, 02.08.2012 11:50:
> When I use same code base for Python 3.x, then behavior is different.

You might want to take a look at Cython. It moves most of these "funny"
little details off your shoulders.

Stefan


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


Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/2 Laszlo Nagy :
>
> Your example did not share the file object between threads. Here an example
> that does that:
>
> class OpenAndRead(threading.Thread):
> def run(self):
> global fz
> fz.read(100)
>
> if __name__ == '__main__':
>
>fz = gzip.open('out2.txt.gz')
>for i in range(10):
> OpenAndRead().start()
>
> Try this with a huge file. And here is the one that should never throw CRC
> error, because the file object is protected by a lock:
>
> class OpenAndRead(threading.Thread):
> def run(self):
> global fz
> global fl
> with fl:
> fz.read(100)
>
> if __name__ == '__main__':
>
>fz = gzip.open('out2.txt.gz')
>fl = threading.Lock()
>for i in range(2):
> OpenAndRead().start()
>
>
>>
>> The code in run should be shared by all the threads since there are no
>> locks, right?
>
> The code is shared but the file object is not. In your example, a new file
> object is created, every time a thread is started.
>


Ok sure that makes sense, but then this explanation is maybe not right
anymore, because I'm quite sure that the file object is *not* shared
between threads, everything happens inside a thread..

I managed to get some errors doing this with a big file
class OpenAndRead(threading.Thread):
 def run(self):
 global fz
 fz.read(100)

if __name__ == '__main__':

fz = gzip.open('bigfile.avi.gz')
for i in range(20):
 OpenAndRead().start()

and it doesn't fail without the *global*, but this is definitively not
what the code does, because every thread gets a new file object, it's
not shared..

Anyway we'll read once for all the threads or add the lock, and
hopefully it should solve the problem, even if I'm not convinced yet
that it was this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/2 andrea crotti :
>
> Ok sure that makes sense, but then this explanation is maybe not right
> anymore, because I'm quite sure that the file object is *not* shared
> between threads, everything happens inside a thread..
>
> I managed to get some errors doing this with a big file
> class OpenAndRead(threading.Thread):
>  def run(self):
>  global fz
>  fz.read(100)
>
> if __name__ == '__main__':
>
> fz = gzip.open('bigfile.avi.gz')
> for i in range(20):
>  OpenAndRead().start()
>
> and it doesn't fail without the *global*, but this is definitively not
> what the code does, because every thread gets a new file object, it's
> not shared..
>
> Anyway we'll read once for all the threads or add the lock, and
> hopefully it should solve the problem, even if I'm not convinced yet
> that it was this.


Just for completeness as suggested this also does not fail:

class OpenAndRead(threading.Thread):
def __init__(self, lock):
threading.Thread.__init__(self)
self.lock = lock

def run(self):
 global fz
 with self.lock:
 fz.read(100)

if __name__ == '__main__':
lock = threading.Lock()
fz = gzip.open('bigfile.avi.gz')
for i in range(20):
 OpenAndRead(lock).start()
-- 
http://mail.python.org/mailman/listinfo/python-list


Error help

2012-08-02 Thread danielashiloh
Hi all

This error has been bugging me for days. I know it's minor, but it's really 
getting in the way of my programming. I'm programming a data analysis programme 
for a psychology experiment which takes pickled data from the experiment and 
produces averages. For some reason python is insisting there is an indentation 
error on line 18. I have untabified and retabified and nothing seems to work. 
Here is the full code:


import cPickle, pickle

print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST'
file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
pickle_file=open(file, 'r')
data=cPickle.load(pickle_file)
file_name=file-'pck' + 'txt'
partifipant_info=data'Participant Info']
first_block_data=data['First block data']
second_block_data=data['Second block data']
first_block_estimates=first_block_data['Estimated times']
first_block_times=first_block_data['Actual times']
second_block_estimates=second_block_data['Estimated times']
second_block_times=second_block_data['Actual times']


def firstBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' 
count=0
first_block_differences=[]
total=0
while count= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
first_block_differences+=differences
count+=1
average_diff_first_block=total/len(first_block_estimates)
text_file.write('\nAverage differences for block 1: ', 
average_diff_first_block)

def secondBlockDifferences():
print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2'
count=0
second_block_differences=[]
total=0
while count= 180:
differences-=360
elif differences <=-180:
differences+=360
total+=differences
differences=[differences]
second_block_differences+=differences
count+=1
average_diff_second_block=total/len(second_block_estimates)
text_file.write('\nAverage differences for block 2: ', 
average_diff_second_block)


text_file=open(file_name, 'w')
text_file.write('\nParticipant info: ', participant_info)
firstBlockDifferences()
secondBlockDifferences()

I apologise for the lack of annotation and it may be a little inefficient, but 
I am really only after a solution to the error on line 18.

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


Re: attribute is accessed from Nonetype

2012-08-02 Thread Dave Angel
On 08/02/2012 06:28 AM, Shanth Kumar wrote:
> Hi ,All,
> I am Shanthkumar. Good to see the mailing list for python programmers.

Welcome to the list.

> Please find my query below,
>
> In my source code in a python file e.g xyz.py couple of classes are defined
> also there is a wrapper class, a none object is declared in the file e.g
> temp=None
> from temp some attributes are being accessed in the files that are
> importing xyz.py
> even though temp is not initialised to any other object still it is none
> object attributes are being accessed from None object.Is there any
> significance of wrapper class here..?
> Can you please help me.
>
>
Once you actually supply some code.  Build a small example illustrating
your problem, and explain better what is wrong/unexpected with how it
works.  If an import of xyz.py is necessary, then show both files.

Are you surprised that the None object has attributes?  It has at least
15 in Python 2.7.   Or are you surprised that temp is different in other
modules than it is in xyz.py ?  Or are you surprised that wrapping a
NoneType is possible?

Also, please use the names correctly and consistently.  The None object
(yes, there is only one) is not the same as a none object.  And there is
no standard type called Nonetype.

Finally, please avoid runon sentences.  By the time we parse where the
periods are supposed to be, we just may lose the meaning you had in mind.



-- 

DaveA

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


Re: consistent input() for Python 2 and 3

2012-08-02 Thread Philipp Hagemeister
On 08/02/2012 11:49 AM, Ulrich Eckhardt wrote:
>   try:
>   # redirect input() to raw_input() like Python 3
>   input = raw_input
>   except NameError:
>   # no raw input, probably running Python 3 already
>   pass
> What do you think? Any better alternatives?

That's the generic solution, see
http://python3porting.com/differences.html#input-and-raw-input .

In my experience, it seems that input's main function is to allow
beginners to learn the language, or to be used in short scripts. For a
serious application, either curses or moving the input to the invocation
arguments is often a better choice.

- Philipp



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error help

2012-08-02 Thread Peter Otten
danielashi...@googlemail.com wrote:

> This error has been bugging me for days. I know it's minor, but it's
> really getting in the way of my programming. I'm programming a data
> analysis programme for a psychology experiment which takes pickled data
> from the experiment and produces averages. For some reason python is
> insisting there is an indentation error on line 18. 

I can't confirm that, I get an error in line 8

> partifipant_info=data'Participant Info']

where you forgot the opening '['. 

Please post your actual code and don't forget to include a cut-and-paste 
version of the traceback you get.

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


Re: Error help

2012-08-02 Thread marmata
Hi,

> This error has been bugging me for days.

Doesn't look like a tab error but:

> partifipant_info=data'Participant Info']

This line is wrong, it should be:

partifipant_info=data['Participant Info']

That's probably what's triggering the error!

Cheers,
]\/[arco
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error help

2012-08-02 Thread Dave Angel
On 08/02/2012 06:58 AM, danielashi...@googlemail.com wrote:
> Hi all
>
> This error has been bugging me for days. I know it's minor, but it's really 
> getting in the way of my programming. I'm programming a data analysis 
> programme for a psychology experiment which takes pickled data from the 
> experiment and produces averages. For some reason python is insisting there 
> is an indentation error on line 18. I have untabified and retabified and 
> nothing seems to work. Here is the full code:
>
>
> import cPickle, pickle
>
> print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST'
> file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
> pickle_file=open(file, 'r')
> data=cPickle.load(pickle_file)
> file_name=file-'pck' + 'txt'
> partifipant_info=data'Participant Info']
> first_block_data=data['First block data']
> second_block_data=data['Second block data']
> first_block_estimates=first_block_data['Estimated times']
> first_block_times=first_block_data['Actual times']
> second_block_estimates=second_block_data['Estimated times']
> second_block_times=second_block_data['Actual times']
>
>
> def firstBlockDifferences():
> print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' 
> count=0
> first_block_differences=[]
> total=0
> while count 
> differences=float(first_block_estimates[count])-float(first_block_times[count])
> if differences >= 180:
> differences-=360
> elif differences <=-180:
> differences+=360
> total+=differences
> differences=[differences]
> first_block_differences+=differences
> count+=1
> average_diff_first_block=total/len(first_block_estimates)
> text_file.write('\nAverage differences for block 1: ', 
> average_diff_first_block)
>
> def secondBlockDifferences():
> print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 2'
> count=0
> second_block_differences=[]
> total=0
> while count 
> differences=float(second_block_estimates[count])-float(second_block_times[count])
> if differences >= 180:
> differences-=360
> elif differences <=-180:
> differences+=360
> total+=differences
> differences=[differences]
> second_block_differences+=differences
> count+=1
> average_diff_second_block=total/len(second_block_estimates)
> text_file.write('\nAverage differences for block 2: ', 
> average_diff_second_block)
>
>
> text_file=open(file_name, 'w')
> text_file.write('\nParticipant info: ', participant_info)
> firstBlockDifferences()
> secondBlockDifferences()
>
> I apologise for the lack of annotation and it may be a little inefficient, 
> but I am really only after a solution to the error on line 18.
>
> Thanks.

You didn't include the error message, so how are we supposed to know
which line is #18 ?  if I take your message literally, it's a blank line.

Even better, you could have reduced the code down to a minimum which
still shows the error.

As your code stands now, I get an error on line 10:

 File "daniel.py", line 10
partifipant_info=data'Participant Info']
  ^
SyntaxError: invalid syntax

It appears you're missing a left bracket.

That line also has a strange spelling for participant, so you'd get an
error later when you tried to use participant_info.   Did you by any
chance retype your program into the message?  If you don't use
copy/paste, it's useless for us to study your code.

Finally, in case it matters, just what version of python did you use,
and on what OS?

-- 

DaveA

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


Re: Error help

2012-08-02 Thread Philipp Hagemeister
Let's go thorugh this program:

On 08/02/2012 12:58 PM, danielashi...@googlemail.com wrote:
> import cPickle, pickle
you probably want to transparently fall back to pickle if cPickle is not
available.

> print 'WELLCOME TO THE LIBET CLOCK EXPERIMENT DATA ANALYSIST'
> file=raw_input('\nPLEASE ENTER THE NAME OF THE FILE YOU WISH TO ANALYSE: ')
This should be a command-line option. Look for optparse, or use sys.argv[1]

> pickle_file=open(file, 'r')
> data=cPickle.load(pickle_file)
You're opening a file in text mode, and leaking the handle.

> file_name=file-'pck' + 'txt'
You cannot subtract strings. You probably want to use + . Also, move
this assignment down to where it's needed

> partifipant_info=data'Participant Info']
You later use participant_info. typo?

> first_block_data=data['First block data']
> second_block_data=data['Second block data']
> first_block_estimates=first_block_data['Estimated times']
> first_block_times=first_block_data['Actual times']
> second_block_estimates=second_block_data['Estimated times']
> second_block_times=second_block_data['Actual times']

This is not a useful data structure. You want:

blocks = [{
  'estimates': data[name]['Estimated times'],
  'actuals': data[name]['Actual Times'],
} for name in ["First block data", "Second block data"}]

or better yet, a sane pickle format.

> def firstBlockDifferences():
This method should be called blockDifferences, and take a block as an
argument, and return differenes. See
http://docs.python.org/tutorial/controlflow.html#defining-functions for
an introduction.

> print '\nCALCULATING AVERAGE DIFFERENCES FOR BLOCK 1' 
This belongs in the calling method.

> count=0
> first_block_differences=[]
> total=0
> while count 
> differences=float(first_block_estimates[count])-float(first_block_times[count])
> if differences >= 180:
> differences-=360
> elif differences <=-180:
> differences+=360
What if the value is larger than 540 or smaller than -540?
> total+=differences

> differences=[differences]
This line looks strange. Please use another variable name for values of
another type.

> first_block_differences+=differences
If that's all there is to this function, have a look at writing a
generator. If you delete the previous line, you can also write jsut
first_block_differences.append(differences)

> count+=1
Not required if you use zip above.

> average_diff_first_block=total/len(first_block_estimates)
> text_file.write('\nAverage differences for block 1: ', 
> average_diff_first_block)
These two lines don't look as if they belong in this method. Better
write another one that wraps the calculation and outputs stuff.

> 
> def secondBlockDifferences():
Instead of writing two methods to do the same thing, write one with
arguments.
> (...)

> text_file=open(file_name, 'w')
You're leaking the handle. Use with(open(file_name, 'w')) as text_file: .

> text_file.write('\nParticipant info: ', participant_info)
> firstBlockDifferences()
> secondBlockDifferences()



- Philipp




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: consistent input() for Python 2 and 3

2012-08-02 Thread Jason Swails
On Thu, Aug 2, 2012 at 5:49 AM, Ulrich Eckhardt <
ulrich.eckha...@dominolaser.com> wrote:

> Hi!
>
> I'm trying to write some code that should work with both Python 2 and 3.
> One of the problems there is that the input() function has different
> meanings, I just need the raw_input() behaviour of Python 2.
>
>
> My approach is to simply do this:
>
>   try:
>   # redirect input() to raw_input() like Python 3
>   input = raw_input
>   except NameError:
>   # no raw input, probably running Python 3 already
>   pass
>
>
> What do you think? Any better alternatives?
>

Depending on how much user input is needed in your application, you can
always use the 'cmd' module: http://docs.python.org/library/cmd.html

It is present in both Python 2 and Python 3 and should just 'do the right
thing'.  It also seamlessly integrates readline (if present),
command-completion, and provides a built-in help menu for defined commands.

It's written in pure Python, and in my opinion, the best form of
documentation for that module is the source code itself.

I haven't used it in Python 3, but I imagine it can be used in a way that
easily supports Python 2 and 3.  If you have only one or two places where
you need user-input, this is probably overkill.

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


Re: Error help

2012-08-02 Thread danielashiloh
On Thursday, 2 August 2012 12:18:59 UTC+1, Peter Otten  wrote:
> danielashi...@googlemail.com wrote:
> 
> 
> 
> > This error has been bugging me for days. I know it's minor, but it's
> 
> > really getting in the way of my programming. I'm programming a data
> 
> > analysis programme for a psychology experiment which takes pickled data
> 
> > from the experiment and produces averages. For some reason python is
> 
> > insisting there is an indentation error on line 18. 
> 
> 
> 
> I can't confirm that, I get an error in line 8
> 
> 
> 
> > partifipant_info=data'Participant Info']
> 
> 
> 
> where you forgot the opening '['. 
> 
> 
> 
> Please post your actual code and don't forget to include a cut-and-paste 
> 
> version of the traceback you get.

Thank you, everyone, for the replies. It does seem to stem from that missing 
bracket, indeed the error did start coming up when I first included that line. 
Do I feel silly! Incidentally, the error message I got was for an unexpected 
indent. All is resolved now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pass data to a subprocess

2012-08-02 Thread Grant Edwards
On 2012-08-02, Laszlo Nagy  wrote:
>
>> I still don't get it.  shm_unlink() works the same way unlink() does.
>> The resource itself doesn't cease to exist until all open file
>> handles are closed. From the shm_unlink() man page on Linux:
>>
>> The operation of shm_unlink() is analogous to unlink(2): it
>> removes a shared memory object name, and, once all processes
>> have unmapped the object, de-allocates and destroys the
>> contents of the associated memory region. After a successful
>> shm_unlink(), attempts to shm_open() an object with the same
>> name will fail (unless O_CREAT was specified, in which case a
>> new, distinct object is created).
>> 
>> Even if the parent calls shm_unlink(), the shared-memory resource
>> will continue to exist (and be usable) until all processes that are
>> holding open file handles unmap/close them.  So not only will
>> detached children not crash, they'll still be able to use the shared
>> memory objects to talk to each other.

Note that when I say the detached children will still be able to talk
to each other using shared memory after the parent calls shm_unlink()
and exit(), I'm talking about the general case -- not specifically
about the multiprocessing module. There may be something else going on
with the multiprocessing module.

> I stand corrected. It should still be examined, what kind shared
> memory is used under non-linux systems. System V on AIX? And what
> about Windows? So maybe the general answer is still no. But I guess
> that the OP wanted this to work on a specific system.
>
> Dear Andrea Crotti! Please try to detach two child processes, exit
> from the main process, and communicate over a multiprocessing queue.
> It will possibly work. Sorry for my bad advice.

I'm not claiming it will work, since I don't know how the IPC in the
multiprocessing module works.  It may indeed break when a child
process is detatched (which I'm assuming means being removed from the
process group and/or detached from the controlling tty).

But, I'm not aware of any underlying Unix IPC mechanism that breaks
when a child is detached, so I was curious about what would cause
multiprocessing's IPC to break.

-- 
Grant Edwards   grant.b.edwardsYow! I didn't order any
  at   WOO-WOO ... Maybe a YUBBA
  gmail.com... But no WOO-WOO!
-- 
http://mail.python.org/mailman/listinfo/python-list


dbf.py API question

2012-08-02 Thread Ethan Furman
SQLite has a neat feature where if you give it a the file-name of 
':memory:' the resulting table is in memory and not on disk.  I thought 
it was a cool feature, but expanded it slightly: any name surrounded by 
colons results in an in-memory table.


I'm looking at the same type of situation with indices, but now I'm 
wondering if the :name: method is not pythonic and I should use a flag 
(in_memory=True) when memory storage instead of disk storage is desired.


Thoughts?

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


Creating a simple CGI Script

2012-08-02 Thread Smaran Harihar
Hi,

I am trying to create a simple CGI Script and following this
tutorialsbut
unfortunately my output is only printing the cgi file as it is on the
browser.

I have already provided the py scripts with the executable functions.

This is my server.py  and this is my
test_cgi.py

-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a simple CGI Script

2012-08-02 Thread Xavier Combelle

In server.py you made a mistake in the declaration of the cgi directory
it should be
handler.cgi_directories = ["/"]


Le 02/08/2012 20:20, Smaran Harihar a écrit :

Hi,

I am trying to create a simple CGI Script and following this tutorials 
 
but unfortunately my output is only printing the cgi file as it is on 
the browser.


I have already provided the py scripts with the executable functions.

This is my server.py  and this is 
mytest_cgi.py 


--
Thanks & Regards
Smaran Harihar



This body part will be downloaded on demand.


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


The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Csanyi Pal
Hi,

I'm new to python.

I'm searching for a way to develope a Python graphical application for a
Postgresql database.

I have installed on my Debian GNU/Linux testing/sid system many python
packages, among others:
eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7,
python-easygui, python-forgetsql, python-gasp, python-glade2,
python-gobject-2, python-gtk2, python-pip, python-pygresql,
python-pyside.qtsql, python-subversion, python-tk, python-wxglade,
spyder, python3-psycopg2, python-psycopg2, XRCed.

I did search in the Google but can't find any good tutorial except for
wxpython tutorial: http://wiki.wxpython.org/FrontPage,
wxGlade tutorial: http://wiki.wxpython.org/WxGladeTutorial

There is a tutorial for using python-psycopg2 here:
http://wiki.postgresql.org/wiki/Psycopg2_Tutorial

Still I don't know how to put these all together?

XRCed is the most interesting way for me.

Can one advices me where to go?

-- 
Regards from Pal

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


Re: Creating a simple CGI Script

2012-08-02 Thread Smaran Harihar
Thanks a lot Xavier, that was exactly what was needed.

On Thu, Aug 2, 2012 at 11:44 AM, Xavier Combelle wrote:

>  In server.py you made a mistake in the declaration of the cgi directory
> it should be
> handler.cgi_directories = ["/"]
>
>
> Le 02/08/2012 20:20, Smaran Harihar a écrit :
>
> Hi,
>
>  I am trying to create a simple CGI Script and following this 
> tutorialsbut
>  unfortunately my output is only printing the cgi file as it is on the
> browser.
>
>  I have already provided the py scripts with the executable functions.
>
>  This is my server.py  and this is my 
> test_cgi.py
>
>  --
> Thanks & Regards
> Smaran Harihar
>
>
>
> This body part will be downloaded on demand.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


unable to get simple html file up

2012-08-02 Thread Smaran Harihar
Hi,

I am following this
tutorial
and
i am not able to get the link.py  up and running.
I should be looking at Html file with link directing to the cgi script.

But strangely i can't even see the page itself. Any idea why it is like
this? I have made link.py executable. Here is the
server.py
.

-- 
Thanks & Regards
Smaran Harihar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Verde Denim
Sounds like you have enough pieces-parts... is it a question of the
development process?
On Aug 2, 2012 3:08 PM, "Csanyi Pal"  wrote:

> Hi,
>
> I'm new to python.
>
> I'm searching for a way to develope a Python graphical application for a
> Postgresql database.
>
> I have installed on my Debian GNU/Linux testing/sid system many python
> packages, among others:
> eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7,
> python-easygui, python-forgetsql, python-gasp, python-glade2,
> python-gobject-2, python-gtk2, python-pip, python-pygresql,
> python-pyside.qtsql, python-subversion, python-tk, python-wxglade,
> spyder, python3-psycopg2, python-psycopg2, XRCed.
>
> I did search in the Google but can't find any good tutorial except for
> wxpython tutorial: http://wiki.wxpython.org/FrontPage,
> wxGlade tutorial: http://wiki.wxpython.org/WxGladeTutorial
>
> There is a tutorial for using python-psycopg2 here:
> http://wiki.postgresql.org/wiki/Psycopg2_Tutorial
>
> Still I don't know how to put these all together?
>
> XRCed is the most interesting way for me.
>
> Can one advices me where to go?
>
> --
> Regards from Pal
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Csanyi Pal
Verde Denim  writes:

> Sounds like you have enough pieces-parts... is it a question of the
> development process?

Yes, it is.

First question is about GUI.

Say I start to create a GUI with XRCed for such an application for
managing a concrete postgresql database.

On a Frame (window) which object should I draw to get a Table of the
database when I write the code?

If I want to use say python-pygresql to connect to the database then I
must study the http://www.pygresql.org/pg.html documentation and after
that I must to write code to connect it with the GUI.

Is on the Internet such a tutorial that can help me in this effort?

-- 
Regards from Pal

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


Re: The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Mark Lawrence

On 02/08/2012 22:13, Csanyi Pal wrote:

Verde Denim  writes:


Sounds like you have enough pieces-parts... is it a question of the
development process?


Yes, it is.

First question is about GUI.

Say I start to create a GUI with XRCed for such an application for
managing a concrete postgresql database.

On a Frame (window) which object should I draw to get a Table of the
database when I write the code?

If I want to use say python-pygresql to connect to the database then I
must study the http://www.pygresql.org/pg.html documentation and after
that I must to write code to connect it with the GUI.

Is on the Internet such a tutorial that can help me in this effort?



Start here? http://zetcode.com/

--
Cheers.

Mark Lawrence.

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


Re: The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Csanyi Pal
Dennis Lee Bieber  writes:

> On Thu, 02 Aug 2012 20:24:36 +0200, Csanyi Pal 
> declaimed the following in gmane.comp.python.general:
>> 
>> I'm searching for a way to develope a Python graphical application for a
>> Postgresql database.
>>
>   A predefined database, or a general access module?

A predefined, already existing database.

>> I have installed on my Debian GNU/Linux testing/sid system many python
>> packages, among others:
>> eric, geany, idle, ninja-ide, pida (it doesn't work here), python2.7,
>> python-easygui, python-forgetsql, python-gasp, python-glade2,
>> python-gobject-2, python-gtk2, python-pip, python-pygresql,
>> python-pyside.qtsql, python-subversion, python-tk, python-wxglade,
>> spyder, python3-psycopg2, python-psycopg2, XRCed.
>>
>   Well... I'd suggest figuring out which GUI toolkit you want to
> use... You have GTK, Tk, I'd say Wx but you didn't list wxpython. You
> also have two competing PostgreSQL adapters -- pick one...

I just installed wxpython packages:
wx2.8-i18n, python-wxgtk2.8, python-wxtools.

>   Eric, geany, and idle are all editor/development environments and
> not directly related to what the application itself runs.
>
>   For a predefined database, you may just want to explore Dabo. For a
> general access (eg; one where you tell the program which PostgreSQL
> database to connect to, and it extracts the schema information from the
> database at run-time) you'll need to study the advanced features of the
> database engine and adapter.

I'm exploring now Dabo.

-- 
Regards from Pal

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


Re: The way to develope a graphical application to manage a Postgres database

2012-08-02 Thread Chris Angelico
On Fri, Aug 3, 2012 at 4:24 AM, Csanyi Pal  wrote:
> I'm searching for a way to develope a Python graphical application for a
> Postgresql database.

There's two quite separate parts to this:

* Develop a Python graphical application
* Develop a Python application [to access] a PostgreSQL database.

I recommend you tackle them separately, and only put them together
once you're confident with each part on its own. Pick a GUI toolkit
and make a "Hello, world". That might take you quite a while, and it
isn't helped by trying to mix in an unfamiliar database.

That said, I do commend your choices of language and DB. :) All the best!

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


RE: Is Python a commercial proposition ?

2012-08-02 Thread Prasad, Ramit
> I'm in stuck record mode here, but one of the things I really enjoy
> about reading here is the way things do go off topic.  IMHO makes for a
> far more interesting experience.  YMMV.

+1 

Ramit
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list