help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
i need to write a code which can sort the list in order of 'n' without use 
builtin functions 
can anyone help me how to do?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:04 PM,   wrote:
> i need to write a code which can sort the list in order of 'n' without use 
> builtin functions
> can anyone help me how to do?
> --
> http://mail.python.org/mailman/listinfo/python-list

http://lmgtfy.com/?q=sorting+algorithm
http://www.catb.org/esr/faqs/smart-questions.html

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


Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
What is the easiest way to reorder a sequence pseudo-randomly?

That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
2,1,4,3) that is different each time.

I'm writing a simulation and would like to visit all the nodes in a
different order at each iteration of the simulation to remove the risk
of a fixed order introducing spurious evidence of correlation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Using ACLs in JSON

2013-05-24 Thread Peter Brooks
I'm designing a system that should allow different views to different
audiences. I understand that I can use application logic to control
the access security, but it seems to me that it'd make more sense to
have this documented in the data-stream so that it's data-driven.

I was wondering if there was any standard way of doing this in JSON.
Alternatively, is there a better way of organising this in Python
that's compatible with JSON?

I've put an example of the sort of thing that I mean below. The idea
is that this object is accessible for viewing or deleting by the role
'HR' and available for change only to the owner of the record itself.
In addition, the record can be viewed by those with the role
'manager'. The syntax may be wrong, but I hope that my intention is
reasonably clear.

Is there an existing practice or standard for doing this sort of
thing?

{
"title" : "Example Schema",
"type"  : "object",
"version" : "1.0",
"properties": {
"firstname" : {
"type": "string"
},
"lastname" : {
"type": "string"
},
"age" : {
"description" : "Age in years",
"type": "integer",
"minimum": 0
}
},
"ACL-view": ["HR","Manager",["firstname","lastname"]],
"ACL-change": ["firstname","Lastname"],
"ACL-delete": ["HR"],
"required": ["firstname","lastname"]
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:14 PM, Peter Brooks
 wrote:
> What is the easiest way to reorder a sequence pseudo-randomly?
>
> That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> 2,1,4,3) that is different each time.
>
> I'm writing a simulation and would like to visit all the nodes in a
> different order at each iteration of the simulation to remove the risk
> of a fixed order introducing spurious evidence of correlation.

Permuting a sequence iteratively to cover every possibility? Good fun.

Here's one way of looking at it. Imagine the indices of all elements
are in some special "base" like so:

[a, b, c, d] --> a*4+b*3+c*2+d*1

Then iterate up to the highest possible value (ie 4*3*2*1), picking
indices for each accordingly. I don't know how efficient this will be,
but here's a simple piece of code to do it:

>>> def permute(lst,pos):
lst=lst[:] # Take a copy
ret=[None]*len(lst)
for i in range(len(lst)):
pos,idx=divmod(pos,len(lst))
ret[i]=lst[idx]
del lst[idx]
return ret

>>> for i in range(4*3*2*1):
permute([10,20,30,40],i)


[10, 20, 30, 40]
[20, 10, 30, 40]
[30, 10, 20, 40]
[40, 10, 20, 30]
[10, 30, 20, 40]
[20, 30, 10, 40]
[30, 20, 10, 40]
[40, 20, 10, 30]
[10, 40, 20, 30]
[20, 40, 10, 30]
[30, 40, 10, 20]
[40, 30, 10, 20]
[10, 20, 40, 30]
[20, 10, 40, 30]
[30, 10, 40, 20]
[40, 10, 30, 20]
[10, 30, 40, 20]
[20, 30, 40, 10]
[30, 20, 40, 10]
[40, 20, 30, 10]
[10, 40, 30, 20]
[20, 40, 30, 10]
[30, 40, 20, 10]
[40, 30, 20, 10]

It works, it produces a unique list for any given index provided, but
it's not the cleanest or most efficient. But I know someone'll improve
on it... or tell me I'm an idiot for not taking a more obvious
approach :)

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


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Fábio Santos
On 24 May 2013 09:41, "Chris Angelico"  wrote:
>
> On Fri, May 24, 2013 at 6:14 PM, Peter Brooks
>  wrote:
> > What is the easiest way to reorder a sequence pseudo-randomly?
> >
> > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> > 2,1,4,3) that is different each time.
> >
...
> It works, it produces a unique list for any given index provided, but
> it's not the cleanest or most efficient. But I know someone'll improve
> on it... or tell me I'm an idiot for not taking a more obvious
> approach :)
>
> ChrisA

I think that is pretty much itertools.permutations from the standard
library. The OP should check it out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:47 PM, Fábio Santos  wrote:
>
> On 24 May 2013 09:41, "Chris Angelico"  wrote:
>>
>> On Fri, May 24, 2013 at 6:14 PM, Peter Brooks
>>  wrote:
>> > What is the easiest way to reorder a sequence pseudo-randomly?
>> >
>> > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
>> > 2,1,4,3) that is different each time.
>> >
> ...
>
>> It works, it produces a unique list for any given index provided, but
>> it's not the cleanest or most efficient. But I know someone'll improve
>> on it... or tell me I'm an idiot for not taking a more obvious
>> approach :)
>>
>> ChrisA
>
> I think that is pretty much itertools.permutations from the standard
> library. The OP should check it out.

That works if all the permutations are wanted at once. Is there a way,
short of iterating over it N times, to request permutation #N? Or
maybe I'm misreading the OP and that's not a requirement.

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


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Terry Jan Reedy

On 5/24/2013 4:14 AM, Peter Brooks wrote:

What is the easiest way to reorder a sequence pseudo-randomly?

That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
2,1,4,3) that is different each time.

I'm writing a simulation and would like to visit all the nodes in a
different order at each iteration of the simulation to remove the risk
of a fixed order introducing spurious evidence of correlation.


random module has a shuffle function I believe


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


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote:

> What is the easiest way to reorder a sequence pseudo-randomly?

import random
random.shuffle(sequence)


The sequence is modified in place, so it must be mutable. Lists are okay, 
tuples are not.


> That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> 2,1,4,3) that is different each time.

You can't *guarantee* that it will be different each time. With a four-
item list, there are only 4! = 24 combinations, so on average you'll get 
the original order one time in 24. For a ten-item list, that is once 
every 3628800 times, and for a twenty-item list, once in 
243290200817664 times. But of course these are *random*, and there's 
always a chance of this:

http://dilbert.com/strips/comic/2001-10-25


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


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Ned Batchelder

On 5/24/2013 6:52 AM, Steven D'Aprano wrote:

On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote:


What is the easiest way to reorder a sequence pseudo-randomly?

import random
random.shuffle(sequence)


The sequence is modified in place, so it must be mutable. Lists are okay,
tuples are not.



That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
2,1,4,3) that is different each time.

You can't *guarantee* that it will be different each time. With a four-
item list, there are only 4! = 24 combinations, so on average you'll get
the original order one time in 24. For a ten-item list, that is once
every 3628800 times, and for a twenty-item list, once in
243290200817664 times. But of course these are *random*, and there's
always a chance of this:

http://dilbert.com/strips/comic/2001-10-25




Also, heed the note in the docs:  "Note that for even rather small 
len(x), the total number of permutations of /x/ is larger than the 
period of most random number generators; this implies that most 
permutations of a long sequence can never be generated."  The default 
random number generator has a period of 2**19937-1, which means that 
lists longer than 2080 have more permutations than the period of the 
generator (because factorial(2081) > 2**19937). Most shuffles involve 
lists far shorter than 2080, but it's still good to keep it in mind.


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


Polymoprhism question

2013-05-24 Thread RVic
I'm trying to figure out (or find an example) of polymorphism whereby I pass a 
commandline argument (a string) which comports to a class (in java, you would 
say that it comports to a given interface bu I don't know if there is such a 
thing in Python) then that class of that name, somehow gets intantiated from 
that string. This way, I can have similar classes, but have my program use 
various ones by simply changing the commandline argument.

Can anyone show me how this might be done in Python? Thanks.

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


Re: Debugging parallel nose tests?

2013-05-24 Thread Roy Smith

On May 24, 2013, at 5:05 AM, Jean-Michel Pichavant wrote:

> - Original Message -
>> In article ,
>> Dave Angel  wrote:
>> 
>>> On 05/23/2013 09:09 AM, Roy Smith wrote:
 
 
 
 nosetests --process-timeout=60 --processes=40 test_api.py
 
>>> 
>>> Do you have a 40-processor system?
>> 
>> No, but many of the tests are I/O bound.
> 
> Sorry to hijack your thread but what do you mean by that ? 

That means that a lot of time running the test is spent waiting for I/O (in 
this case, network reads), as opposed to actually running on a CPU.

> I have a lot of tests myself that spend most of their time writing and 
> reading files. Should I try to multiprocess  them ?

Maybe :-)

--
Roy Smith
r...@panix.com

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


Re: Polymoprhism question

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 04:40:22 -0700, RVic wrote:

> I'm trying to figure out (or find an example) of polymorphism whereby I
> pass a commandline argument (a string) which comports to a class (in
> java, you would say that it comports to a given interface bu I don't
> know if there is such a thing in Python) then that class of that name,
> somehow gets intantiated from that string. This way, I can have similar
> classes, but have my program use various ones by simply changing the
> commandline argument.
> 
> Can anyone show me how this might be done in Python? Thanks.


I'm not 100% sure I understand what you want, but my guess is you want 
something like this:


# A toy class.
class AClass(object):
def __init__(self, astring):
self.astring = astring
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self.astring)

# And some variations.
class BClass(AClass):
pass

class CClass(AClass):
pass


# Build a dispatch table, mapping the class name to the class itself.
TABLE = {}
for cls in (AClass, BClass, CClass):
TABLE[cls.__name__] = cls


# Get the name of the class, and an argument, from the command line.
# Or from the user. Any source of two strings will do.
# Data validation is left as an exercise.
import sys
argv = sys.argv[1:]
if not argv:
name = raw_input("Name of the class to use? ")
arg = raw_input("And the argument to use? ")
argv = [name, arg]


# Instantiate.
instance = TABLE[argv[0]](argv[1])
print instance


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


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Dave Angel

On 05/24/2013 04:04 AM, lokeshkopp...@gmail.com wrote:

i need to write a code which can sort the list in order of 'n' without use 
builtin functions
can anyone help me how to do?



You could sort, but you couldn't print out the results, so what's the 
point?  In Python 3.3 at least, print() is a built-in function.


Is the homework assignment more clearly worded than your summary?  And 
if so, how far have you gotten on it?


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


Utility to locate errors in regular expressions

2013-05-24 Thread Malte Forkel
Finding out why a regular expression does not match a given string can
very tedious. I would like to write a utility that identifies the
sub-expression causing the non-match. My idea is to use a parser to
create a tree representing the complete regular expression. Then I could
simplify the expression by dropping sub-expressions one by one from
right to left and from bottom to top until the remaining regex matches.
The last sub-expression dropped should be (part of) the problem.

As a first step, I am looking for a parser for Python regular
expressions, or a Python regex grammar to create a parser from.

But may be my idea is flawed? Or a similar (or better) tools already
exists? Any advice will be highly appreciated!

Malte

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


RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Carlos Nepomuceno
lol wtf?

If 'n' is the quantity of elements to be sorted there's 
no way you can write an algorithm with complexity O(n) for the worst 
case not knowing something special about the data.

For example, Quicksort will give you O(n*(log(n)) on average case (O(n^2) in 
the worst case).

You gotta be much more specific than that if you really need an O(n) code.

There's probably assumptions you didn't mention about the data if O(n) it's 
really what you're looking for.

PS: Looks like a joke as stated..


> Date: Fri, 24 May 2013 01:04:51 -0700
> Subject: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: lokeshkopp...@gmail.com
> To: python-list@python.org
>
> i need to write a code which can sort the list in order of 'n' without use 
> builtin functions
> can anyone help me how to do?
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read txt file, add to iptables not working on new host

2013-05-24 Thread JackM

Thanks for answering. Do you mean something like this?

outPut = os.popen('uname -a' '/sbin/iptables -V INPUT -s' + ' ' + IP + ' 
' + '-j  REJECT' )


Sorry but like I said, I have no experience with any of this.



On 5/23/2013 11:10 PM, Carlos Nepomuceno wrote:

Send the output of the following commands:

uname -a
/sbin/iptables -V




From: notr...@earthlink.net
Subject: Read txt file, add to iptables not working on new host
Date: Thu, 23 May 2013 22:44:38 -0400
To: python-list@python.org

First, let me say that I have no knowledge of or experience with Python
or Linux/Unix. I have a script which was written by a host tech person
that ran via cron on my old server. It was designed to read IP addresses
from a text file and add them to be blocked on iptables. That way, we
could add or remove IPs without involving tech support daily. It worked
great.

Then we changed hosts and this script is now throwing errors on the new
server. This host runs Python 2.6.6. This is the script:

#!/usr/bin/python
import os,time

##Input, Output, and TimeStamp
inFile = open('/var/www/html/mydomain.com/banlist.txt','r')
logFile = open('/var/log/banList.log','w')
stamp = time.asctime(time.localtime())


##Daily Flush of blockList rules before re-applying Blocks
os.popen('/sbin/iptables -F INPUT')
logFile.write(stamp), logFile.write('\n'), logFile.write('Flushing
Rules..\n')

##Loop to read in file and Apply rules to IPtables
for line in inFile.readlines():
tmp = line.split(';')
IP = tmp[0]
outPut = os.popen( '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' + '-j
REJECT' )
logFile.write(IP), logFile.write(' - Has been blocked '),
logFile.write(stamp),logFile.write


The errors we're getting are like these:

Bad argument `174.37.65.204'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `94.159.162.182'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `95.134.132.98'
Try `iptables -h' or 'iptables --help' for more information.
etc.

Entries from the banlist.txt are like these:

200.193.54.138; February 9, 2013, 7:42 am 
87.120.57.4; February 9, 2013, 7:42 am 
82.206.129.160; February 9, 2013, 7:43 am 
etc.

I know the error points to a bad iptables command.
Can someone tell me what change(s) I need to make to this script to get
it working again? Thanks.



--
My email address on the header is a non-monitored spam catching account.
I can be reached via http://www.wvnh.net/contact.htm

--





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


Re: Utility to locate errors in regular expressions

2013-05-24 Thread Devin Jeanpierre
On Fri, May 24, 2013 at 8:58 AM, Malte Forkel  wrote:
> As a first step, I am looking for a parser for Python regular
> expressions, or a Python regex grammar to create a parser from.

the sre_parse module is undocumented, but very usable.

> But may be my idea is flawed? Or a similar (or better) tools already
> exists? Any advice will be highly appreciated!

I think your task is made problematic by the possibility that no
single part of the regexp causes a match failure. What causes failure
depends on what branches are chosen with the |, *, +, ?, etc.
operators -- it might be a different character/subexpression for each
branch. And then there's exponentially many possible branches.

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


RE: Read txt file, add to iptables not working on new host

2013-05-24 Thread Carlos Nepomuceno
No, there's no need to change your python script, although it can be improved 
because as it is it may flush (delete all) iptables rules and let you 
vulnerable and don't create the new rules.

All you need to do is enter the commands in the shell and send it's output. The 
'iptables' have changed.



> From: notr...@earthlink.net
> Subject: Re: Read txt file, add to iptables not working on new host
> Date: Fri, 24 May 2013 09:08:26 -0400
> To: python-list@python.org
>
> Thanks for answering. Do you mean something like this?
>
> outPut = os.popen('uname -a' '/sbin/iptables -V INPUT -s' + ' ' + IP + '
> ' + '-j REJECT' )
>
> Sorry but like I said, I have no experience with any of this.
>
>
>
> On 5/23/2013 11:10 PM, Carlos Nepomuceno wrote:
>> Send the output of the following commands:
>>
>> uname -a
>> /sbin/iptables -V
>>
>>
>> 
>>> From: notr...@earthlink.net
>>> Subject: Read txt file, add to iptables not working on new host
>>> Date: Thu, 23 May 2013 22:44:38 -0400
>>> To: python-list@python.org
>>>
>>> First, let me say that I have no knowledge of or experience with Python
>>> or Linux/Unix. I have a script which was written by a host tech person
>>> that ran via cron on my old server. It was designed to read IP addresses
>>> from a text file and add them to be blocked on iptables. That way, we
>>> could add or remove IPs without involving tech support daily. It worked
>>> great.
>>>
>>> Then we changed hosts and this script is now throwing errors on the new
>>> server. This host runs Python 2.6.6. This is the script:
>>>
>>> #!/usr/bin/python
>>> import os,time
>>>
>>> ##Input, Output, and TimeStamp
>>> inFile = open('/var/www/html/mydomain.com/banlist.txt','r')
>>> logFile = open('/var/log/banList.log','w')
>>> stamp = time.asctime(time.localtime())
>>>
>>>
>>> ##Daily Flush of blockList rules before re-applying Blocks
>>> os.popen('/sbin/iptables -F INPUT')
>>> logFile.write(stamp), logFile.write('\n'), logFile.write('Flushing
>>> Rules..\n')
>>>
>>> ##Loop to read in file and Apply rules to IPtables
>>> for line in inFile.readlines():
>>> tmp = line.split(';')
>>> IP = tmp[0]
>>> outPut = os.popen( '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' + '-j
>>> REJECT' )
>>> logFile.write(IP), logFile.write(' - Has been blocked '),
>>> logFile.write(stamp),logFile.write
>>>
>>>
>>> The errors we're getting are like these:
>>>
>>> Bad argument `174.37.65.204'
>>> Try `iptables -h' or 'iptables --help' for more information.
>>> Bad argument `94.159.162.182'
>>> Try `iptables -h' or 'iptables --help' for more information.
>>> Bad argument `95.134.132.98'
>>> Try `iptables -h' or 'iptables --help' for more information.
>>> etc.
>>>
>>> Entries from the banlist.txt are like these:
>>>
>>> 200.193.54.138; February 9, 2013, 7:42 am 
>>> 87.120.57.4; February 9, 2013, 7:42 am 
>>> 82.206.129.160; February 9, 2013, 7:43 am 
>>> etc.
>>>
>>> I know the error points to a bad iptables command.
>>> Can someone tell me what change(s) I need to make to this script to get
>>> it working again? Thanks.
>>>
>>>
>>>
>>> --
>>> My email address on the header is a non-monitored spam catching account.
>>> I can be reached via http://www.wvnh.net/contact.htm
>>>
>>> --
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Utility to locate errors in regular expressions

2013-05-24 Thread Roy Smith
In article ,
 Malte Forkel  wrote:

> Finding out why a regular expression does not match a given string can
> very tedious. I would like to write a utility that identifies the
> sub-expression causing the non-match. My idea is to use a parser to
> create a tree representing the complete regular expression. Then I could
> simplify the expression by dropping sub-expressions one by one from
> right to left and from bottom to top until the remaining regex matches.
> The last sub-expression dropped should be (part of) the problem.
> 
> As a first step, I am looking for a parser for Python regular
> expressions, or a Python regex grammar to create a parser from.
> 
> But may be my idea is flawed? Or a similar (or better) tools already
> exists? Any advice will be highly appreciated!

I think this would be a really cool tool.  The debugging process I've 
always used is essentially what you describe.  I start try progressively 
shorter sub-patterns until I get a match, then try to incrementally add 
back little bits of the original pattern until it no longer matches.  
With luck, the problem will become obvious at that point.

Having a tool which automated this would be really useful.

Of course, most of Python user community are wimps and shy away from big 
hairy regexes [ducking and running].
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
Thank you all for those most helpful suggestions! random.shuffle does
precisely the job that I need quickly. Thank you for introducing me to
itertools, though, I should have remembered APL did this in a symbol
or two and I'm sure that itertools will come in handy in future.

Thanks for the warnings about random numbers too - I hope my lists
will be short enough for the permutations of the function to be
irrelevant. I don't need every single sequence to be unique, only that
the same sequence only occurs occasionally. My lists might get up to
the ~2k length one day, and I'll keep in mind the need, at that stage,
to use a different pseudo-random generator. Actually, thinking about
it, there is probably a source of non-algorithmically-derived 'random'
numbers somewhere on the net that would do the job nicely.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Utility to locate errors in regular expressions

2013-05-24 Thread Roy Smith
In article ,
 Devin Jeanpierre  wrote:

> On Fri, May 24, 2013 at 8:58 AM, Malte Forkel  wrote:
> > As a first step, I am looking for a parser for Python regular
> > expressions, or a Python regex grammar to create a parser from.
> 
> the sre_parse module is undocumented, but very usable.
> 
> > But may be my idea is flawed? Or a similar (or better) tools already
> > exists? Any advice will be highly appreciated!
> 
> I think your task is made problematic by the possibility that no
> single part of the regexp causes a match failure. What causes failure
> depends on what branches are chosen with the |, *, +, ?, etc.
> operators -- it might be a different character/subexpression for each
> branch. And then there's exponentially many possible branches.

That's certainly true.  The full power of regex makes stuff like this 
very hard to do in the general case.  That being said, people tend to 
write regexen which match hunks of text from left to right.

So, in theory, it's probably an intractable problem.  But, in practice, 
such a tool would actually be useful in a large set of real-life cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read txt file, add to iptables not working on new host

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 12:44 PM, JackM  wrote:
> outPut = os.popen( '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' +
> '-j REJECT' )

There's so much about this script that's less than Pythonic, but the
one thing I'd really like to see is a log of the exact command being
executed. Replace the above line with this:

command = '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' + '-j REJECT'
outPut = os.popen(command)
logFile.write(command+"\n")

That will show, in your log, exactly what's being executed. You should
then be able to execute that command in the shell and see the exact
same result. That might also show you the problem - it might be
obvious from the commands logged.

If that doesn't work, here's a rewrite of your code for cleanliness,
which still does what I think your original code does. See if they act
differently...

-- cut --

#!/usr/bin/python
import os
import time

# Input, Output, and TimeStamp
inFile = open('/var/www/html/mydomain.com/banlist.txt','r')
logFile = open('/var/log/banList.log','w')
stamp = time.asctime(time.localtime())

# Daily Flush of blockList rules before re-applying Blocks
os.popen('/sbin/iptables -F INPUT')
logFile.write(stamp+'\nFlushing Rules..\n')

# Loop to read in file and Apply rules to IPtables
for line in inFile:  # TODO: Use 'with' for a bit of protection
ip = line.split(';')[0]
output = os.popen( '/sbin/iptables -A INPUT -s ' + ip + ' -j REJECT' )
logFile.write(IP+' - Has been blocked\n')


-- cut --

Since the timestamp doesn't change across a run anyway, there's not
much point printing it out every time, and I'm also putting newlines
in the logfile. Beyond that, it should function the same way as the
original.

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread nn
On May 23, 2:42 pm, Dave Angel  wrote:
> On 05/23/2013 11:26 AM, Carlos Nepomuceno wrote:
>
> > 
> >> Date: Thu, 23 May 2013 06:44:05 -0700
> >> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> >> From: prueba...@latinmail.com
> >> To: python-l...@python.org
> > [...]
>
> You left out the part where a and f are initialized:
>
>  >>> a='%s'
>  >>> f=(3,5)
>
> > eggs(a,f)
> >> Traceback (most recent call last):
> >> File "", line 1, in 
> >> eggs(a,f)
> >> File "", line 1, in eggs
> >> def eggs(spam, ham): return spam % ham
> >> TypeError: not all arguments converted during string formatting
> > '%s'%(5%3)
> >> '2'
>
> > So % doesn't handle tuples! Why's that? Is it intentional (by design)?
>
> It's a conflict in the design.  A tuple is used to supply multiple
> arguments to the % operator.  So if you want to have a tuple as the
> first argument, you need to enclose it in another tuple.
>
> try the following:
>
> print a % (f,)
>
> The trouble is, it doesn't generalize very readily, so it's difficult to
> use in a function like eggs()
>
> --
> DaveA

It's all there, it's just that quoting ate it. Let's try this again:

>>> def eggs(spam, ham): return spam % ham
>>> def milk(beef, steak): return beef.format(steak)
>>> a='%s'
>>> c=9
>>> d=4
>>> e=[1,2]
>>> f=(3,5)
>>> d='{}'
>>> eggs(a,4)
'4'
>>> eggs(c,4)
1
>>> eggs(a,e)
'[1, 2]'
>>> eggs(a,f)

Traceback (most recent call last):
  File "", line 1, in 
eggs(a,f)
  File "", line 1, in eggs
def eggs(spam, ham): return spam % ham
TypeError: not all arguments converted during string formatting
>>> '%s'%(5%3)
'2'

>>> milk(d,4)
'4'
>>> milk(c,4)

Traceback (most recent call last):
  File "", line 1, in 
milk(c,4)
  File "", line 1, in milk
def milk(beef, steak): return beef.format(steak)
AttributeError: 'int' object has no attribute 'format'
>>> milk(d,e)
'[1, 2]'
>>> milk(d,f)
'(3, 5)'
>>> '{}'.format(5%3)
'2'

The three issues represented:
1. Functions in which both values of the operator are parameters might
not return a string but an integer instead. It is not always
immediately obvious when reading such functions if modulus or
formatting is intended.
2. Function doesn't handle tuple properly unless carefully written
3. Too much % noise because % is used for 3 things: the special
placeholder character inside format strings, the format operator and
the modulus operator.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 06:23:14 -0700, Peter Brooks wrote:


> Thanks for the warnings about random numbers too - I hope my lists will
> be short enough for the permutations of the function to be irrelevant. I
> don't need every single sequence to be unique, only that the same
> sequence only occurs occasionally. My lists might get up to the ~2k
> length one day, and I'll keep in mind the need, at that stage, to use a
> different pseudo-random generator. Actually, thinking about it, there is
> probably a source of non-algorithmically-derived 'random' numbers
> somewhere on the net that would do the job nicely.

That's massive overkill.

Take a closer look at what Ned wrote:

"The default random number generator has a period of 2**19937-1"

and consider the numbers.

For a list with 3000 items, there are 3000! possible permutations. That 
is approximately 10**21024. That is, a number with 21024 digits, or 
somewhere around a trillion trillion trillion ... trillion trillion, 
where there are 1752 "trillions".

If you could generate a million permutations a second, it would take you 
on average 10**210988 centuries before getting the original permutation 
again. That's the expected result you would get with a source of true 
randomness.

Instead, with Python's default pseudo-random number generator, you cannot 
get the full 3000! permutations, but only 2**19937-1 of them. Using the 
same calculation as above, that means that you will have to generate a 
million permutations per second for "only" 10**13783 centuries before 
getting the original permutation again.

There are uses where being able to generate any possible permutation is 
important, and the default PRNG is not sufficient. But merely shuffling 
your data around to avoid spurious correlations is not one of them. Save 
yourself a lot of development effort, and debugging, and just use 
random.shuffle.


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


Re: Utility to locate errors in regular expressions

2013-05-24 Thread Neil Cerutti
On 2013-05-24, Roy Smith  wrote:
> Of course, most of Python user community are wimps and shy away
> from big hairy regexes [ducking and running].

I prefer the simple, lumbering regular expressions like those in
the original Night of the Regular Expressions. The fast, powerful
ones from programs like the remake of Dawn of the GREP, just
aren't as scary.

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


Re: suppress newlines in my script

2013-05-24 Thread sloan949
On Thursday, May 23, 2013 1:49:02 PM UTC-7, sloa...@gmail.com wrote:
> I am importing lines from an external csv file and when I iterate through the 
> lines and increment, new lines are introduced.
> 
> How would I cut out the newlines.  I have attempted several pythonic strip() 
> and rstrip() how can i implent this?
> 
> 
> 
> 
> 
> import sys, os
> 
> 
> 
> f=open('europe_csv')
> 
> lines=f.readlines()
> 
> 
> 
> BU = 'Company,,'
> 
> PPP = 'Pre-ProdProd,,'
> 
> C1 = ',,'
> 
> Title = 'Site,Environment,'
> 
> NET1 = lines[4]
> 
> GW1 = lines[5]
> 
> M1 = lines[6]
> 
> PS1 = lines[7]
> 
> PE1 = lines[8]
> 
> C2 = ',,'
> 
> NET2 = lines[10]
> 
> GW2 = lines[11]
> 
> M2 = lines[12]
> 
> PS2 = lines[13]
> 
> PE2  = lines[14]
> 
> 
> 
> 
> 
> 
> 
> for count in range(64, 127):
> 
>  print NET1.format(count)
> 
>  print GW1.format(count)
> 
>  print M1
> 
>  print PS1.format(count)
> 
>  print PE1.format(count)
> 
>  print C2
> 
>  print NET2.format(count)
> 
>  print GW2.format(count)
> 
>  print M2
> 
>  print PS2.format(count)
> 
>  print PE2.format(count)

Thanks for the tip about the CSV module.  I did not know about that.   

Here are two lines from the CSV file:

,,172.20.{0}.0/27,172.20.{0}.32/27,172.20.{0}.64/27,29,172.20.{0}.96/27172.21.{0}.0/27,172.21.{0}.32/27,172.21.{0}.64/27,29,172.21.{0}.96/27
GW:,,172.20.{0}.1,172.20.{0}.33,172.20.{0}.65,,172.20.{0}.97,,GW:,,172.21.{0}.1,172.21.{0}.33,172.21.{0}.65,,172.21.{0}.97

This is the output:
,,

,,
GW:,,172.20.126.129,172.20.126.161,172.20.126.193,,172.20.126.225,,GW:,,172.21.126.129,172.21.126.161,172.21.126.193,,172.21.126.225

''

There are blank lines between and I am assuming that these are from newlines 
being introduced.

The idea of this script is/was to abstract the csv data so that I dont need to 
place them in the file as there are many seperate CSV files to import.

I hope I answered your questions.

The majority of the script is below.
#!/usr/bin/python

import sys, os
#import pdb

#pdb.set_trace()

f=open('europe_germanyfinalcsv')
lines=f.readlines()

BU = 'Europe Germany,,'
PPP = 'Pre-ProdProd,,'
C1 = ',,'
Title = 'Site,Environment,vApp Web,vApp App,vApp Data,Hosts Per 
Net,Reserved,,Site,Environment,vApp Web,vApp App,vApp Data,Hosts Per 
Net,Reserved'
NET1 = lines[4]
GW1 = lines[5]
M1 = lines[6]
PS1 = lines[7]
PE1 = lines[8]


for count in range(64, 127):
 print NET1.format(count)
 print GW1.format(count)
 print M1
 print PS1.format(count)
 print PE1.format(count)
-- 
http://mail.python.org/mailman/listinfo/python-list


Piping processes works with 'shell = True' but not otherwise.

2013-05-24 Thread Luca Cerone
Hi everybody, 
I am new to the group (and relatively new to Python)
so I am sorry if this issues has been discussed (although searching for topics 
in the group I couldn't find a solution to my problem).

I am using Python 2.7.3 to analyse the output of two 3rd parties programs that 
can be launched in a linux shell as:

 program1 | program2

To do this I have written a function that pipes program1 and program2 (using 
subprocess.Popen) and the stdout of the subprocess, and a function that parses 
the output:

A basic example:

from subprocess import Popen, STDOUT, PIPE
def run():
  p1 = Popen(['program1'], stdout = PIPE, stderr = STDOUT)
  p2 = Popen(['program2'], stdin = p1.stdout, stdout = PIPE, stderr = STDOUT)
  p1.stdout.close()
  return p2.stdout


def parse(out):
  for row in out:
print row
#do something else with each line
  out.close()
  return parsed_output
   

# main block here

pout = run()

parsed = parse(pout)

#--- END OF PROGRAM #

I want to parse the output of 'program1 | program2' line by line because the 
output is very large.

When running the code above, occasionally some error occurs (IOERROR: [Errno 
0]). However this error doesn't occur if I code the run() function as:

def run():
  p = Popen('program1 | program2', shell = True, stderr = STDOUT, stdout = PIPE)
  return p.stdout

I really can't understand why the first version causes errors, while the second 
one doesn't.

Can you please help me understanding what's the difference between the two 
cases? 

Thanks a lot in advance for the help,
Cheers, Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Utility to locate errors in regular expressions

2013-05-24 Thread rusi
On May 24, 5:58 pm, Malte Forkel  wrote:
> Finding out why a regular expression does not match a given string can
> very tedious. I would like to write a utility that identifies the
> sub-expression causing the non-match. My idea is to use a parser to
> create a tree representing the complete regular expression. Then I could
> simplify the expression by dropping sub-expressions one by one from
> right to left and from bottom to top until the remaining regex matches.
> The last sub-expression dropped should be (part of) the problem.
>
> As a first step, I am looking for a parser for Python regular
> expressions, or a Python regex grammar to create a parser from.
>
> But may be my idea is flawed? Or a similar (or better) tools already
> exists? Any advice will be highly appreciated!
>
> Malte



python-specific:  http://kodos.sourceforge.net/
Online: http://gskinner.com/RegExr/
emacs-specific: re-builder and regex-tool http://bc.tech.coop/blog/071103.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread duncan smith

On 24/05/13 10:11, Chris Angelico wrote:

On Fri, May 24, 2013 at 6:47 PM, Fábio Santos  wrote:


On 24 May 2013 09:41, "Chris Angelico"  wrote:


On Fri, May 24, 2013 at 6:14 PM, Peter Brooks
 wrote:

What is the easiest way to reorder a sequence pseudo-randomly?

That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
2,1,4,3) that is different each time.


...


It works, it produces a unique list for any given index provided, but
it's not the cleanest or most efficient. But I know someone'll improve
on it... or tell me I'm an idiot for not taking a more obvious
approach :)

ChrisA


I think that is pretty much itertools.permutations from the standard
library. The OP should check it out.


That works if all the permutations are wanted at once. Is there a way,
short of iterating over it N times, to request permutation #N? Or
maybe I'm misreading the OP and that's not a requirement.

ChrisA



A long time ago I wrote some code to do that.


import gmpy

def LexPermFromIndex(items, index):
n = len(items)
inds = range(n)
perm = []
for i in range(1, n+1):
r, index = divmod(index, gmpy.fac(n-i))
r = int(r)
perm.append(inds[r])
inds = inds[:r] + inds[r+1:]

return [items[i] for i in perm]


>>> LexPermFromIndex([1,2,3,4], 0)
[1, 2, 3, 4]
>>> LexPermFromIndex([1,2,3,4], 1)
[1, 2, 4, 3]
>>> LexPermFromIndex([1,2,3,4], 10)
[2, 4, 1, 3]
>>>


I can't remember exactly why I wrote it. But I also have something for 
generating a permutation's index and similar functions for combinations.


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


RE: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 01:14:45 -0700
> Subject: Simple algorithm question - how to reorder a sequence economically
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
>
> What is the easiest way to reorder a sequence pseudo-randomly?
>
> That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> 2,1,4,3) that is different each time.
>
> I'm writing a simulation and would like to visit all the nodes in a
> different order at each iteration of the simulation to remove the risk
> of a fixed order introducing spurious evidence of correlation.
> --
> http://mail.python.org/mailman/listinfo/python-list

I don't know what "spurious evidence of correlation" is. Can you give a 
mathematical definition?

Here's a snippet for creating a random shuffle by Fisher–Yates algorithm:

def FY_shuffle(l):
    from random import randint
    for i in range(len(l)-1,0,-1):
    j = randint(0,i)
    l[j],l[i] = l[i],l[j]

It looks just like random.shuffle() mentioned before, but you can change it as 
you see fit.

If you can afford to test all permutations you can iterate over it by doing:

>>> from itertools import permutations
>>> l=range(4)
>>> l
[0, 1, 2, 3]
>>> for i in permutations(l): print i
...
(0, 1, 2, 3)
(0, 1, 3, 2)
(0, 2, 1, 3)
[...]
(3, 1, 2, 0)
(3, 2, 0, 1)
(3, 2, 1, 0)
>>>

Note that 'i' is a tuple.

If you need a list of all permutations to make a selection:

>>> l=range(4)
>>> l
[0, 1, 2, 3]
>>> [list(i) for i in permutations(l)]
[[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 
2, 1], [1, 0, 2, 3], [1, 0, 3, 2], [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], 
[1, 3, 2, 0], [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0], [2, 3, 0, 
1], [2, 3, 1, 0], [3, 0, 1, 2], [3, 0, 2, 1], [3, 1, 0, 2], [3, 1, 2, 0], [3, 
2, 0, 1], [3, 2, 1, 0]]

This will produce big lists:
-for 10 elements (l=range(10)) the size of the list is about 30MB (on Windows).
-for 11 elements (l=range(11)) the size of the list is about 335MB (on 
Windows). It took more than 7GB for CPython 2.7.5 to create that list.

Didn't try after that.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread Carlos Nepomuceno

> Date: Thu, 23 May 2013 19:29:14 -0700
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> From: dihedral88...@gmail.com
[...]
> Could a separate instance like the I/O device of a subprocess
> to be easily available in Python?
>
> The next question would be whether the flow of several I/O data streams could 
> be easily piped and manipulated in the high level
> programming designs without consuming too much resources.


I'm sorry but I don't understand your question.

Do you mean returning the output of another process to the caller? Like:

import subprocess
output = subprocess.check_output(['ping', 'google.com'])
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Using ACLs in JSON

2013-05-24 Thread Carlos Nepomuceno
Not exactly what you want but you may consider Google ACL XML[1].

If there aren't any system integration restrictions you can do what you think 
it's best... for now.


[1] https://developers.google.com/storage/docs/accesscontrol#applyacls



> Date: Fri, 24 May 2013 01:18:06 -0700
> Subject: Using ACLs in JSON
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
>
> I'm designing a system that should allow different views to different
> audiences. I understand that I can use application logic to control
> the access security, but it seems to me that it'd make more sense to
> have this documented in the data-stream so that it's data-driven.
>
> I was wondering if there was any standard way of doing this in JSON.
> Alternatively, is there a better way of organising this in Python
> that's compatible with JSON?
>
> I've put an example of the sort of thing that I mean below. The idea
> is that this object is accessible for viewing or deleting by the role
> 'HR' and available for change only to the owner of the record itself.
> In addition, the record can be viewed by those with the role
> 'manager'. The syntax may be wrong, but I hope that my intention is
> reasonably clear.
>
> Is there an existing practice or standard for doing this sort of
> thing?
>
> {
> "title" : "Example Schema",
> "type" : "object",
> "version" : "1.0",
> "properties": {
> "firstname" : {
> "type": "string"
> },
> "lastname" : {
> "type": "string"
> },
> "age" : {
> "description" : "Age in years",
> "type": "integer",
> "minimum": 0
> }
> },
> "ACL-view": ["HR","Manager",["firstname","lastname"]],
> "ACL-change": ["firstname","Lastname"],
> "ACL-delete": ["HR"],
> "required": ["firstname","lastname"]
> }
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read txt file, add to iptables not working on new host

2013-05-24 Thread JackM

So Chris, does this version look better? Changed to inFile to with.


#!/usr/bin/python
import os
import time

# Input, Output, and TimeStamp
logFile = open('/var/www/html/statistics/logs/banList.log','w')
stamp = time.asctime(time.localtime())

# Daily Flush of blockList rules before re-applying Blocks
os.popen('/sbin/iptables -F INPUT')
logFile.write(stamp+'\nFlushing Rules..\n')

# Loop to read in file and Apply rules to IPtables
with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
for line in inFile:  # TODO: Use 'with' for a bit of protection
ip = line.split(';')[0]
output = os.popen( '/sbin/iptables -A INPUT -s ' + ip + ' -j 
REJECT' )

logFile.write(ip+' - Has been blocked\n')





On 5/24/2013 9:54 AM, Chris Angelico wrote:

On Fri, May 24, 2013 at 12:44 PM, JackM  wrote:

 outPut = os.popen( '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' +
'-j REJECT' )


There's so much about this script that's less than Pythonic, but the
one thing I'd really like to see is a log of the exact command being
executed. Replace the above line with this:

 command = '/sbin/iptables -A INPUT -s' + ' ' + IP + ' ' + '-j REJECT'
 outPut = os.popen(command)
 logFile.write(command+"\n")

That will show, in your log, exactly what's being executed. You should
then be able to execute that command in the shell and see the exact
same result. That might also show you the problem - it might be
obvious from the commands logged.

If that doesn't work, here's a rewrite of your code for cleanliness,
which still does what I think your original code does. See if they act
differently...

-- cut --

#!/usr/bin/python
import os
import time

# Input, Output, and TimeStamp
inFile = open('/var/www/html/mydomain.com/banlist.txt','r')
logFile = open('/var/log/banList.log','w')
stamp = time.asctime(time.localtime())

# Daily Flush of blockList rules before re-applying Blocks
os.popen('/sbin/iptables -F INPUT')
logFile.write(stamp+'\nFlushing Rules..\n')

# Loop to read in file and Apply rules to IPtables
for line in inFile:  # TODO: Use 'with' for a bit of protection
 ip = line.split(';')[0]
 output = os.popen( '/sbin/iptables -A INPUT -s ' + ip + ' -j REJECT' )
 logFile.write(IP+' - Has been blocked\n')


-- cut --

Since the timestamp doesn't change across a run anyway, there's not
much point printing it out every time, and I'm also putting newlines
in the logfile. Beyond that, it should function the same way as the
original.

ChrisA




--
My email address on the header is a non-monitored spam catching account. 
I can be reached via http://www.wvnh.net/contact.htm


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


Re: Using ACLs in JSON

2013-05-24 Thread Michael Torrie
On 05/24/2013 02:18 AM, Peter Brooks wrote:
> I'm designing a system that should allow different views to different
> audiences. I understand that I can use application logic to control
> the access security, but it seems to me that it'd make more sense to
> have this documented in the data-stream so that it's data-driven.
> 
> I was wondering if there was any standard way of doing this in JSON.
> Alternatively, is there a better way of organising this in Python
> that's compatible with JSON?

While I don't understand exactly what you're using JSON for, and nor do
I understand the purpose of the JSON structure you posted, I can say
that ACLs have nothing to do with JSON.

JSON is simply a data markup format, like HTML, XML, plain text, or an
INI file.  It's merely data.  If you want to restrict who sees what when
they request a chunk of data formatted using JSON, then you have to
enforce that in the code that's processing the request for data using
another mechanism.  And that mechanism depends on how your clients ask
for JSON data, and what code is serving or generating the JSON data.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read txt file, add to iptables not working on new host

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 2:32 AM, JackM  wrote:
> So Chris, does this version look better? Changed to inFile to with.
>

Heh, I didn't know you knew about with :) Since you know how to use
it, you probably also know why it's useful. Anyway, the main thing is
to see the exact command that's being executed, which you then should
be able to try at a shell prompt.

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


Re: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread Andreas Perstinger

On 24.05.2013 17:25, Carlos Nepomuceno wrote:



Date: Thu, 23 May 2013 19:29:14 -0700
Subject: Re: PEP 378: Format Specifier for Thousands Separator
From: dihedral88...@gmail.com
[some typical dihedral stuff]


I'm sorry but I don't understand your question.


Don't worry. I guess most people on this list don't understand it either.

It looks like dihedral is a bot although nobody knows for sure. Search 
for some other posts from him/her/it in the archive and form your own 
opinion.


IMHO you can simply ignore him/her/it.

Bye, Andreas

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


Total Beginner - Extracting Data from a Database Online (Screenshot)

2013-05-24 Thread logan . c . graham
Hey guys,

I'm learning Python and I'm experimenting with different projects -- I like 
learning by doing. I'm wondering if you can help me here:

http://i.imgur.com/KgvSKWk.jpg

What this is is a publicly-accessible webpage that's a simple database of 
people who have used the website. Ideally what I'd like to end up with is an 
excel spreadsheet with data from the columns #fb, # vids, fb sent?, # email tm.

I'd like to use Python to do it -- crawl the page and extract the data in a 
usable way.

I'd love your input! I'm just a learner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread John Ladasky
On Friday, May 24, 2013 3:52:18 AM UTC-7, Steven D'Aprano wrote:
> On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote:
> 
> > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> > 2,1,4,3) that is different each time.
> 
> You can't *guarantee* that it will be different each time. 

Well, within limits, you can guarantee a LONG TIME between repeats.  And that 
may be good enough for Peter's purpose. 

When the number of elements in your sequence is short enough (the right value 
of "short enough" is at least partially a matter of opinion, and the amount of 
RAM available, but I would guess n < 10 myself), use itertools.permutations to 
generate all the possibilities at once -- call this list p.  Store p in memory. 
 Then shuffle p, and use its elements one at a time.  If you get to the end of 
p and need to keep working, it's up to you whether to shuffle p a second time.  
If you don't reshuffle p, it guarantees the maximum interval between reusing 
the same permutation.

Use random.shuffle on your sequence directly, when your sequence has a larger 
number of elements.  This doesn't guarantee that two successive permutations 
will not be identical, but the probability is of course very low.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error with python 3.3.2 and https

2013-05-24 Thread asianavatar
So apparently switching the http to https in the proxyHandler call did the 
trick. Thanks for all the help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Utility to locate errors in regular expressions

2013-05-24 Thread Christian Gollwitzer

Am 24.05.13 14:58, schrieb Malte Forkel:

Finding out why a regular expression does not match a given string can
very tedious. I would like to write a utility that identifies the
sub-expression causing the non-match.


Try

http://laurent.riesterer.free.fr/regexp/

it shows the subexpressions which cause the match by coloring the parts. 
Not exacty what you want, but very intuitive and powerful. Beware this 
is Tcl and there might be subtle differences in RE syntax, but largely 
it's the same.


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


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
On May 24, 5:00 pm, Carlos Nepomuceno 
wrote:
>
>
> I don't know what "spurious evidence of correlation" is. Can you give a 
> mathematical definition?
>
If I run the simulation with the same sequence, then, because event E1
always comes before event E2, somebody might believe that there is a
causative connection between them in the world that's being simulated,
when, in fact, they only correlate in this way because the sequence is
not being shuffled. That's what it means.

Actually it'll be a bit more subtle than that, because each iteration
of the simulation updates all nodes in one time interval, the events
will not usually show the order of iteration - but, where there are
any secondary effects, that are related to the order in which the
nodes are updated, these will always happen the same way, which is my
concern.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using ACLs in JSON

2013-05-24 Thread Peter Brooks
On May 24, 6:42 pm, Michael Torrie  wrote:
> On 05/24/2013 02:18 AM, Peter Brooks wrote:
>
> > I'm designing a system that should allow different views to different
> > audiences. I understand that I can use application logic to control
> > the access security, but it seems to me that it'd make more sense to
> > have this documented in the data-stream so that it's data-driven.
>
> > I was wondering if there was any standard way of doing this in JSON.
> > Alternatively, is there a better way of organising this in Python
> > that's compatible with JSON?
>
> While I don't understand exactly what you're using JSON for, and nor do
> I understand the purpose of the JSON structure you posted, I can say
> that ACLs have nothing to do with JSON.
>
> JSON is simply a data markup format, like HTML, XML, plain text, or an
> INI file.  It's merely data.  If you want to restrict who sees what when
> they request a chunk of data formatted using JSON, then you have to
> enforce that in the code that's processing the request for data using
> another mechanism.  And that mechanism depends on how your clients ask
> for JSON data, and what code is serving or generating the JSON data.
>
Yes, you're right, I know that. However, I want the permissions
embedded in the data so that it's easy to verify, from the data, who
has access to which objects. The reason is to enforce transparency of
the access rights and to make them easy to grant and change without
needing to make any coding changes.

My question was whether anybody had taken a similar approach and found
a way that worked well with python or, even better, if there was a
standard way of doing this.

If nobody has done this, then I'm happy to invent my own method, but I
don't really want to reinvent wheels that might have been nicely
designed already.

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


Re: Using ACLs in JSON

2013-05-24 Thread Peter Brooks
On May 24, 6:13 pm, Carlos Nepomuceno 
wrote:
> Not exactly what you want but you may consider Google ACL XML[1].
>
> If there aren't any system integration restrictions you can do what you think 
> it's best... for now.
>
> [1]https://developers.google.com/storage/docs/accesscontrol#applyacls
>
Thank you for the reference. I specifically don't want to use XML
itself, but I can adapt that to my purpose - great!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Polymoprhism question

2013-05-24 Thread RVic
Thanks Steven,

Yes, I see Python isn't going to do this very well, from what I can understand.

Lets say I have a type of class, and this type of class will always have two 
methods, in() and out().

Here is, essentially, what I am trying to do, but I don't know if this will 
make sense to you or if it is really doable in Python:  #thanks, RVic

import sys
argv = sys.argv[1:] 
ClassIamInstantiating = argv
ClassIamInstantiating.in("something")
x = ClassIamInstantiating.out()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suppress newlines in my script

2013-05-24 Thread Dave Angel

On 05/24/2013 09:59 AM, sloan...@gmail.com wrote:



 http://wiki.python.org/moin/GoogleGroupsPython >



  print PE2.format(count)


Thanks for the tip about the CSV module.  I did not know about that.


So why aren't you using it?  There's not much point in solving "the 
newlines problem" if you're going to later switch to a library which 
doesn't have the problem.  The csv module will eliminate the newlines, 
and the commas, organizing your data for you directly (assuming this 
really is a csv file, and that the separator is comma).  None of your 
present code seems to believe it's a csv file, so maybe that's just a 
misdirection.





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


Re: Read txt file, add to iptables not working on new host

2013-05-24 Thread Dave Angel

On 05/24/2013 12:32 PM, JackM wrote:

So Chris, does this version look better? Changed to inFile to with.


#!/usr/bin/python
import os
import time

# Input, Output, and TimeStamp
logFile = open('/var/www/html/statistics/logs/banList.log','w')
stamp = time.asctime(time.localtime())

# Daily Flush of blockList rules before re-applying Blocks
os.popen('/sbin/iptables -F INPUT')
logFile.write(stamp+'\nFlushing Rules..\n')

# Loop to read in file and Apply rules to IPtables
with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile:
 for line in inFile:  # TODO: Use 'with' for a bit of protection
 ip = line.split(';')[0]


You want to write the command to the logfile here, BEFORE you try the 
popen().  That way if there's a problem, you can see what it was about 
to try before it crashed.



 output = os.popen( '/sbin/iptables -A INPUT -s ' + ip + ' -j
REJECT' )
 logFile.write(ip+' - Has been blocked\n')






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


Re: Total Beginner - Extracting Data from a Database Online (Screenshot)

2013-05-24 Thread Dave Angel

On 05/24/2013 01:32 PM, logan.c.gra...@gmail.com wrote:

Hey guys,

I'm learning Python


Welcome.


and I'm experimenting with different projects -- I like learning by doing. I'm 
wondering if you can help me here:

na

What this is is a publicly-accessible webpage


No, it's just a jpeg file, an image.


that's a simple database of people who have used the website. Ideally what I'd 
like to end up with is an excel spreadsheet with data from the columns #fb, # 
vids, fb sent?, # email tm.

I'd like to use Python to do it -- crawl the page and extract the data in a 
usable way.



But there's no page to crawl.  You may have to start by finding an ocr 
to interpret the image as characters.  Or find some other source for 
your data.



I'd love your input! I'm just a learner.




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


Plotting with PyQwt

2013-05-24 Thread Sara Lochtie
Hi,

I'm trying to plot temperature vs. time using Qwt. I have temp data that i get 
in real time and I want to plot against time. So I thought I would have to use 
QwtPlot and QwtPlotCurve, so I did this first:

self.tempGraph = Qwt.QwtPlot(self)

curve =  QwtPlotCurve()
curve.setData(x, temp)



x is the time and temp is the data I have collected.

I know this isn't current, but I just don't know how to go about it. I haven't 
used Qwt before.

If anyone has some tips or advice for me that would be great!


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


Re: Plotting with PyQwt

2013-05-24 Thread Sara Lochtie
isn't correct*

On Friday, May 24, 2013 12:58:50 PM UTC-7, Sara Lochtie wrote:
> Hi,
> 
> 
> 
> I'm trying to plot temperature vs. time using Qwt. I have temp data that i 
> get in real time and I want to plot against time. So I thought I would have 
> to use QwtPlot and QwtPlotCurve, so I did this first:
> 
> 
> 
> self.tempGraph = Qwt.QwtPlot(self)
> 
> 
> 
> curve =  QwtPlotCurve()
> 
> curve.setData(x, temp)
> 
> 
> 
> 
> 
> 
> 
> x is the time and temp is the data I have collected.
> 
> 
> 
> I know this isn't current, but I just don't know how to go about it. I 
> haven't used Qwt before.
> 
> 
> 
> If anyone has some tips or advice for me that would be great!

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


Re: Polymoprhism question

2013-05-24 Thread Neil Cerutti
On 2013-05-24, RVic  wrote:
> Thanks Steven,
>
> Yes, I see Python isn't going to do this very well, from what I
> can understand.
>
> Lets say I have a type of class, and this type of class will
> always have two methods, in() and out().
>
> Here is, essentially, what I am trying to do, but I don't know
> if this will make sense to you or if it is really doable in
> Python:  #thanks, RVic
>
> import sys
> argv = sys.argv[1:] 
> ClassIamInstantiating = argv
> ClassIamInstantiating.in("something")
> x = ClassIamInstantiating.out()

This is pretty easy in Python using the __name__ attribute.

import sys

class A:
 def in(self):
   print("A in")
 def out(self):
   print("A out")

class B:
 def in(self):
   print("B in")
 def out(self):
   print("B out")

classes = {cls.__name__: cls for cls in (A, B)}

ArgType = classes[sys.agrv[1]]

arg = ArgType()

arg.in("test")
arg.out("test")

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


Ldap module and base64 oncoding

2013-05-24 Thread Joseph L. Casale
I have some data I am working with that is not being interpreted as a string 
requiring
base64 encoding when sent to the ldif module for output.

The base64 string parsed is ZGV0XDMzMTB3YmJccGc= and the raw string is 
det\3310wbb\pg.
I'll admit my understanding of the handling requirements of non ascii data in 
2.7 is weak
and as such I am failing at adjusting the regex that deduces is the string 
contains characters
requiring base64 encoding when being output.

Any insight, or nudges in the right direction would be appreciated!
Thanks,
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-24 Thread Carlos Nepomuceno
lol that reminds me of George! lol
;)


> Date: Fri, 24 May 2013 19:28:29 +0200
> From: andiper...@gmail.com
> To: python-list@python.org
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
>
> On 24.05.2013 17:25, Carlos Nepomuceno wrote:
>> 
>>> Date: Thu, 23 May 2013 19:29:14 -0700
>>> Subject: Re: PEP 378: Format Specifier for Thousands Separator
>>> From: dihedral88...@gmail.com
>>> [some typical dihedral stuff]
>>
>> I'm sorry but I don't understand your question.
>
> Don't worry. I guess most people on this list don't understand it either.
>
> It looks like dihedral is a bot although nobody knows for sure. Search
> for some other posts from him/her/it in the archive and form your own
> opinion.
>
> IMHO you can simply ignore him/her/it.
>
> Bye, Andreas
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Using ACLs in JSON

2013-05-24 Thread Carlos Nepomuceno
You welcome! Can you send me whatever you decide is best to your case?

I'd like to have an example just in case I have to do that in the future.

I think that approach is gonna become more prevalent in the coming years. ;)


> Date: Fri, 24 May 2013 12:08:03 -0700
> Subject: Re: Using ACLs in JSON
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
>
> On May 24, 6:13 pm, Carlos Nepomuceno 
> wrote:
>> Not exactly what you want but you may consider Google ACL XML[1].
>>
>> If there aren't any system integration restrictions you can do what you 
>> think it's best... for now.
>>
>> [1]https://developers.google.com/storage/docs/accesscontrol#applyacls
>>
> Thank you for the reference. I specifically don't want to use XML
> itself, but I can adapt that to my purpose - great!
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 12:01:35 -0700
> Subject: Re: Simple algorithm question - how to reorder a sequence 
> economically
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
>
> On May 24, 5:00 pm, Carlos Nepomuceno 
> wrote:
>>
>>
>> I don't know what "spurious evidence of correlation" is. Can you give a 
>> mathematical definition?
>>
> If I run the simulation with the same sequence, then, because event E1
> always comes before event E2, somebody might believe that there is a
> causative connection between them in the world that's being simulated,
> when, in fact, they only correlate in this way because the sequence is
> not being shuffled. That's what it means.

Correlation does not imply causation. If "somebody" is an expert system and you 
want to avoid it's recognition and/or triggering of some kind, and you can't or 
don't want to change it's behavior, you may take the random way because it's 
cheaper.

> Actually it'll be a bit more subtle than that, because each iteration
> of the simulation updates all nodes in one time interval, the events
> will not usually show the order of iteration - but, where there are
> any secondary effects, that are related to the order in which the
> nodes are updated, these will always happen the same way, which is my
> concern.

You should have a more precise understanding of the dependence of the variables 
you taking in consideration before randomizing the series of events your are 
using for tests.

I suggest you start using PPMCC. If it's close to zero or negative you wouldn't 
have to mind about it! ;) 
-- 
http://mail.python.org/mailman/listinfo/python-list


Prepending string "@" to usernames

2013-05-24 Thread Thomas Murphy
Hi beloved list,

I'm having a dumb and SO doesn't seem to have this one answered. I was
sent a long list of instagram usernames to tag for a nightlife
announcement in this format(not real names(i hope))

cookielover93
TheGermanHatesSaurkraut
WhatsThatBoy932834

I'd like to turn this raw text into a list and prepend the @ symbol to
the front of each one, so they're good to go for pasting without me
having to manually add the @ to each one.

Here's where I got to:


raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
address_library = [raw_address.split()]
print address_library

for address in address_library:
final_address = "@" + str(address)
print final_address


However my output is:

[['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']]
@['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']


I know I'm iterating wrong. May I ask how?

--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Dan Stromberg
On Fri, May 24, 2013 at 3:53 PM, Thomas Murphy
wrote:

> Hi beloved list,
>
> I'm having a dumb and SO doesn't seem to have this one answered. I was
> sent a long list of instagram usernames to tag for a nightlife
> announcement in this format(not real names(i hope))
>
> cookielover93
> TheGermanHatesSaurkraut
> WhatsThatBoy932834
>
> I'd like to turn this raw text into a list and prepend the @ symbol to
> the front of each one, so they're good to go for pasting without me
> having to manually add the @ to each one.
>
> Here's where I got to:
>
>
> raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
> address_library = [raw_address.split()]
> print address_library
>
> for address in address_library:
> final_address = "@" + str(address)
> print final_address
>
>
> However my output is:
>
> [['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']]
> @['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']
>
>
> I know I'm iterating wrong. May I ask how?
>
> --
> Sincerely,
> Thomas Murphy
> Code Ninja
> 646.957.6115
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Maybe this is what you're looking for?

raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
address_library = raw_address.split()
print address_library

final_address = []
for address in address_library:
final_address.append("@" + str(address))
print final_address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Thomas Murphy
> Maybe this is what you're looking for?
>
> raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
> address_library = raw_address.split()
> print address_library
>
> final_address = []
> for address in address_library:
> final_address.append("@" + str(address))
> print final_address
>
Exactly it. Thank you so much Dan. Perfect!



--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115
-- 
http://mail.python.org/mailman/listinfo/python-list


Survey of Python-in-browser technologies

2013-05-24 Thread Dan Stromberg
I'm putting together a spreadsheet about Python-in-the-browser technologies
for my local python user group.

I've been hitting the mailing lists for the various implementations
already, but I thought I should run it by people here at least once.

Anyway, here it is:

http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html

If you see something inaccurate or omitted, please let me know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Andrew Berg
On 2013.05.24 17:53, Thomas Murphy wrote:
> I know I'm iterating wrong. May I ask how?
.split() already returns a list, so instead of iterating over the list and 
getting a single username, you iterate over the list and get a
single list.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Mark Lawrence

On 25/05/2013 00:04, Thomas Murphy wrote:

Maybe this is what you're looking for?

raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
address_library = raw_address.split()
print address_library

final_address = []
for address in address_library:
 final_address.append("@" + str(address))
print final_address


Exactly it. Thank you so much Dan. Perfect!



--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115



You can safely remove the call to str as address is already a string.

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Prepending string "@" to usernames

2013-05-24 Thread Tim Chase
On 2013-05-24 19:04, Thomas Murphy wrote:
>> raw_address = "cookielover93 TheGermanHatesSaurkraut
>> WhatsThatBoy932834" address_library = raw_address.split()
>> print address_library
>>
>> final_address = []
>> for address in address_library:
>> final_address.append("@" + str(address))
>> print final_address
>>
> Exactly it. Thank you so much Dan. Perfect!

Which can be tidily written as a list comprehension:

  final_address = ['@' + address for address in raw_address.split()]

-tkc


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


RE: Total Beginner - Extracting Data from a Database Online (Screenshot)

2013-05-24 Thread Carlos Nepomuceno
### table_data_extraction.py ###
# Usage: table[id][row][column]
# tables[0]   : 1st table
# tables[1][2]    : 3rd row of 2nd table
# tables[3][4][5] : cell content of 6th column of 5th row of 4th table
# len(table)  : quantity of tables
# len(table[6])   : quantity of rows of 7th table
# len(table[7][8]): quantity of columns of 9th row of 8th table

impor re
import urllib2

#to retrieve the contents of the page
page = urllib2.urlopen("http://example.com/page.html";).read().strip()

#to create the tables list
tables=[[re.findall('(.*?)',r,re.S) for r in 
re.findall('(.*?)',t,re.S)] for t in 
re.findall('(.*?)',page,re.S)]


Pretty simple. Good luck!


> Date: Fri, 24 May 2013 10:32:26 -0700
> Subject: Total Beginner - Extracting Data from a Database Online (Screenshot)
> From: logan.c.gra...@gmail.com
> To: python-list@python.org
>
> Hey guys,
>
> I'm learning Python and I'm experimenting with different projects -- I like 
> learning by doing. I'm wondering if you can help me here:
>
> http://i.imgur.com/KgvSKWk.jpg
>
> What this is is a publicly-accessible webpage that's a simple database of 
> people who have used the website. Ideally what I'd like to end up with is an 
> excel spreadsheet with data from the columns #fb, # vids, fb sent?, # email 
> tm.
>
> I'd like to use Python to do it -- crawl the page and extract the data in a 
> usable way.
>
> I'd love your input! I'm just a learner.
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Survey of Python-in-browser technologies

2013-05-24 Thread Carlos Nepomuceno
Thanks Dan! All of that is relevant but I'm specially concerned about security 
issues and think another column for that purpose would improve your database, 
although I'm not sure if there's data available or how it would be presented.


> Date: Fri, 24 May 2013 16:05:51 -0700 
> Subject: Survey of Python-in-browser technologies 
> From: drsali...@gmail.com 
> To: python-list@python.org 
>  
>  
> I'm putting together a spreadsheet about Python-in-the-browser  
> technologies for my local python user group. 
>  
> I've been hitting the mailing lists for the various implementations  
> already, but I thought I should run it by people here at least once. 
>  
> Anyway, here it is: 
>  
> http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html 
>  
> If you see something inaccurate or omitted, please let me know. 
>  
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Thomas Murphy
> Which can be tidily written as a list comprehension:
>
>   final_address = ['@' + address for address in raw_address.split()]
>
> -tkc
>
>
Ah! Thanks Tim…that tidiness is something I'm trying to head towards
in my own code. I'm trying to transition from the need to visually
write every little step out and write in these more powerful chunks.


--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Survey of Python-in-browser technologies

2013-05-24 Thread Dan Stromberg
Security is an important topic... but I'm not sure how I could gather info
about the security of these implementations.  Still, it's an idea worth at
least keeping in the back of my mind.

On Fri, May 24, 2013 at 4:43 PM, Carlos Nepomuceno <
carlosnepomuc...@outlook.com> wrote:

> Thanks Dan! All of that is relevant but I'm specially concerned about
> security issues and think another column for that purpose would improve
> your database, although I'm not sure if there's data available or how it
> would be presented.
>
> 
> > Date: Fri, 24 May 2013 16:05:51 -0700
> > Subject: Survey of Python-in-browser technologies
> > From: drsali...@gmail.com
> > To: python-list@python.org
> >
> >
> > I'm putting together a spreadsheet about Python-in-the-browser
> > technologies for my local python user group.
> >
> > I've been hitting the mailing lists for the various implementations
> > already, but I thought I should run it by people here at least once.
> >
> > Anyway, here it is:
> >
> > http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html
> >
> > If you see something inaccurate or omitted, please let me know.
> >
> >
> > -- http://mail.python.org/mailman/listinfo/python-list
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
On May 24, 11:33 pm, Carlos Nepomuceno 
wrote:
> 
>
>
>
>
>
>
>
>
>
> > Date: Fri, 24 May 2013 12:01:35 -0700
> > Subject: Re: Simple algorithm question - how to reorder a sequence 
> > economically
> > From: peter.h.m.bro...@gmail.com
> > To: python-l...@python.org
>
> > On May 24, 5:00 pm, Carlos Nepomuceno 
> > wrote:
>
> >> I don't know what "spurious evidence of correlation" is. Can you give a 
> >> mathematical definition?
>
> > If I run the simulation with the same sequence, then, because event E1
> > always comes before event E2, somebody might believe that there is a
> > causative connection between them in the world that's being simulated,
> > when, in fact, they only correlate in this way because the sequence is
> > not being shuffled. That's what it means.
>
> Correlation does not imply causation. If "somebody" is an expert system and 
> you want to avoid it's recognition and/or triggering of some kind, and you 
> can't or don't want to change it's behavior, you may take the random way 
> because it's cheaper.
>
> > Actually it'll be a bit more subtle than that, because each iteration
> > of the simulation updates all nodes in one time interval, the events
> > will not usually show the order of iteration - but, where there are
> > any secondary effects, that are related to the order in which the
> > nodes are updated, these will always happen the same way, which is my
> > concern.
>
> You should have a more precise understanding of the dependence of the 
> variables you taking in consideration before randomizing the series of events 
> your are using for tests.
>
If the scenario could be modelled mathematically, then there'd be no
point in writing the simulation.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Survey of Python-in-browser technologies

2013-05-24 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 17:11:18 -0700 
> Subject: Re: Survey of Python-in-browser technologies 
> From: drsali...@gmail.com 
> To: carlosnepomuc...@outlook.com 
> CC: python-list@python.org 
>  
>  
> Security is an important topic... but I'm not sure how I could gather  
> info about the security of these implementations.  Still, it's an idea  
> worth at least keeping in the back of my mind. 

Security specialists opinions and facts about known vulnerabilities would be a 
start, although it may be time consuming to gather all data.

Just a thought! ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Why won't Python 2/3 compile when I have valgrind installed?

2013-05-24 Thread Yves S. Garret
This isn't a huge issue, but I'm wondering.  I'm running
Mac OS X, I tried to configure with --with-valgrind and
this is the error that I got:

configure: error: Valgrind support requested but headers not available

Now, I have valgrind installed, so it should work, yes?
If someone has any extra info on this, I'd appreciate it.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Why won't Python 2/3 compile when I have valgrind installed?

2013-05-24 Thread Carlos Nepomuceno
You probably need 'valgrind-devel' package installed.


> Date: Fri, 24 May 2013 20:59:22 -0400 
> Subject: Why won't Python 2/3 compile when I have valgrind installed? 
> From: yoursurrogate...@gmail.com 
> To: python-list@python.org 
>  
> This isn't a huge issue, but I'm wondering.  I'm running 
> Mac OS X, I tried to configure with --with-valgrind and 
> this is the error that I got: 
>  
> configure: error: Valgrind support requested but headers not available 
>  
> Now, I have valgrind installed, so it should work, yes? 
> If someone has any extra info on this, I'd appreciate it. 
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Ldap module and base64 oncoding

2013-05-24 Thread Carlos Nepomuceno
Can you give an example of the code you have?


> From: jcas...@activenetwerx.com
> To: python-list@python.org
> Subject: Ldap module and base64 oncoding
> Date: Fri, 24 May 2013 21:00:01 +
>
> I have some data I am working with that is not being interpreted as a string 
> requiring
> base64 encoding when sent to the ldif module for output.
>
> The base64 string parsed is ZGV0XDMzMTB3YmJccGc= and the raw string is 
> det\3310wbb\pg.
> I'll admit my understanding of the handling requirements of non ascii data in 
> 2.7 is weak
> and as such I am failing at adjusting the regex that deduces is the string 
> contains characters
> requiring base64 encoding when being output.
>
> Any insight, or nudges in the right direction would be appreciated!
> Thanks,
> jlc
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Total Beginner - Extracting Data from a Database Online (Screenshot)

2013-05-24 Thread Dave Angel

On 05/24/2013 07:36 PM, Carlos Nepomuceno wrote:


 
page = urllib2.urlopen("http://example.com/page.html";).read().strip()

#to create the tables list
tables=[[re.findall('(.*?)',r,re.S) for r in re.findall('(.*?)',t,re.S)] 
for t in re.findall('(.*?)',page,re.S)]


Pretty simple. Good luck!


Only if the page is html, which the OP's was not. It was an image.  Try 
parsing that with regex.




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


Is python.org powered by CPython?

2013-05-24 Thread Carlos Nepomuceno
Is python.org powered by CPython?

Is it using WSGI?

What Python version is been used?

I already checked it's using Apache. Is it using mod_wsgi?

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


Re: Is python.org powered by CPython?

2013-05-24 Thread Ned Deily
In article ,
 Carlos Nepomuceno  wrote:
> Is python.org powered by CPython?

Like many websites, the python.org domain consists of a number of 
subdomains with several different webservers on various hosts.  AFAIK, 
the main www.python.org server is currently all (or mainly) static 
content served by Apache, although the static files are, in part, 
generated by a home-grown content management system powered by CPython.  
I'm not sure about the details of the other servers.  For example, both 
bugs.python.org and hg.python.org have CPython applications behind them: 
Roundup and Mercurial.

FTR, the whole python.org web domain is being redesigned so the details 
of what is under the covers will be changing.  Jesse Noller posted about 
the redesign process some months ago:

http://jessenoller.com/blog/2012/11/28/the-great-python-org-redesign

-- 
 Ned Deily,
 n...@acm.org

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


Re: Debugging parallel nose tests?

2013-05-24 Thread Roy Smith
In article ,
 Roy Smith  wrote:

> Is there some way to make nose print a report of how it partitioned the 
> tests across the various processes?

I never found such a feature, but I did figure out a way to do what I 
needed.  We use a system of unique id's to track HTTP requests through 
our system.  All you need do is add a X-Unique-Request-ID header and any 
of our server processes will log that.  So, I just had my test suite add:

X-Unique-Request-ID: name-of-test.process-id

to each HTTP request.  That got me what I was looking for (to know what 
tests were grouped into the same process).

> We're using:
> 
> nosetests --process-timeout=60 --processes=40 test_api.py

It turned out, the answer was purely a timing issue.  We had some tests 
that called out to facebook.  Those were (intermittently) so slow they 
caused the 60 second timeout to be exceeded.  The solution there was to 
pull the facebook tests out to their own suite (which we'll run in 
single-process mode).
-- 
http://mail.python.org/mailman/listinfo/python-list


Preventing nose from finding setup.py

2013-05-24 Thread Roy Smith
We've got a package (with an empty __init__.py), which contains a 
setup.py file.  When I run nosetests, the test discovery code finds 
setup.py, thinks it's a test, and tries to run it (with predictably poor 
results).

Is there some way to mark this file as not a test? If it was a method in 
a file, I would decorate it with @nottest, but that doesn't work here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Preventing nose from finding setup.py

2013-05-24 Thread Roy Smith
In article ,
 Roy Smith  wrote:

> We've got a package (with an empty __init__.py), which contains a 
> setup.py file.  When I run nosetests, the test discovery code finds 
> setup.py, thinks it's a test, and tries to run it (with predictably poor 
> results).

Ugh, I described that wrong.  Setup is also a package (with it's own 
empty __init__.py file).  But, the same problem applies.  Nosetests 
discovers it, tries to run it, and barfs with:

TypeError: Attribute setup of  is not a python 
function. Only functions or callables may be used as fixtures.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Total Beginner - Extracting Data from a Database Online (Screenshot)

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 3:32 AM,   wrote:
> http://i.imgur.com/KgvSKWk.jpg
>
> What this is is a publicly-accessible webpage...

If that's a screenshot of something that we'd be able to access
directly, then why not just post a link to the actual thing? More
likely I'm thinking it's NOT publicly accessible, which is why it's
been censored.

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


Python Magazine

2013-05-24 Thread DRJ Reddy
Planning to start a python online chronicle.What you want to see in it. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prepending string "@" to usernames

2013-05-24 Thread Larry Hudson

On 05/24/2013 03:53 PM, Thomas Murphy wrote:




Here's where I got to:


raw_address = "cookielover93 TheGermanHatesSaurkraut WhatsThatBoy932834"
address_library = [raw_address.split()]
print address_library

for address in address_library:
 final_address = "@" + str(address)
print final_address


However my output is:

[['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']]
@['cookielover93', 'TheGermanHatesSaurkraut', 'WhatsThatBoy932834']


I know I'm iterating wrong. May I ask how?

--
Sincerely,
Thomas Murphy
Code Ninja
646.957.6115



No, you're not iterating wrong, but you do have two errors:

1:  split() returns a list.  You are putting this list (as a single element) inside a list. 
Drop the square brackets.  Make it:  address_library = raw_address.split()


2:  In your for loop, you want the print _inside_ the loop not outside.  IOW, indent the print 
line.  The way you have it written it will only print the _last_ string.


 -=- Larry -=-

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


Re: Python Magazine

2013-05-24 Thread Mark Janssen
I always liked the daily Python-URL from Dr. Dobbs.

Summaries of salient discussions on python-dev, ideas, list.

interviews with devs on philosophies.

quote of the week

--m

On 5/24/13, DRJ Reddy  wrote:
> Planning to start a python online chronicle.What you want to see in it. :)
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
MarkJ
Tacoma, Washington
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread Roy Smith
In article <27969350-4dd8-4afa-881a-b4a2364b3...@googlegroups.com>,
 DRJ Reddy  wrote:

> Planning to start a python online chronicle.What you want to see in it. :)

Issue 1:

"Whitespace as syntax: mistake or magic?"

"Python 3 vs. IPv6: who will win the race for early adoption?"

"Did Python 3 break unicode?  The true story"

"Tuplemania: 100 things you can do with immutable lists"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread DRJ Reddy

> Issue 1:

> "Whitespace as syntax: mistake or magic?"
Thanks Roy :)

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


Re: Python Magazine

2013-05-24 Thread DRJ Reddy
On Saturday, May 25, 2013 9:08:28 AM UTC+5:30, zipher wrote:
> I always liked the daily Python-URL from Dr. Dobbs.
 
> quote of the week

Thanks zipher we have already planned to continue Python-URL and quote of the 
week.
We will plan for other things that you have mentioned.
Thanks again :)

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


RE: Python Magazine

2013-05-24 Thread Carlos Nepomuceno
In-depth articles about Python! Like security analisys of modules, packages, 
frameworks, everything Python related.

Performance benchmarks. How a Python technology/solution compares to other 
competitor technologies.

Python competitions/contests/challenges!



> Date: Fri, 24 May 2013 20:38:28 -0700
> Subject: Re: Python Magazine
> From: dreamingforw...@gmail.com
> To: rama29...@gmail.com
> CC: python-list@python.org
>
> I always liked the daily Python-URL from Dr. Dobbs.
>
> Summaries of salient discussions on python-dev, ideas, list.
>
> interviews with devs on philosophies.
>
> quote of the week
>
> --m
>
> On 5/24/13, DRJ Reddy  wrote:
>> Planning to start a python online chronicle.What you want to see in it. :)
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
> MarkJ
> Tacoma, Washington
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 1:35 PM, Roy Smith  wrote:
> "Python 3 vs. IPv6: who will win the race for early adoption?"

I think Py3 is winning that one so far. But really, both need to get
moving. Neither of my ISPs does IPv6 :(

Seconding the recommendation for QOTW, that's good fun.

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


Re: suppress newlines in my script

2013-05-24 Thread Jason Friedman
> Here are two lines from the CSV file:
> ,,172.20.{0}.0/27,172.20.{0}.32/27,172.20.{0}.64/27,29,172.20.{0}.96/27172.21.{0}.0/27,172.21.{0}.32/27,172.21.{0}.64/27,29,172.21.{0}.96/27
> GW:,,172.20.{0}.1,172.20.{0}.33,172.20.{0}.65,,172.20.{0}.97,,GW:,,172.21.{0}.1,172.21.{0}.33,172.21.{0}.65,,172.21.{0}.97
>
> This is the output:
> ,,
>
> ,,
> GW:,,172.20.126.129,172.20.126.161,172.20.126.193,,172.20.126.225,,GW:,,172.21.126.129,172.21.126.161,172.21.126.193,,172.21.126.225
>
> ''

When you say "this is the output" do you mean that is what you are
getting or that is what you want?  If that is what you are getting
please reply with what you want for output.
-- 
http://mail.python.org/mailman/listinfo/python-list


Source code as text/plain

2013-05-24 Thread Carlos Nepomuceno
I'd like to have the option to download the source code as text/plain from the 
docs.python.org pages.

For example: when I'm a docs page, such as:

http://docs.python.org/2/library/string.html

and I click the source code link I'm taken to a Mercurial page:

http://hg.python.org/cpython/file/2.7/Lib/string.py

but over there there's no way to get a clean text/plain version of the code 
because the line numbers are included.

A link to the text/plain version on that page would be nice!
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Source code as text/plain

2013-05-24 Thread Chris Rebert
On May 24, 2013 9:02 PM, "Carlos Nepomuceno" 
wrote:
>
> I'd like to have the option to download the source code as text/plain
from the docs.python.org pages.
>
> For example: when I'm a docs page, such as:
>
> http://docs.python.org/2/library/string.html
>
> and I click the source code link I'm taken to a Mercurial page:
>
> http://hg.python.org/cpython/file/2.7/Lib/string.py
>
> but over there there's no way to get a clean text/plain version of the
code because the line numbers are included.
>
> A link to the text/plain version on that page would be nice!

It's already there. Click the "raw" link in the sidebar. In this case, at
this moment, it sends you to
http://hg.python.org/cpython/raw-file/f4981d8eb401/Lib/string.py
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Source code as text/plain

2013-05-24 Thread Carlos Nepomuceno
Oh great! Thank you!


> Date: Fri, 24 May 2013 21:06:05 -0700 
> Subject: Re: Source code as text/plain 
> From: c...@rebertia.com 
> To: carlosnepomuc...@outlook.com 
> CC: python-list@python.org 
>  
>  
> On May 24, 2013 9:02 PM, "Carlos Nepomuceno"  
> mailto:carlosnepomuc...@outlook.com>>  
> wrote: 
> > 
> > I'd like to have the option to download the source code as text/plain  
> from the docs.python.org pages. 
> > 
> > For example: when I'm a docs page, such as: 
> > 
> > http://docs.python.org/2/library/string.html 
> > 
> > and I click the source code link I'm taken to a Mercurial page: 
> > 
> > http://hg.python.org/cpython/file/2.7/Lib/string.py 
> > 
> > but over there there's no way to get a clean text/plain version of  
> the code because the line numbers are included. 
> > 
> > A link to the text/plain version on that page would be nice! 
>  
> It's already there. Click the "raw" link in the sidebar. In this case,  
> at this moment, it sends you to 
> http://hg.python.org/cpython/raw-file/f4981d8eb401/Lib/string.py  
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread DRJ Reddy
On Saturday, May 25, 2013 9:13:56 AM UTC+5:30, Carlos Nepomuceno wrote:
> In-depth articles about Python! Like security analisys of modules, packages, 
> frameworks, everything Python related.
> 
> Performance benchmarks. How a Python technology/solution compares to other 
> competitor technologies.
> 
> Python competitions/contests/challenges!

Thankyou for your suggestions. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Magazine

2013-05-24 Thread DRJ Reddy
This is what i love with python community faster responses. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Magazine

2013-05-24 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 21:10:02 -0700
> Subject: Re: Python Magazine
> From: rama29...@gmail.com
> To: python-list@python.org
>
> On Saturday, May 25, 2013 9:13:56 AM UTC+5:30, Carlos Nepomuceno wrote:
>> In-depth articles about Python! Like security analisys of modules, packages, 
>> frameworks, everything Python related.
>>
>> Performance benchmarks. How a Python technology/solution compares to other 
>> competitor technologies.
>>
>> Python competitions/contests/challenges!
>
> Thankyou for your suggestions. :)
> --
> http://mail.python.org/mailman/listinfo/python-list

Also, comparison of Python flavors (CPython, PyPy, Cython, Stackles, etc.) -- 
How do they differ? What's the benefits and hindrances? 

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


Re: Python Magazine

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 2:22 PM, Carlos Nepomuceno
 wrote:
> Also, comparison of Python flavors (CPython, PyPy, Cython, Stackles, etc.) -- 
> How do they differ? What's the benefits and hindrances?

Good point. Could go even more general than that: Just highlight some
lesser-known Python and show it off.

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


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote:
> i need to write a code which can sort the list in order of 'n' without use 
> builtin functions 
> 
> can anyone help me how to do?

 Note:
the list only contains 0's,1's,2's
need to sort them in order of 'n'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 3:15 PM,   wrote:
> On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote:
>> i need to write a code which can sort the list in order of 'n' without use 
>> builtin functions
>>
>> can anyone help me how to do?
>
>  Note:
> the list only contains 0's,1's,2's
> need to sort them in order of 'n'

In that case, you're not really ordering them, you're counting them.
Look at the collections module; you can very easily figure out how
many of each there are, and then reconstruct the list afterward.

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


Re: Python Magazine

2013-05-24 Thread Michael Poeltl
* DRJ Reddy  [2013-05-25 05:26]:
> Planning to start a python online chronicle.What you want to see in it. :)
- idiomatic python (common mistakes; do it 'pythonically')
- interviews
- challenge of the week (how would you solve that?)
- python for kids
- scientific python news
- new python-books

- 


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

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.3,
  with python-3.2.3, on slackware-13.37   :-)
  fon: +43-1-4277-51409
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote:
> On Sat, May 25, 2013 at 3:15 PM,   wrote:
> 
> > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote:
> 
> >> i need to write a code which can sort the list in order of 'n' without use 
> >> builtin functions
> 
> >>
> 
> >> can anyone help me how to do?
> 
> >
> 
> >  Note:
> 
> > the list only contains 0's,1's,2's
> 
> > need to sort them in order of 'n'
> 
> 
> 
> In that case, you're not really ordering them, you're counting them.
> 
> Look at the collections module; you can very easily figure out how
> 
> many of each there are, and then reconstruct the list afterward.
> 
> 
> 
> ChrisA

but i need to do it with out using builtin functions
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 3:39 PM,   wrote:
> On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote:
>> On Sat, May 25, 2013 at 3:15 PM,   wrote:
>>
>> > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote:
>>
>> >> i need to write a code which can sort the list in order of 'n' without 
>> >> use builtin functions
>>
>> >>
>>
>> >> can anyone help me how to do?
>>
>> >
>>
>> >  Note:
>>
>> > the list only contains 0's,1's,2's
>>
>> > need to sort them in order of 'n'
>>
>>
>>
>> In that case, you're not really ordering them, you're counting them.
>>
>> Look at the collections module; you can very easily figure out how
>>
>> many of each there are, and then reconstruct the list afterward.
>>
>>
>>
>> ChrisA
>
> but i need to do it with out using builtin functions

Depending on your definitions, that's either trivially easy (the
'collections' module is not builtin functions) or completely
impossible. Have fun.

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


Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread rusi
On May 25, 10:15 am, lokeshkopp...@gmail.com wrote:
> On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote:
> > i need to write a code which can sort the list in order of 'n' without use 
> > builtin functions
>
> > can anyone help me how to do?
>
>  Note:
> the list only contains 0's,1's,2's
> need to sort them in order of 'n'

Its a classic problem
http://en.wikipedia.org/wiki/Dutch_national_flag_problem
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >