Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread John Ladasky
On Sep 15, 1:52 pm, John Ladasky  wrote:
> I've been snooping around inside Pool, and I would guess that what I
> want to do is to manipulate Pool._inqueue, which is a
> multiprocessing.queues.SimpleQueue object.  I haven't found any
> documentation for SimpleQueue.  It appears to have only the most
> rudimentary of public methods -- put, get, and empty.

Reading more deeply, I think that my first guess was incorrect.
There's also Pool._taskqueue, and it's a full-fledged Queue.  It
appears that map.async() puts pending jobs there, not in
Pool._inqueue.

If this is true, then all that should have to be done is to override a
few methods.  I'm going to try it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Request for research feedback

2011-09-15 Thread Waldek M.
On Thu, 15 Sep 2011 16:11:13 -0400, Prasad, Ramit wrote:
> I don't want to be rude but...
> Not rude:
> Rude:

You're right. I must have gotten a few bad habits I didn't
even realize. Thanks.

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


Comparisons of computation timing

2011-09-15 Thread Akand Islam
I have run my codes (written in Python) in my Notebook (3 GB Ram, Dual-
core CPU T4500 @ 2.3 GHz) and in my lab machine (11.57 GB Ram, i7-920
CPU @ 2.67 GHz). However, I have found execution time in Notebook
250.3 seconds, and in Lab machine 333.2 seconds. How is it possible?
Good configuration machine performs slower??? I reran the codes, same
finding whatsoever. I run Windows 7 in my laptop, and Ubuntu 11.04 in
lab machine. Both are 64 bit. When I ran my simulation in Notebook, I
also did some other stuffs; however for the case of lab machine I did
nothing other than running simulation only.

About the codes: Basically it simply solves some non-linear equations
using "fsolve" along with some other calculations.

I will appreciate if some one discusses about possible reasons? For
fair comparisons, in both machines I ran exactly the same codes. My
codes are not parallelized, is this the main reason i7 processes show
slower performance?

Thanks in advance,
Akand
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: help regarding extracting a smaller list from larger one

2011-09-15 Thread Prasad, Ramit
>Nevertheless, I think list comprehension is what you want:
> [ x  for x in A  if 3.0 <= x <= 8.0 ]
>will extract all the values between 3 and 8 from the array A and create 
>a new list containing them.

>If you want the new list to be a numpy array then
> numpy.array([ x  for x in A  if 3.0 <= x <= 8.0 ])


I have been told that the following is much faster than list generation for 
filtering if you are using numpy arrays. I have not looked to see if this claim 
is accurate, but since it was one of the SciPy creatorsI trust him :) YMMV

foo = numpy.array([
[1.2,2.3,1.3],
[4.3,2.1,6.2],
[3.2,1.2,6.5],
[1.4,2.1,4.3]])
#if we want 2nd element > 2 and 3rd element < 6
mask = (foo[:,2]>2)&(foo[:,2]<6)
v = foo[mask] #this is a view and if you want a new list, you will have to wrap 
it
# I assume np.array(v) will create new array (untested).

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



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


Re: From Python on Solaris to Python on LINUX

2011-09-15 Thread Cameron Simpson
On 15Sep2011 17:30, Genevi�ve Diagorn  wrote:
| I work on projects developed in Python 2.3 on Solaris. The customer asks us
| to pass on LINUX in a recent version of Python.
| 
| Is it someone has already realized this modification? What are the traps to
| be avoided?
| 
| Is it a long and difficult phase?

Aside from the very minor things mentioned by others, only two things
occur to me:

  - if you use the struct module and you're moving from SPARC to Intel the
endianness of some things may change

  - if you call external shell commands, there are (usually minor)
differences between the Solaris and GNU toolsets

Neither seems likely to be a big problem and of course both are "outside
Python" in a sense. Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Do not taunt Happy Fun Coder.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread Chris Angelico
On Fri, Sep 16, 2011 at 8:32 AM, John Ladasky  wrote:
> Ah. Now, see?  Having the right vocabulary helps.  Searching for
> "priority queue" brings up this discussion from back in January:
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/b69aeced28634898
>
> Now, this discussion refers to a PriorityPool class which doesn't
> appear to be a standard part of Python (2.6, anyway).  But I'm not the
> first one to ask the question, and there's code out there.

Awesome! I wasn't aware of that (although considering the volume of
traffic on this list, I doubt there's any human who knows everything
that's been discussed). Previously-solved problems save everyone a lot
of trouble.

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


Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread John Ladasky
Ah. Now, see?  Having the right vocabulary helps.  Searching for
"priority queue" brings up this discussion from back in January:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/b69aeced28634898

Now, this discussion refers to a PriorityPool class which doesn't
appear to be a standard part of Python (2.6, anyway).  But I'm not the
first one to ask the question, and there's code out there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread Chris Angelico
On Fri, Sep 16, 2011 at 8:25 AM, John Ladasky  wrote:
> Starting 50 milliseconds late would be close enough
> to "real time" for my purposes.
> ...
>
> If that's not putting T2 at the head of the queue, I guess I don't
> know a better way to describe it.

Yep, your terms are correct, with that caveat ("immediate" or "urgent"
without being "real-time"). So you're definitely looking for a
priority queue.

It may be possible to patch a different queue object straight into
Pool, but I've never done anything like that. It's probably best to
dig in the code and add an option somewhere to pass in a queue object
- that'd be a very useful feature imho.

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


Re: Cancel or timeout a long running regular expression

2011-09-15 Thread Chris Angelico
On Fri, Sep 16, 2011 at 4:54 AM, Terry Reedy  wrote:
> On 9/15/2011 1:19 AM, pyt...@bdurham.com wrote:
>> I was thinking there might be a technique I could use to evaluate
>> regular expressions in a thread or another process launched via
>> multiprocessing module and then kill the thread/process after a
>> specified timeout period.
>
> Only solution I remember ever seen posted.

Then here's a minor refinement. Since long-running RE is the
exceptional case, optimize for the other. Keep the process around and
feed it all the jobs you get, and on problem, kill and respawn. That
way, you pay most of the overhead cost only when you make use of the
separation. (There's still some IPC overhead of course. Can't escape
that.)

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


Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread John Ladasky
On Sep 15, 3:14 pm, Chris Angelico  wrote:
> On Fri, Sep 16, 2011 at 6:52 AM, John Ladasky  wrote:
> > Suppose that I have a second, parallelizable, long-running task T2
> > that I want to address in REAL TIME when the need arises.  Using Pool,
> > is there a way for me to insert the chunks of T2 at the HEAD of the
> > task queue, instead of at its TAIL?
>
> That's a self-contradiction there. Even if you insert a task into the
> head of the queue, it won't be addressed in real time; the only way to
> do that would be to have a dedicated process, always ready to handle
> the real-time events, or else some kind of interrupt system.
>
> But if you just want them handled when there's a worker available,
> what you're after is a priority queue system. I don't know if one
> exists in Python already or not, but if not, it'd be a worthwhile
> addition.
>
> ChrisA

Hi, Chris,

Sorry if I'm not quite familiar with the proper terminology for
queues.  Let me try to define what I need as precisely as I can.

1) I aim to keep all five child Processes as busy as possible at all
times, crunching numbers.

2) I break my data for the low-priority task, T1, into large enough
chunks to benefit from multiprocessing, but small enough so that any
given Process should become available fairly frequently -- say, every
50 milliseconds.  Starting 50 milliseconds late would be close enough
to "real time" for my purposes.

3) But let's say that T1 still has twenty chunks in the Process queue
when T2 comes along.  I could be waiting 300 milliseconds for the
queue to empty.  If I could just ensure that T2 gets the next
available Processes, I would be happy.  Since T2 is also
parallelizable and I am using five child Processes, I would divide T2
into exactly five chunks.  These chunks should get inserted at
positions 0-4 in the queue rather than at 20-24.  T2 would briefly
commandeer all five Processes and then clear out.

If that's not putting T2 at the head of the queue, I guess I don't
know a better way to describe it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding extracting a smaller list from larger one

2011-09-15 Thread Gary Herron

On 09/15/2011 11:55 AM, neeru K wrote:

Dear Gary,
thank you for the reply.
I will be more specific and take the same example that you have given 
and tell you what is my problem -

array([0.0, 1.3, 2.45, 3.87, 4.54, 5.11, 6.90, 7.78, 8.23, 9.01])
from this array I want to a sub-list with lower and upper indexes that 
are not present in the above array for example - sub-list[3, 8]

Is there a function for this?
thank you
niranjan


You say "index", but I think that is not what you mean.  An index is in 
integer referring to an element's position in the array.   The "value" 
at an index is what I believe you are referring to.


Nevertheless, I think list comprehension is what you want:
[ x  for x in A  if 3.0 <= x <= 8.0 ]
will extract all the values between 3 and 8 from the array A and create 
a new list containing them.


If you want the new list to be a numpy array then
numpy.array([ x  for x in A  if 3.0 <= x <= 8.0 ])






On Thu, Sep 15, 2011 at 10:54 PM, Gary Herron > wrote:


On 09/15/2011 09:40 AM, neeru K wrote:

Dear Python Users,
I am trying to write a code for visualization (raster plots
and peri-event time histogram) of time series
electrophysiological data using numpy, scipy and matlplotlib
in python. I am importing the data into list using loadtext
command.
I was curious if anyone is aware of a function in numpy that
can *extract a smaller list containing numbers from a larger
list* given the upper and lower limit of the values between
which the smaller list lies.
Thank you in advance.
Sincerely,
niranjan

-- 
Niranjan Kambi

Senior Research Fellow,
Neeraj Lab,
National Brain Research Centre,
Manesar, Gurgaon-122050
Haryana, INDIA
Ph:+919818654846 
website:-
http://www.nbrc.ac.in/faculty/neeraj/Lab_webpage/Niranjan_Kambi.html
email:- neuro.n...@nbrc.res.in 
>, neuron...@gmail.com
 >

Do mean to extract a sub-list from a list based on lower and upper
indexes into the list?  Python has a standard notation for
indicating sub-lists, and numpy implements them:

>>> a = numpy.array(range(10))
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a[3:6]
array([3, 4, 5])

If you mean something else, please be more specific, and we'll try
again.

Gary Herron


-- 
Gary Herron, PhD.

Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418 

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










--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: how to make a nested list

2011-09-15 Thread Chris Angelico
On Fri, Sep 16, 2011 at 8:02 AM, Vlastimil Brom
 wrote:
> Besides the above sugestions to correct the nested list approach,
> if you need to set and access the data at the given "coordinates" you
> could also use a nested defaultdict...

The defaultdict is efficient for a sparse matrix, but I suspect that
it'd be rather worse if you use all the elements.

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


Re: multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread Chris Angelico
On Fri, Sep 16, 2011 at 6:52 AM, John Ladasky  wrote:
> Suppose that I have a second, parallelizable, long-running task T2
> that I want to address in REAL TIME when the need arises.  Using Pool,
> is there a way for me to insert the chunks of T2 at the HEAD of the
> task queue, instead of at its TAIL?
>

That's a self-contradiction there. Even if you insert a task into the
head of the queue, it won't be addressed in real time; the only way to
do that would be to have a dedicated process, always ready to handle
the real-time events, or else some kind of interrupt system.

But if you just want them handled when there's a worker available,
what you're after is a priority queue system. I don't know if one
exists in Python already or not, but if not, it'd be a worthwhile
addition.

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


Re: how to make a nested list

2011-09-15 Thread Vlastimil Brom
2011/9/15 Stef Mientki :
> hello,
>
> I need a nested list, like this
>
 A= [ [None,None], [None,None], [None, None] ]
 A[2][0] =77
 A
> [[None, None], [None, None], [77, None]]
> ...
>
> thanks,
> Stef
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Besides the above sugestions to correct the nested list approach,
if you need to set and access the data at the given "coordinates" you
could also use a nested defaultdict, which doesn't need to be
pre-filled before setting, e.g.:

>>> from collections import defaultdict as dd
>>> def dd_dd():
... return dd(dd)
...
>>> dd_matrix = dd(dd_dd)
>>>
>>> dd_matrix[2][0] = 77
>>> dd_matrix[2][0]
77
>>> dd_matrix
defaultdict(, {2: defaultdict(, {0: 77})})
>>>

However, the nested list are concise enough, I guess.

Regards,
   vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing matplotlib-users discussion group?

2011-09-15 Thread John Ladasky
Hate to bump this, but... I found Sourceforge's IRC, and tried to ask
for help there, and it doesn't look like I can get any help until
business hours tomorrow.  Anyone?
-- 
http://mail.python.org/mailman/listinfo/python-list


multiprocessing.Pool, its queue, and pre-emption

2011-09-15 Thread John Ladasky
Suppose that I have a multi-core computer with N CPU's, and I create a
multiprocessing.Pool in Python 2.6 with N-1 Processes.

(My rationale for choosing N-1 Processes was discussed here:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/65ba3ccd4be8228c)

Then I use Pool.map_async() to break up a long-running task T1 into M
chunks, where M > 2N.

Suppose that I have a second, parallelizable, long-running task T2
that I want to address in REAL TIME when the need arises.  Using Pool,
is there a way for me to insert the chunks of T2 at the HEAD of the
task queue, instead of at its TAIL?

I've been snooping around inside Pool, and I would guess that what I
want to do is to manipulate Pool._inqueue, which is a
multiprocessing.queues.SimpleQueue object.  I haven't found any
documentation for SimpleQueue.  It appears to have only the most
rudimentary of public methods -- put, get, and empty.

Reading further, I can see that multiprocessing.Queue (not the same as
SimpleQueue) has put_nowait(), which looks like what I need.  Assuming
that I had access to put_nowait(), then I would need an option in
map_async() which would invoke put_nowait() rather than just plain
put().

Does anyone know of an efficient way to accomplish this?  I'm thinking
that a subclass of Pool which replaces the SimpleQueue with a full-
fledged Queue, and which overrides map_async() allowing for a no-wait
task, would be very useful... but maybe I'm re-inventing the wheel.
Thanks for your advice!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Request for research feedback

2011-09-15 Thread Fulvio Valente
Whoops, I thought the rather iffy Exchange web client at my institution 
would've wrapped outgoing messages automatically. I'm now using a proper 
client for that account which should prevent such issues in the future. 
Thanks for the heads up.


For anyone who couldn't stand to read the original message, a fixed 
version is at http://geeksoc.org/~fvalente/jimmy/request.txt (figured 
it'd be rude to repost it directly in this message).


On 15/09/2011 20:14, Waldek M. wrote:

On Thu, 15 Sep 2011 16:55:13 +0100, Fulvio Valente wrote:


Hi, I am a research intern at the University of Strathclyde
who has been doing a summer research internship.


I don't want to be rude, but please: could you rather first research
how to use a newsreader before you use it?
These long lines (a few times the limit of 78 characters per line)
make your post unreadable.

Thanks,
Waldek


--
Regards,
- Fulvio
--
http://mail.python.org/mailman/listinfo/python-list


RE: Request for research feedback

2011-09-15 Thread Prasad, Ramit
I don't want to be rude but...

Rude:
>I don't want to be rude, but please: could you rather first research
>how to use a newsreader before you use it?
>These long lines (a few times the limit of 78 characters per line)
>make your post unreadable.

Not rude:
>These long lines (a few times the limit of 78 characters per line)
>make your post unreadable.

Sincerely,
Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



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


Re: PC locks up with list operations

2011-09-15 Thread John Nagle

On 8/31/2011 5:40 AM, Chris Withers wrote:

On 31/08/2011 13:33, Steven D'Aprano wrote:

I am using Linux desktops; both incidents were with Python 2.5. Do newer
versions of Python respond to this sort of situation more gracefully?


Ironically, Windows does better here and dumps you out with a
MemoryError before slowly recovering.

Linux seems to fair badly when programs use more memory than physically
available.


   Linux virtual memory has some known design problems.  For example,
you can crash many Linux systems with a program which opens large
files and accesses them randomly, combined with another program which
is spawning processes that need a fair amount of memory.  The disk
caching system tries to use all unused memory, and when process
startup is consuming pages, it's possible to get into a situation
where a page is needed, the task requesting it can't block, and
a lock preventing freeing a file cache page is set.

   Arguably, paging to disk is obsolete. RAM is too cheap and
disk is too slow.

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


Re: Request for research feedback

2011-09-15 Thread Waldek M.
On Thu, 15 Sep 2011 16:55:13 +0100, Fulvio Valente wrote:

> Hi, I am a research intern at the University of Strathclyde
> who has been doing a summer research internship.

I don't want to be rude, but please: could you rather first research
how to use a newsreader before you use it?
These long lines (a few times the limit of 78 characters per line)
make your post unreadable.

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


Re: Cancel or timeout a long running regular expression

2011-09-15 Thread Terry Reedy

On 9/15/2011 1:19 AM, pyt...@bdurham.com wrote:

Is there a way to cancel or timeout a long running regular expression?
I have a program that accepts regular expressions from users and I'm
concerned about how to handle worst case regular expressions that seem
to run forever. Ideally I'm looking for a way to evaluate a regular
expression and timeout after a specified time period if the regular
expression hasn't completed yet. Or a way for a user to cancel a long
running regular expression.


This is a general problem when evaluating *any* expression from the 
outside. [0]*1*1 will eat space as well as time. At least, as 
far as I know, an re cannot cause a disk reformat ;-).


There have been previous discussions on this generally topic.


I was thinking there might be a technique I could use to evaluate
regular expressions in a thread or another process launched via
multiprocessing module and then kill the thread/process after a
specified timeout period.


Only solution I remember ever seen posted. I wonder if there are any 
heuristics for detecting exponential time re's.


> My concern about the multiprocessing module

technique is that launching a process for every regex evaluation sounds
pretty inefficient. And I don't think the threading module supports the
ability to kill threads from outside a thread itself.


--
Terry Jan Reedy

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


Re: help regarding extracting a smaller list from larger one

2011-09-15 Thread neeru K
Dear Gary,
thank you for the reply.
I will be more specific and take the same example that you have given and
tell you what is my problem -
array([0.0, 1.3, 2.45, 3.87, 4.54, 5.11, 6.90, 7.78, 8.23, 9.01])
from this array I want to a sub-list with lower and upper indexes that are
not present in the above array for example - sub-list[3, 8]
Is there a function for this?
thank you
niranjan


On Thu, Sep 15, 2011 at 10:54 PM, Gary Herron  wrote:

> On 09/15/2011 09:40 AM, neeru K wrote:
>
>> Dear Python Users,
>> I am trying to write a code for visualization (raster plots and peri-event
>> time histogram) of time series electrophysiological data using numpy, scipy
>> and matlplotlib in python. I am importing the data into list using loadtext
>> command.
>> I was curious if anyone is aware of a function in numpy that can *extract
>> a smaller list containing numbers from a larger list* given the upper and
>> lower limit of the values between which the smaller list lies.
>> Thank you in advance.
>> Sincerely,
>> niranjan
>>
>> --
>> Niranjan Kambi
>> Senior Research Fellow,
>> Neeraj Lab,
>> National Brain Research Centre,
>> Manesar, Gurgaon-122050
>> Haryana, INDIA
>> Ph:+919818654846
>> website:- http://www.nbrc.ac.in/faculty/**neeraj/Lab_webpage/Niranjan_**
>> Kambi.html
>> email:- neuro.n...@nbrc.res.in ,
>> neuron...@gmail.com 
>>
>>  Do mean to extract a sub-list from a list based on lower and upper
> indexes into the list?  Python has a standard notation for indicating
> sub-lists, and numpy implements them:
>
> >>> a = numpy.array(range(10))
> >>> a
> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
> >>> a[3:6]
> array([3, 4, 5])
>
> If you mean something else, please be more specific, and we'll try again.
>
> Gary Herron
>
>
> --
> Gary Herron, PhD.
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to make a nested list

2011-09-15 Thread John Ladasky
Stef,

Are your bottom-level lists always of length 2?  If so, then you could
use an array, instead of a list of lists.

Python ships with a module called array, but it doesn't allow you to
put non-numeric types into arrays, and it looks like you want the
NoneType.  I use the popular numpy module, which does allow non-
numeric types.

You might also like the slice notation that numpy uses for referencing
items in the array.  The indices go inside a single set of square
brackets, and are separated by commas.

>>> from numpy import empty
>>> B = empty((3,2), object)
>>> B
array([[None, None],
   [None, None],
   [None, None]], dtype=object)
>>> B[2,0] = 77
>>> B
array([[None, None],
   [None, None],
   [77, None]], dtype=object)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cause __init__ to return a different class?

2011-09-15 Thread Arnaud Delobelle
On 15 September 2011 15:41, Matthew Pounsett  wrote:
> On Sep 15, 1:35 am, Chris Rebert  wrote:
>> Override __new__() instead:
>> http://docs.python.org/reference/datamodel.html#object.__new__
>
> Aha.. thanks!  The reference book I'm working from neglects to mention
> __new__, so I'd assumed __init__ was the constructor.  It hadn't
> occurred to me that python would separate the functions (I still don't
> see exactly why it would be useful to do that, but perhaps insight
> will come with time).

If you're interested in the reason, I suggest you read Guido's essay
on "new style classes" which were introduced in Python 2.2 (and are
now a good 10 years old I think):

http://www.python.org/download/releases/2.2.3/descrintro

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


Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')

2011-09-15 Thread Tim Johnson
* Tim Johnson  [110914 18:18]:
> * Chris Rebert  [110914 16:46]:
> > On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson  wrote:
> > > I have written a class that uses ftplib.FTP as the parent.
> > > I need to reconcile the modified time of a workstation file with
> > > that same filename on a remote server.
> > > Let's say we have a file called '400.shtml'. I get the mtime on
> > > my workstation by
> > >>> os.path.getmtime('400.shtml')
> > > 1311648420.0
> > 
> > http://docs.python.org/library/os.path.html#os.path.getmtime
> > Your sample seems to be a typical Unix timestamp:
>  Yup. Needs to be converted to a timedate stamp, methinks.
> > http://en.wikipedia.org/wiki/Unix_time
>   I'll look at that tomorrow. Late here.  
> > > And I use
> > >>> ftp.sendcmd('MDTM 400.shtml') ## for the remote server
> > > '213 20110726004703'
>  
> > RFC 3659 - Extensions to FTP
> > Sec 3. File Modification Time (MDTM)
> > http://tools.ietf.org/html/rfc3659#section-3
> > 
> > (Note: Code 213 = File status response)
>   and '213 20110726004703'[4:] should give me
>   the string representation of the timedate stamp on the
>   remote file.
  FYI:  datetime.datetime.fromtimestamp(mod_time)
  Is probably what I was looking for. However, for my
  purposes - I'm going to take another approach.
  Every uploaded file is defined in an object stored on my
  workstationr:
  I will store the MDTM string after upload and then on the next
  upload, compare the stored string with the return value
  from ftp.sendcmd('MDTM ' + filename)
  Thanks for the input.
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding extracting a smaller list from larger one

2011-09-15 Thread Gary Herron

On 09/15/2011 09:40 AM, neeru K wrote:

Dear Python Users,
I am trying to write a code for visualization (raster plots and 
peri-event time histogram) of time series electrophysiological data 
using numpy, scipy and matlplotlib in python. I am importing the data 
into list using loadtext command.
I was curious if anyone is aware of a function in numpy that can 
*extract a smaller list containing numbers from a larger list* given 
the upper and lower limit of the values between which the smaller list 
lies.

Thank you in advance.
Sincerely,
niranjan

--
Niranjan Kambi
Senior Research Fellow,
Neeraj Lab,
National Brain Research Centre,
Manesar, Gurgaon-122050
Haryana, INDIA
Ph:+919818654846
website:- 
http://www.nbrc.ac.in/faculty/neeraj/Lab_webpage/Niranjan_Kambi.html
email:- neuro.n...@nbrc.res.in , 
neuron...@gmail.com 


Do mean to extract a sub-list from a list based on lower and upper 
indexes into the list?  Python has a standard notation for indicating 
sub-lists, and numpy implements them:


>>> a = numpy.array(range(10))
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a[3:6]
array([3, 4, 5])

If you mean something else, please be more specific, and we'll try again.

Gary Herron


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: From Python on Solaris to Python on LINUX

2011-09-15 Thread GrayShark
I think that was more of a version question the Kernel questin

1) you can install any and all versions python on a linux computer.
You just need you app to select the correct path, correct python 
interpret. Likely there many be some some drivers in /dev that are
not the same as in Solaris. But that shouldn't daunt you. 
So start by installing python2.3, then test and fix version by version
through python2.7. python3.0 might be a pretty be rewrite.

2) Try to pick a version of linux supported locally; likely SuSE, even 
though Novell/Attachmate owns it. SuSE seems popular in Europe.


On Thu, 15 Sep 2011 18:26:04 +0200, Philipp Hagemeister wrote:

>> What are the traps to be avoided?
> 
> Assuming you're not using any OS features (scan the code for "/dev" and
> "/proc"), the transition from Solaris to Linux will be seamless.
> 
> Your main problem will be the transition from the archaic Python 2.3 to
> a modern one. Luckily, all 2.x Pythons should be backwards-compatible.
> 
> In summary, your application should work just fine (although being
> written in 2.3, it's probably not as maintainable as a modern
> application would).
> 
>> What is the most recent version on LINUX?
> There are multiple Linux distributions which can differ quite a lot.
> debian, Ubuntu, and CentOS are popular ones. As you can see on
> http://www.debian.org/CD/ , the current debian version is 6.0. As you
> can't see at the moment on http://kernel.org/ , the current Linux kernel
> version is 3.0 (although most distribution will want to test the kernel
> and therefore include a slightly older one).
> 
> -- Philipp

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


Re: how to make a nested list

2011-09-15 Thread Gary Herron

On 09/15/2011 09:57 AM, Stef Mientki wrote:

hello,

I need a nested list, like this

>>> A= [ [None,None], [None,None], [None, None] ]
>>> A[2][0] =77
>>> A
[[None, None], [None, None], [77, None]]


Because the list is much larger, I need a shortcut (ok I can use a for 
loop)

So I tried
>>> B = 3 * [ [ None, None ]]
>>> B[2][0] = 77
>>> B
[[77, None], [77, None], [77, None]]

which doesn't work as expected.

any suggestions ?

thanks,
Stef


A for loop to fill in the array would work, but list comprehension 
(which is really just an internal loop for filling an array) is probably 
more efficient, certainly less code, and arguably more Pythonic.


A = [ [None,None]  for i in range(1000) ]

Gary Herron


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: how to make a nested list

2011-09-15 Thread Peter Pearson
On Thu, 15 Sep 2011 18:57:24 +0200, Stef Mientki wrote:
[snip]
> Because the list is much larger, I need a shortcut (ok I can use a for loop)
> So I tried
> >>> B = 3 * [ [ None, None ]]
> >>> B[2][0] = 77
> >>> B
> [[77, None], [77, None], [77, None]]
>
> which doesn't work as expected.
>
> any suggestions ?

>>> b = [[None, None] for i in range(3)]
>>> b[2][0] = 77
>>> b
[[None, None], [None, None], [77, None]]

If you don't understand why the other approach resulted in
[[77, None], [77, None], [77, None]], feel free to ask.  It's
a mistake that I think everybody makes at least once.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: how to make a nested list

2011-09-15 Thread Prasad, Ramit
>>> B = 3 * [ [ None, None ]]
That makes a list of the exact same list object: [ a, a, a ] where a = [ None, 
None ]. 
Instead I would do something like (untested python2.x):
B = [ [ None, None ] for x in xrange(3) ]

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



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


how to make a nested list

2011-09-15 Thread Stef Mientki

hello,

I need a nested list, like this

>>> A= [ [None,None], [None,None], [None, None] ]
>>> A[2][0] =77
>>> A
[[None, None], [None, None], [77, None]]


Because the list is much larger, I need a shortcut (ok I can use a for loop)
So I tried
>>> B = 3 * [ [ None, None ]]
>>> B[2][0] = 77
>>> B
[[77, None], [77, None], [77, None]]

which doesn't work as expected.

any suggestions ?

thanks,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: From Python on Solaris to Python on LINUX

2011-09-15 Thread Philipp Hagemeister
> What are the traps to be avoided?

Assuming you're not using any OS features (scan the code for "/dev" and
"/proc"), the transition from Solaris to Linux will be seamless.

Your main problem will be the transition from the archaic Python 2.3 to
a modern one. Luckily, all 2.x Pythons should be backwards-compatible.

In summary, your application should work just fine (although being
written in 2.3, it's probably not as maintainable as a modern
application would).

> What is the most recent version on LINUX?
There are multiple Linux distributions which can differ quite a lot.
debian, Ubuntu, and CentOS are popular ones. As you can see on
http://www.debian.org/CD/ , the current debian version is 6.0. As you
can't see at the moment on http://kernel.org/ , the current Linux kernel
version is 3.0 (although most distribution will want to test the kernel
and therefore include a slightly older one).

-- Philipp



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


help regarding extracting a smaller list from larger one

2011-09-15 Thread neeru K
Dear Python Users,
I am trying to write a code for visualization (raster plots and peri-event
time histogram) of time series electrophysiological data using numpy, scipy
and matlplotlib in python. I am importing the data into list using loadtext
command.
I was curious if anyone is aware of a function in numpy that can *extract a
smaller list containing numbers from a larger list* given the upper and
lower limit of the values between which the smaller list lies.
Thank you in advance.
Sincerely,
niranjan

-- 
Niranjan Kambi
Senior Research Fellow,
Neeraj Lab,
National Brain Research Centre,
Manesar, Gurgaon-122050
Haryana, INDIA
Ph:+919818654846
website:-
http://www.nbrc.ac.in/faculty/neeraj/Lab_webpage/Niranjan_Kambi.html
email:- neuro.n...@nbrc.res.in, neuron...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cause __init__ to return a different class?

2011-09-15 Thread Miki Tebeka
I'd go for a factory function 
(http://en.wikipedia.org/wiki/Factory_method_pattern):

def create(foo):
return Child(foo) if foo else Parent()
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN} OpenOpt, FuncDesigner, DerApproximator, SpaceFuncs release 0.36 Options

2011-09-15 Thread dmitrey
Hi all,
new release of our free scientific soft (OpenOpt, FuncDesigner,
DerApproximator,
SpaceFuncs) v. 0.36 is out:

OpenOpt:

Now solver interalg can handle all types of constraints and
integration problems
Some minor improvements and code cleanup

FuncDesigner:

Interval analysis now can involve min, max and 1-d monotone
splines R -> R of 1st and 3rd order
Some bugfixes and improvements

SpaceFuncs:

Some minor changes

DerApproximator:

Some improvements for obtaining derivatives in points from R^n
where left or right derivative for a variable is absent, especially
for stencil > 1

See http://openopt.org for more details.

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


Request for research feedback

2011-09-15 Thread Fulvio Valente
Hi, I am a research intern at the University of Strathclyde who has been doing 
a summer research internship. I hope that this is not an inappropriate place to 
ask, but I am looking for participants willing to use and evaluate an 
application that was written as part of this internship. If you choose to 
participate, this should only take no more than an hour or two of your time at 
the very most, unless you wish to not use the analysis files provided.

My project is to experiment with ways of inferring and displaying 
socio-technical information about a software project from a version control 
repository by creating a prototype application. The application infers 
authorship information in the form of "closeness scores" between authors and 
the files they have worked on by traversing the history of a Mercurial 
repository. This is then displayed as a map of socio-technical dependencies 
between files and the authors that worked on them and between authors and the 
files they have worked on, which should allow for easy visual comparisons of 
closeness.

Some potential applications and use cases I can envision in the program's 
current form include discovering who the key figures are (i.e. who to talk to 
about a problem) or what the bus factor (how many people need to be "hit by a 
bus" before a project is in trouble because there's nobody left who understands 
it) is for a project or a subsystem within it. Perhaps a little more 
depressingly, this also maybe be used to highlight potential cases of poor 
productivity to be investigated.

The program itself, Jimmy (for lack of a better name), has a binary 
distribution which can be found at 
http://geeksoc.org/~fvalente/jimmy/jimmy_r1.zip and only requires Java 7 and 
Mercurial (other libraries are included), getting you started quickly. The 
source is available at https://bitbucket.org/fvalente/jimmy and if you wish to 
build it yourself, it depends on Guava r09 and JUNG 2.0.1 (api, algorithms, 
graph-impl, visualization) which itself depends on Apache Commons 
collections-generic 4.0.1.

To perform a basic analysis of a project, you can open a directory that's a 
Mercurial repository and it will just look at the list of commits and the files 
that changed, adding 1 to a score each time an author touches a file, which 
should only take a minute or two, even for large projects. If you have more 
time, you can do the more expensive diff stats analysis which compares the size 
of each diff with the average diff size of the project, excluding empty diffs 
and binary changes. Unfortunately, the diff stats analysis is very slow due to 
retrieving each diff requiring the spawning of a hg subprocess (for reference, 
my 4 year old quad-core machine can do only ~10,000 commits per hour). I don't 
have a progress UI yet, but progress status is sent to stdout when doing a diff 
stats analysis. Once analysis is complete, you can save the results to review 
later by using the open analysis results option.

To navigate the results you can switch to viewing a particular file or author 
of interest from the file and author lists on the left. For files, this will 
display that file as a node in the centre with the authors that have been 
involved with it as orbiting nodes, with the connecting lines' length, 
thickness and colour shortening, thickening and approaching red respectively as 
the closeness score between that author and the file increases. For authors, it 
is the same except the files they have worked on will be the orbiting nodes. 
You can also directly navigate to having a display based on an orbiting node by 
clicking it in the display rather than searching through the file or author 
lists. The display can be zoomed by using the scroll wheel and can be 
translated with the scroll bars or by dragging on an area not occupied by a 
node.

What I would like is for you to please run Jimmy on one or more Mercurial 
repositories of your choice and to give some feedback on it. Some questions I'd 
particularly like answered are:

* Do the closeness scores it produces match with your perception of the 
relationships between people and code in the project? (e.g. if you're looking 
at a particular file and some authors involved in it are shown as closer than 
others, is this the result you would have expected from a perfect version of 
Jimmy?)
* Does the visualisation of the scores substantially improve your ability to 
draw conclusions from the data compared to just reading a saved analysis (which 
is just plaintext)?
* If, hypothetically, you had no prior knowledge about the project, would using 
it help you to discover the key figures (e.g. maintainer, BDFL) behind the 
project or any of its subsystems? (Alternatively, do such people correctly show 
up as having touched a wider variety of files and with closer relations to them 
than other people?)
* If you were a manager would you be able to use it to discover potential 
productivity issues that you would then inves

From Python on Solaris to Python on LINUX

2011-09-15 Thread Geneviève Diagorn
Hi,

 

I work on projects developed in Python 2.3 on Solaris. The customer asks us
to pass on LINUX in a recent version of Python.

Is it someone has already realized this modification? What are the traps to
be avoided?

Is it a long and difficult phase?

What is the most recent version on LINUX?

Thanks. 

 

Geneviève 

 

 

 

 

 

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


Re: How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
On 15 September 2011 16:17, Ian Kelly  wrote:
> On Thu, Sep 15, 2011 at 5:10 AM, Arnaud Delobelle  wrote:
>> Hi all,
>>
>> You can do:
>>
>> def foo():
>>    "foodoc"
>>    pass
>>
>> function = type(lambda:0)
>> foo2 = function(foo.__code__, globals())
>> assert foo2.__doc__ == "foodoc"
>>
>> I am wondering how the function constructor knows that foo.__code__
>> has a docstring. [...]
>
> From what I'm seeing, it appears that if there is no docstring, the
> first constant will always be None.  So if the first constant is a
> string, then it's a docstring.
>

Yes it seems to be the case.  Even if None is not used in the
function, it appears in co_consts.  Good thinking!

Thanks,

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


Re: How does a function know the docstring of its code object?

2011-09-15 Thread Ian Kelly
On Thu, Sep 15, 2011 at 5:10 AM, Arnaud Delobelle  wrote:
> Hi all,
>
> You can do:
>
> def foo():
>    "foodoc"
>    pass
>
> function = type(lambda:0)
> foo2 = function(foo.__code__, globals())
> assert foo2.__doc__ == "foodoc"
>
> I am wondering how the function constructor knows that foo.__code__
> has a docstring.  I can see that
>
>    foo.__code__.co_consts == ('foodoc',)
>
> But I can't find where in foo.__code__ is stored the information that
> the first constant in foo.__code__ is actually a docstring.

>From what I'm seeing, it appears that if there is no docstring, the
first constant will always be None.  So if the first constant is a
string, then it's a docstring.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turkic I and re

2011-09-15 Thread Yaşar Arabacı
Hi,

I am a Turkish self-taught python user. Personally, I don't think I am in a
position to discuss a issue in this scale. But in my opinion, I think
pardus* developers should be invited to join to this discussion. As they are
using python heavily on most of their projects** I think they would have
something valueable to say about this subject. Here is the pardus-developers
mailing list : http://liste.pardus.org.tr/mailman/listinfo/pardus-devel

And as for me, I always expect Turkish locale might cause problems, and use
some workarounds if neccessary. For example, If I needed to match lower-case
or upper-case Turkish "i", I would probably go with [iİ] with unicode flag.


*) a linux distro developed by  Scientific & Technological Research Council
of Turkey
**) http://developer.pardus.org.tr/projects/index.html



2011/9/15 MRAB 

> On 15/09/2011 14:44, John-John Tedro wrote:
>
>> On Thu, Sep 15, 2011 at 1:16 PM, Alan Plum > > wrote:
>>
>>On 2011-09-15 15:02, MRAB wrote:
>>
>>The regex module at 
>> http://pypi.python.org/pypi/__**regex
>>
>> >
>> currently uses a
>>compromise, where it matches 'I' with 'i' and also 'I' with 'ı'
>>and 'İ'
>>with 'i'.
>>
>>I was wondering if it would be preferable to have a TURKIC flag
>>instead
>>("(?T)" or "(?T:...)" in the pattern).
>>
>>
>>I think the problem many people ignore when coming up with solutions
>>like this is that while this behaviour is pretty much unique for
>>Turkish script, there is no guarantee that Turkish substrings won't
>>appear in other language strings (or vice versa).
>>
>>For example, foreign names in Turkish are often given as spelled in
>>their native (non-Turkish) script variants. Likewise, Turkish names
>>in other languages are often given as spelled in Turkish.
>>
>>The Turkish 'I' is a peculiarity that will probably haunt us
>>programmers until hell freezes over. Unless Turkey abandons its
>>traditional orthography or people start speaking only a single
>>language at a time (including names), there's no easy way to deal
>>with this.
>>
>>In other words: the only way to make use of your proposed flag is if
>>you have a fully language-tagged input (e.g. an XML document making
>>extensive use of xml:lang) and only ever apply regular expressions
>>to substrings containing one culture at a time.
>>
>>--
>>
>> http://mail.python.org/__**mailman/listinfo/python-list
>>
>> 
>> >
>>
>>
>> Python does not appear to support special cases mapping, in effect, it
>> is not 100% compliant with the unicode standard.
>>
>> The locale specific 'i' casing in Turkic is mentioned in 5.18 (Case
>> Mappings > pdf#G21180 
>> >)
>>
>> of the unicode standard.
>> http://www.unicode.org/**versions/Unicode6.0.0/ch05.**pdf#G21180
>>
>> AFAIK, the case methods of python strings seems to be built around the
>> assumption that len("string") == len("string".upper()), but some of
>> these casing rules require that the string grow. Like uppercasing of the
>> german sharp s "ß" which should be translated to the expanded string "SS".
>> These special cases should be triggered on specific locales, but I have
>> not been able to verify that the Turkic uppercasing of "i" works on
>> either python 2.6, 2.7 or 3.1:
>>
>>   locale.setlocale(locale.LC_**ALL, "tr_TR.utf8") # warning, requires
>> turkish locale on your system.
>>   ord("i".upper()) == 0x130 # is False for me, but should be True
>>
>> I wouldn't be surprised if these issues are translated into the 're'
>> module.
>>
>>  There has been some discussion on the Python-dev list about improving
> Unicode support in Python 3.
>
> It's somewhat unlikely that Unicode will become locale-dependent in
> Python because it would cause problems; you don't want:
>
>"i".upper() == "I"
>
> to be maybe true, maybe false.
>
> An option would be to specify whether it should be locale-dependent.
>
>
>  The only support appears to be 'L' switch, but it only makes "\w, \W,
>> \b, \B, \s and \S dependent on the current locale".
>>
>
> That flag is for locale-dependent 8-bit encodings. The ASCII (Python
> 3), LOCALE and UNICODE flags are mutually exclusive.
>
>
>  Which probably does not yield to the special rules mentioned above, but
>> I could be wrong. Make sure that your locale is correct and test again.
>>
>> If you are unsuccessful, I don't see a 'Turkic flag' being introduced
>> into re module any time soon, given the follo

Re: Turkic I and re

2011-09-15 Thread Tim Chase

On 09/15/11 09:06, MRAB wrote:

It's somewhat unlikely that Unicode will become locale-dependent in
Python because it would cause problems; you don't want:

  "i".upper() == "I"

to be maybe true, maybe false.

An option would be to specify whether it should be locale-dependent.


There have been several times when I've wished that unicode 
strings would grow something like


  .locale_aware_insensitive_cmp(other[,
 locale=locale.getdefaultlocale()]
 )

to return -1/0/1 like cmp(), or in case sort-order is 
nonsensical/arbitrary (such as for things like Mandarin glyphs)


  .insensitive_locale_equal(other,[,
 locale=locale.getdefaultlocale()]
 )

so you could do something like

 if "i".locale_aware_insensitive_cmp("I"):
   not_equal()
 else:
   equal()

or

 if "i".insensitive_locale_equal("I"):
   equal()
 else:
   not_equal()

because while I know that .upper() or .lower() doesn't work in a 
lot of cases, I don't really care about the upper/lower'ness of 
the result, I want to do an insensitive compare (and most of teh 
time it's just for equality, not for sorting).  It's my 
understanding[1] that the same goes for the German where 
"ß".upper() is traditionally written as "SS" but "SS".lower() is 
traditionally just "ss" instead of "ß".


So if these language-dependent comparisons were relegated to a 
well-tested core method of a unicode string, it may simplify the 
work/issue for you.


-tkc


[1]
http://en.wikipedia.org/wiki/Letter_case#Special_cases





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


Re: cause __init__ to return a different class?

2011-09-15 Thread Matthew Pounsett
On Sep 15, 1:54 am, Ryan Kelly  wrote:
> The above will do exactly what you want, but it's generally bad style
> unless you have a very specific use-case.  Is there a particular reason
> you need to "magically" return a subclass, rather than making this
> explicit in the code?
>
> To be friendlier to others reading your code, I would consider using a
> classmethod to create an alternative constructor:

Yeah, I was considering doing this as well, particularly if I couldn't
have made the other work.   The reason I'm not too concerned about
anyone misinterpreting what's going on is that in this case the base
class is actually named for being a constructor, and any rare case
where I want a specific subclass the subclass will be created
directly.

Thanks very much for your help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cause __init__ to return a different class?

2011-09-15 Thread Matthew Pounsett
On Sep 15, 1:35 am, Chris Rebert  wrote:
> Override __new__() instead:
> http://docs.python.org/reference/datamodel.html#object.__new__

Aha.. thanks!  The reference book I'm working from neglects to mention
__new__, so I'd assumed __init__ was the constructor.  It hadn't
occurred to me that python would separate the functions (I still don't
see exactly why it would be useful to do that, but perhaps insight
will come with time).

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


Re: What is wrong with this code?

2011-09-15 Thread John Gordon
In  superhappyfuntime  
writes:

> it's not running. here it is: 

> #this is antiWYSIWYG, an easy to learn cap for begginners to LaTeX.

> #this is defines what means what. you can just read howto.pdf instead 
> of this part.
> here it is: = '\begin{document}'
> it's an article = '\documentclass article'
> it's a book = '\documentclass{book}'
> it's a letter = '\documentclass{letter}'
> it's a report = '\documentclass{report}'
> it's called = '\title{'
> it's over! = '\end{document}'

> #this is where you come in: type what you want below using the terms 
> explained in howto.pdf 

>  print ('it's an article it's called test} here it is: Hello World! 
> it's over!')

You cannot use words like

  it's 

inside a single-quoted string.  Either escape the word like this:

  it\'s

or enclose the entire string in double quotes.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: What is wrong with this code?

2011-09-15 Thread Ulrich Eckhardt
superhappyfuntime wrote:
> #this is antiWYSIWYG, an easy to learn cap for begginners to LaTeX.

It's LaTeX, not Python.

Uli


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


Re: Turkic I and re

2011-09-15 Thread MRAB

On 15/09/2011 14:44, John-John Tedro wrote:

On Thu, Sep 15, 2011 at 1:16 PM, Alan Plum mailto:m...@alanplum.com>> wrote:

On 2011-09-15 15:02, MRAB wrote:

The regex module at http://pypi.python.org/pypi/__regex
 currently uses a
compromise, where it matches 'I' with 'i' and also 'I' with 'ı'
and 'İ'
with 'i'.

I was wondering if it would be preferable to have a TURKIC flag
instead
("(?T)" or "(?T:...)" in the pattern).


I think the problem many people ignore when coming up with solutions
like this is that while this behaviour is pretty much unique for
Turkish script, there is no guarantee that Turkish substrings won't
appear in other language strings (or vice versa).

For example, foreign names in Turkish are often given as spelled in
their native (non-Turkish) script variants. Likewise, Turkish names
in other languages are often given as spelled in Turkish.

The Turkish 'I' is a peculiarity that will probably haunt us
programmers until hell freezes over. Unless Turkey abandons its
traditional orthography or people start speaking only a single
language at a time (including names), there's no easy way to deal
with this.

In other words: the only way to make use of your proposed flag is if
you have a fully language-tagged input (e.g. an XML document making
extensive use of xml:lang) and only ever apply regular expressions
to substrings containing one culture at a time.

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



Python does not appear to support special cases mapping, in effect, it
is not 100% compliant with the unicode standard.

The locale specific 'i' casing in Turkic is mentioned in 5.18 (Case
Mappings )
of the unicode standard.
http://www.unicode.org/versions/Unicode6.0.0/ch05.pdf#G21180

AFAIK, the case methods of python strings seems to be built around the
assumption that len("string") == len("string".upper()), but some of
these casing rules require that the string grow. Like uppercasing of the
german sharp s "ß" which should be translated to the expanded string "SS".
These special cases should be triggered on specific locales, but I have
not been able to verify that the Turkic uppercasing of "i" works on
either python 2.6, 2.7 or 3.1:

   locale.setlocale(locale.LC_ALL, "tr_TR.utf8") # warning, requires
turkish locale on your system.
   ord("i".upper()) == 0x130 # is False for me, but should be True

I wouldn't be surprised if these issues are translated into the 're' module.


There has been some discussion on the Python-dev list about improving
Unicode support in Python 3.

It's somewhat unlikely that Unicode will become locale-dependent in
Python because it would cause problems; you don't want:

"i".upper() == "I"

to be maybe true, maybe false.

An option would be to specify whether it should be locale-dependent.


The only support appears to be 'L' switch, but it only makes "\w, \W,
\b, \B, \s and \S dependent on the current locale".


That flag is for locale-dependent 8-bit encodings. The ASCII (Python
3), LOCALE and UNICODE flags are mutually exclusive.


Which probably does not yield to the special rules mentioned above, but
I could be wrong. Make sure that your locale is correct and test again.

If you are unsuccessful, I don't see a 'Turkic flag' being introduced
into re module any time soon, given the following from PEP 20
"Special cases aren't special enough to break the rules"


That's why I'm interested in the view of Turkish users. The rest of us
will probably never have to worry about it! :-)

(There's a report in the Python bug tracker about this issue, which is
why the regex module has the compromise.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turkic I and re

2011-09-15 Thread John-John Tedro
On Thu, Sep 15, 2011 at 1:16 PM, Alan Plum  wrote:

> On 2011-09-15 15:02, MRAB wrote:
>
>> The regex module at 
>> http://pypi.python.org/pypi/**regexcurrently
>>  uses a
>> compromise, where it matches 'I' with 'i' and also 'I' with 'ı' and 'İ'
>> with 'i'.
>>
>> I was wondering if it would be preferable to have a TURKIC flag instead
>> ("(?T)" or "(?T:...)" in the pattern).
>>
>
> I think the problem many people ignore when coming up with solutions like
> this is that while this behaviour is pretty much unique for Turkish script,
> there is no guarantee that Turkish substrings won't appear in other language
> strings (or vice versa).
>
> For example, foreign names in Turkish are often given as spelled in their
> native (non-Turkish) script variants. Likewise, Turkish names in other
> languages are often given as spelled in Turkish.
>
> The Turkish 'I' is a peculiarity that will probably haunt us programmers
> until hell freezes over. Unless Turkey abandons its traditional orthography
> or people start speaking only a single language at a time (including names),
> there's no easy way to deal with this.
>
> In other words: the only way to make use of your proposed flag is if you
> have a fully language-tagged input (e.g. an XML document making extensive
> use of xml:lang) and only ever apply regular expressions to substrings
> containing one culture at a time.
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>

Python does not appear to support special cases mapping, in effect, it is
not 100% compliant with the unicode standard.

The locale specific 'i' casing in Turkic is mentioned in 5.18 (Case
Mappings)
of the unicode standard.
http://www.unicode.org/versions/Unicode6.0.0/ch05.pdf#G21180

AFAIK, the case methods of python strings seems to be built around the
assumption that len("string") == len("string".upper()), but some of these
casing rules require that the string grow. Like uppercasing of the german
sharp s "ß" which should be translated to the expanded string "SS".
These special cases should be triggered on specific locales, but I have not
been able to verify that the Turkic uppercasing of "i" works on either
python 2.6, 2.7 or 3.1:

  locale.setlocale(locale.LC_ALL, "tr_TR.utf8") # warning, requires turkish
locale on your system.
  ord("i".upper()) == 0x130 # is False for me, but should be True

I wouldn't be surprised if these issues are translated into the 're' module.

The only support appears to be 'L' switch, but it only makes "\w, \W, \b, \B,
\s and \S dependent on the current locale".
Which probably does not yield to the special rules mentioned above, but I
could be wrong. Make sure that your locale is correct and test again.

If you are unsuccessful, I don't see a 'Turkic flag' being introduced into
re module any time soon, given the following from PEP 20
"Special cases aren't special enough to break the rules"

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


Re: using python in web applications

2011-09-15 Thread Roy Smith
In article ,
 Alan Plum  wrote:

> Django can be scaled down a lot, but it's a full-featured framework at 
> its heart.

You can pick and chose which parts of django you want to use.  You don't 
need to use any of the Django model stuff.  You don't need to use any of 
the template system.  You can tear out all or most of the default 
middleware.  At that point, about all that's left is the route parser 
and dispatch code.  The nice thing about this is that as you 
incrementally discover which pieces of it you really do need, it's easy 
to pull them in.

That being said, we've made a lot of use of Tornado for small 
stand-alone web services with just a couple of routes.  In retrospect, 
it's unclear if there's any justifiable argument for why we use both 
Tornado and Django, other than hysterical raisins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using python in web applications

2011-09-15 Thread Alan Plum

On 2011-09-11 02:50, Littlefield, Tyler wrote:
I replied to that one off list I guess, but I figured Django was way 
more overhead than I wanted, doesn't really fit with solving the speed 
issue.


Depending on your needs, you may find something like bottle or Flask a 
better choice then.


Django can be scaled down a lot, but it's a full-featured framework at 
its heart. Bottle is pretty minimal (IIRC it doesn't even come with any 
templating). Flask is somewhere in between as it bundles Werkzeug (a 
pure WSGI framework) with Jinja (a template library) with some glue code.


I have used Flask in the past but often found myself implementing half 
of Django anyway, which is why I eventually switched. When I only need a 
bare API with no database and without templates, I usually go for Bottle 
these days.


If you feel like coding closer to the metal and care more about 
performance than readability, you might also find Twisted useful.

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


Re: Turkic I and re

2011-09-15 Thread Alan Plum

On 2011-09-15 15:02, MRAB wrote:

The regex module at http://pypi.python.org/pypi/regex currently uses a
compromise, where it matches 'I' with 'i' and also 'I' with 'ı' and 'İ'
with 'i'.

I was wondering if it would be preferable to have a TURKIC flag instead
("(?T)" or "(?T:...)" in the pattern).


I think the problem many people ignore when coming up with solutions 
like this is that while this behaviour is pretty much unique for Turkish 
script, there is no guarantee that Turkish substrings won't appear in 
other language strings (or vice versa).


For example, foreign names in Turkish are often given as spelled in 
their native (non-Turkish) script variants. Likewise, Turkish names in 
other languages are often given as spelled in Turkish.


The Turkish 'I' is a peculiarity that will probably haunt us programmers 
until hell freezes over. Unless Turkey abandons its traditional 
orthography or people start speaking only a single language at a time 
(including names), there's no easy way to deal with this.


In other words: the only way to make use of your proposed flag is if you 
have a fully language-tagged input (e.g. an XML document making 
extensive use of xml:lang) and only ever apply regular expressions to 
substrings containing one culture at a time.

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


Turkic I and re

2011-09-15 Thread MRAB

I'm interested to know the opinion of Turkish users of the re or regex
module.

When the re module performs a case-insensitive match, it matches 'I'
with 'i'. In Turkish, however, it should match 'I' with 'ı' and 'İ'
with 'i'.

The regex module at http://pypi.python.org/pypi/regex currently uses a
compromise, where it matches 'I' with 'i' and also 'I' with 'ı' and 'İ'
with 'i'.

I was wondering if it would be preferable to have a TURKIC flag instead
("(?T)" or "(?T:...)" in the pattern).

Without the Turkic flag it would match 'I' with 'i'; with Turkic flag
it would match 'I' with 'ı' and 'İ' with 'i'.
--
http://mail.python.org/mailman/listinfo/python-list


What is wrong with this code?

2011-09-15 Thread superhappyfuntime
it's not running. here it is: 



#this is antiWYSIWYG, an easy to learn cap for begginners to LaTeX.


#this is defines what means what. you can just read howto.pdf instead 
of this part.
here it is: = '\begin{document}'
it's an article = '\documentclass article'
it's a book = '\documentclass{book}'
it's a letter = '\documentclass{letter}'
it's a report = '\documentclass{report}'
it's called = '\title{'
it's over! = '\end{document}'




#this is where you come in: type what you want below using the terms 
explained in howto.pdf 


 print ('it's an article it's called test} here it is: Hello World! 
it's over!')


-- 
I'm trying a new usenet client for Mac, Nemo OS X, since 0 days.
You can download it at http://www.malcom-mac.com/nemo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cause __init__ to return a different class?

2011-09-15 Thread Jonathan Hartley
Perhaps a more idiomatic way of achieving the same thing is to use a factory 
function, which returns instances of different classes:

  def PersonFactory(foo):
  if foo:
 return Person()
  else:
 return Child()


Apologies if the code is messed up, I'm posting from Google groups web UI.
-- 
http://mail.python.org/mailman/listinfo/python-list


How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
Hi all,

You can do:

def foo():
"foodoc"
pass

function = type(lambda:0)
foo2 = function(foo.__code__, globals())
assert foo2.__doc__ == "foodoc"

I am wondering how the function constructor knows that foo.__code__
has a docstring.  I can see that

foo.__code__.co_consts == ('foodoc',)

But I can't find where in foo.__code__ is stored the information that
the first constant in foo.__code__ is actually a docstring.

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


Re: help regarding re.search

2011-09-15 Thread Sagar Neve
Hey
Thanks.

I just resolved it and yes you are right there was a (hidden) new-line to
it. I found it in a crude way of putting dots before and after.  I was to
post about it here and saw your message.

I was not knowing about %r. Thanks for that. Thats a good addition to my
knowledge.

Thanks a bunch of all. My day is saved.

Best Regards,
Sagar Neve.


On Thu, Sep 15, 2011 at 2:35 PM, Gelonida N  wrote:

> Hi Sagar,
>
> In order to be able to help you I propose following:
>
> On 09/15/2011 06:54 AM, Sagar Neve wrote:
> . . .
> > print "hello..Man_Param=%s,Opt_Param1=%s,
> > Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)
>
> Change above line into
>
> > print "hello..Man_Param=%r,Opt_Param1=%r,
> > Opt_Param2=%r\n" %(Man_Param,Opt_Param1,Opt_Param2)
>
>
> and show us the output of an example which is NOT working.
>
> printing with '%r" might help to show some 'hidden special characters'
>
>
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method:wrong structure

2011-09-15 Thread Nizamov Shawkat
>
>     loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
>

comma instead of dot after self.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-15 Thread Gelonida N
Hi Sagar,

In order to be able to help you I propose following:

On 09/15/2011 06:54 AM, Sagar Neve wrote:
. . .
> print "hello..Man_Param=%s,Opt_Param1=%s,
> Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)

Change above line into

> print "hello..Man_Param=%r,Opt_Param1=%r,
> Opt_Param2=%r\n" %(Man_Param,Opt_Param1,Opt_Param2)


and show us the output of an example which is NOT working.

printing with '%r" might help to show some 'hidden special characters'







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


Re: stackoverflow and c.l.py

2011-09-15 Thread Chris Angelico
On Thu, Sep 15, 2011 at 1:05 PM, Westley Martínez  wrote:
> This is really what I love and hate about the internet.  It's full of
> people who argue for the sake of venting their internal frustrations.
> How many discussions comparing declarative and imperative programming
> languages have you seen on the web?

Yes, it's both normal and useful on the internet to break off
conversation to argue about a minor technicality. But it's completely
inappropriate in other contexts, to the point that it can be used for
comedy. Two characters, in the middle of a rather heated debate, stop
to discuss grammar:

"Listen - I've come to pinch her!"
"Mercy! Whom?"
"You mean who."
"Nay! It is the accusative after the verb!"

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


Re: method:wrong structure

2011-09-15 Thread Chris Rebert
2011/9/15 守株待兔 <1248283...@qq.com>:
> there are  three  programs,all of them  left  main  structure,
> code0 is ok,i don't know why code2 and code3 can't run,how to fix them?
> code0
> class   webdata(object):
>     def  __init__(self,arg):
>
>     def  loadequity(self):
>
>     def  loadoption(self):
>
>     #loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
>
>     def  run(self):
>
> if  __name__=="__main__":
>  s=webdata('equity').run()
>  s.loadequity()
>
> code1
> class   webdata(object):
>     def  __init__(self,arg):
>
>     def  loadequity(self):
>
>     def  loadoption(self):
>
>     loadstatus={'equity':self.loadequity(),'option':self,loadoption()}

Class definitions are executable code. So the assignment to loadstatus
happens *while the class webdata is still being defined*. There is
therefore no class instance object or `self` at this point, hence the
error when you try and do self.loadequity(): you're trying to call an
instance method before it's even possible for there to be instances of
the class.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


method:wrong structure

2011-09-15 Thread 守株待兔
there are  three  programs,all of them  left  main  structure,
code0 is ok,i don't know why code2 and code3 can't run,how to fix them?
code0
class   webdata(object):
def  __init__(self,arg):
  
def  loadequity(self):

def  loadoption(self):

#loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
  
def  run(self):  

if  __name__=="__main__":
 s=webdata('equity').run()
 s.loadequity()   

code1
class   webdata(object):
def  __init__(self,arg):
  
def  loadequity(self):

def  loadoption(self):

loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
  
def  run(self):

  
if  __name__=="__main__":
 s=webdata('equity').run()
 loadstatus['equity']

wrong output is 
name 'self' is not defined


code2
class   webdata(object):
def  __init__(self,arg):
  
def  loadequity(self):

def  loadoption(self):

loadstatus={'equity':loadequity(),'option':loadoption()}
  
def  run(self):  

if  __name__=="__main__":
 s=webdata('equity').run()
 s.loadequity() 

wrong output is :
TypeError: loadequity() takes exactly 1 argument (0 given)-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-15 Thread john
On Sep 14, 4:58 pm, Steven D'Aprano  wrote:
> memilanuk wrote:
> > On 09/14/2011 05:47 AM, Chris Angelico wrote:
> >> The SNR here isn't bad either. Most of the spam gets filtered out, and
> >> even stuff like Ranting Rick posts can be of some amusement when it's
> >> a slow day...
>
> > I subscribe to the list via Gmane, and if 'most of the spam' gets
> > filtered out, I'd hate to see how much gets submitted as I still see 2-5
> > minimum blatant spam per day on here.
>
> 2-5 spam posts is nothing. (Well, I know any spam is too much spam, but
> still.) Since nearly all of it is obvious, it's easy to filter out of your
> mail client, news client, or if all else fails, your attention. The hard
> ones to ignore are the ones that look like they might be legitimate, but
> fortunately most spammers are too lazy or stupid to bother with even the
> most feeble disguise.
>
> Either way, I don't consider half a dozen spam posts a day to be anything
> more than a minor distraction.
>
> Commercial spam is annoying, but otherwise harmless because it is so easy to
> filter. What's really the problem is crackpots, trollers and griefers,
> because there is a terrible temptation to engage them in debate: "someone
> is wrong on the Internet!". If you want to see a news group gone bad, go to
> something like sci.math. You can't move for the cranks "disproving"
> Cantor's Diagonal Theorem and Special Relativity and proving that 10**603
> is the One True Actual Infinity (I'm not making that last one up!).
>
> --
> Steven

And, all this time, I'd thought it was ((10**603) - 1) that was the
highest.  Oh, well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stackoverflow and c.l.py

2011-09-15 Thread Westley Martínez
On Thu, Sep 15, 2011 at 09:58:32AM +1000, Steven D'Aprano wrote:
> memilanuk wrote:
> 
> > On 09/14/2011 05:47 AM, Chris Angelico wrote:
> >> The SNR here isn't bad either. Most of the spam gets filtered out, and
> >> even stuff like Ranting Rick posts can be of some amusement when it's
> >> a slow day...
> > 
> > I subscribe to the list via Gmane, and if 'most of the spam' gets
> > filtered out, I'd hate to see how much gets submitted as I still see 2-5
> > minimum blatant spam per day on here.
> 
> 2-5 spam posts is nothing. (Well, I know any spam is too much spam, but
> still.) Since nearly all of it is obvious, it's easy to filter out of your
> mail client, news client, or if all else fails, your attention. The hard
> ones to ignore are the ones that look like they might be legitimate, but
> fortunately most spammers are too lazy or stupid to bother with even the
> most feeble disguise.
> 
> Either way, I don't consider half a dozen spam posts a day to be anything
> more than a minor distraction.
> 
> Commercial spam is annoying, but otherwise harmless because it is so easy to
> filter. What's really the problem is crackpots, trollers and griefers,
> because there is a terrible temptation to engage them in debate: "someone
> is wrong on the Internet!". If you want to see a news group gone bad, go to
> something like sci.math. You can't move for the cranks "disproving"
> Cantor's Diagonal Theorem and Special Relativity and proving that 10**603
> is the One True Actual Infinity (I'm not making that last one up!).
> 
> 
> 

This is really what I love and hate about the internet.  It's full of
people who argue for the sake of venting their internal frustrations.
How many discussions comparing declarative and imperative programming
languages have you seen on the web?  They are everywhere.  Really,
there's no point to these discussions, just use what you like, but it's
still fun to read and think.  This goes into all kinds of subjects.
That said, this post is somewhat of a rant and may spur debate.  It is
what it is, no matter where you are, the internet is just a natural
breeder of this kind of thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Change Location in the google search page

2011-09-15 Thread sajuptpm
Hi,

I want to open Google search page and Change the Location link in the
left hand nav of Google) from the users current location to a
different location, then return the results of the updated search.

I tried to change google search location through
http://www.google.co.in/preferences?hl=en#loc , but getting error
mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not
Found

Here is the code i tried

= 1

import re
import cookielib
from mechanize import Browser
import mechanize

br1= Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br1.set_cookiejar(cj)

br1.set_handle_robots(False)
br1.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

P_URL = "http://www.google.co.in/preferences?hl=en#loc";
s_page = br1.open(P_URL)
loc_form = br1.select_form(name="langform")
br1.form['luul'] = u'bangaluru' # <-- New location
resp = br1.submit()
print "-resp-",resp.read()


Output
===

$ python a11.py
Traceback (most recent call last):
  File "a11.py", line 94, in ?
resp = br1.submit()
  File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 541,
in submit
  File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 203,
in open
  File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line 255,
in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 404: Not Found


= 2


Tried this also, but getting blank google search page.

import re
from mechanize import Browser

LOGIN_URL = "http://www.google.co.in/search?q=new+york
+locksmith&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-
US:official&client=firefox-a"

br = Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686;
en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9
Firefox/3.0.1')]

s_page = br.open(LOGIN_URL)
loc_form = br.select_form(nr=1)
loc_text_fld = br.form.find_control(id='lc-input')
loc_text_fld.__dict__['_value'] = 'kerala' #Change the Location
resp = br.submit()

print "\n\n--resp--", resp.read() #Returning blank
google search page.



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