Accessing class variable at class creation time

2005-09-23 Thread Carlos
Hi!

class A:
  X = 2
  def F():
print A.X
  F()

The above fails because the name A is not
yet at global scope when the reference A.X
is reached. Is there any way to refer to A.X
without making explicit use of the name 'A'?
Admittedly the code looks pretty unusual,
but I'm defining configuration "minilanguages"
to configure different parts of an application,
each inside a configuration class (like A),
and I find this very convenient except for
the above problem.

Thank you in advance
Regards,
Carlos

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


Re: Accessing class variable at class creation time

2005-09-25 Thread Carlos
Thank you all!

After all, I found at least three more or less convenient alternatives:

1) Pass X as default parameter to F.
2) Set globals() from inside A, something like globals()['A_locals'] =
locals() or globals()['A_X'] = X. Then access A_locals or A_X from F.
3) Use sys._getframe(1) or sys._getframe().f_back to get the caller
frame.

But the following won't work:

> self.__class__.X

Because there is no self around here, I'm not trying to access X from a
class instance but instead from code running at class definition time.

>  class A:
> ... X = 2
> ... print X

Of course this will print X but the point was to do it from inside a
function.

Regards,
Carlos

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


Twice bound method

2005-08-27 Thread Carlos
Hi!

I want to instrumentate a class with a number of getter/setters.
Each pair of getter/setter must keep it's own state gsState but also
access to the state iState of instances of the instrumentated class.
For example:

class GetterSetter:
  def __init__(gsInstance, gsState):
   
  def get(gsInstance, iInstance, attr):
   
  def set(gsInstance, iInstance, attr, value):
   

class Instrumentated:
  def __init__(iInstance, iState):
   

getterSetter = GetterSetter(gsState1)
Instrumentated.getter1 = getterSetter.get
Instrumentated.setter1 = getterSetter.set

getterSetter = GetterSetter(gsState2)
Instrumentated.getter2 = getterSetter.get
Instrumentated.setter2 = getterSetter.set

instrumentated = Instrumentated(...)
instrumentated.getter1("x")
instrumentated.setter2("x", 5)

At first sight I thought that the above would work fine
as getterSetter.get would bind the getter to the GetterSetter
instance and then instrumented.getter1 would bind the already
bound getter to the Instrumentated instance, so at the end
an invocation like instrumentated.getter1("x") would be calling the
original getter passing a GetterInstance as first implicit
argument, an Instrumented instance as a second one and "x"
as the third -explicit- one. Well, the fact is that the getter
is only bound to the last instance, there are no nested bindings.

Another solution could come from the use of function nested
lexical scopes and closures, with a factory function which
takes the gsState as argument and produces a getter (or setter)
function taking an iState as first argument and the attribute as
second one. Then the class can be instrumentated with the generated
getter (or setter) which keeps the gsState captured within its closure.
For example:

def getterGen(gsState):
  def getter(iState, attr):

  return getter

Instrumentated.getter1 = getterGen(gsState1)
Instrumentated.getter2 = getterGen(gsState2)

Do you know of another -elegant- solution for the above problem?
Is there any way to get the nested method binding behaviour that
the first failed attempt required?

Thank you in advance.
Regards,
Carlos

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


Looking for Django/Python programmer in Jakarta

2014-01-08 Thread carlos
For working in a startup environment.
Immediate incorporation.
Please send your CV to tal...@zocko.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Regular expressions: recursive patterns and callouts

2006-01-21 Thread Carlos
Hi!
I think two extensions to re could be really powerful in aiding to
match non regular strings -for example those containing parens nested
up to an arbitrary depth- but without a significative performance loss,
although I'm not at all sure at this last point. One of these features
is re nesting; I don't mean nesting some strings and then compiling the
composed re, but to include -possibly recursive- references to other
re's. The second feature is the ability to add callout points in a re,
so external functions would be called when the matcher reaches those
points to validate the current matched prefix or even to do some
arbitrary further matching of its own, advancing the pattern position.
pcre implements similar features with its (?CN) callout and (?N)
recursive patterns mechanisms.
Are the above or equivalent features planned for future python
releases?
Do you know of some extension package which provide them or at least
pcre compatible res?
Thank you in advance,
Carlos

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


First post

2013-05-14 Thread Carlos Nepomuceno
Hi guys! This is my first post on this list.

I'd like have your opinion on how to safely implement WSGI on a production 
server.

My benchmarks show no performance differences between our PHP and Python 
environments. I'm using mod_wsgi v3.4 with Apache 2.4.

Is that ok or can it get faster?

Thanks in advance.

Regards,

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


RE: IndexError: pop index out of range

2013-05-14 Thread Carlos Nepomuceno
Your "for idx, val in enumerate(words):" is running on words not list_temp.
As you remove from list_temp and keeps parsing words you get the IndexError.

> From: form...@gmail.com 
> Date: Wed, 15 May 2013 00:22:05 -0400 
> Subject: IndexError: pop index out of range 
> To: python-list@python.org 
>  
> hello, 
>   going fru some basic examples and can't figureout why the following  
> errors out. Help is very much appreciated: 
>  
> def front_x(words): 
># +++your code here+++ 
>  print "words passed : ", words 
>  list_xx = [] 
>  list_temp = words[:] 
>  print "list_temp -", list_temp 
>  print "words -", words 
>  for idx, val in enumerate(words): 
>  print val, idx 
>  # str_idx = val.find('x',0,2) 
>  if val[0] == 'x': 
>  vl = list_temp.pop(idx) 
>  list_xx.append(vl) 
>  
>  print "appending list_xx", list_xx 
>  
>  list_xx.sort 
>  list_temp.sort 
>  print "words sorted : " + str(words) 
>  print "list_temp sorted : ", list_temp 
>  list_xx.append(words) 
>  print "list_xx" + str(list_xx) 
>  return True 
>  
> front_x 
> words passed : ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> list_temp - ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> words - ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> bbb 0 
> ccc 1 
> axx 2 
> xzz 3 
> appending list_xx ['xzz'] 
> xaa 4 
> Traceback (most recent call last): 
>File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 119, in  
>  main() 
>File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 100, in main 
>  test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), 
>File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 55, in front_x 
>  vl = list_temp.pop(idx) 
> IndexError: pop index out of range 
>  
>  
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PDF generator decision

2013-05-14 Thread Carlos Nepomuceno
Christian, have you tried pod[1]? You can use create templates in OpenDocument 
format and then create the PDFs just passing the arguments, like:

args = {'name':'John', 'email':'j...@example.com'}
renderer = Renderer('template.odt', args, 'result.odt')renderer.run()



[1] http://appyframework.org/pod.html


> To: python-list@python.org
> From: die...@handshake.de
> Subject: Re: PDF generator decision
> Date: Wed, 15 May 2013 08:22:25 +0200
>
> Christian Jurk  writes:
>
>> ...
>> So far I'd like to ask which is the (probably) best way to create PDFs in 
>> Python (3)? It is important for me that I am able to specify not only 
>> background graphics, paragaphs, tables and so on but also to specify page 
>> headers/footers. The reason is that I have a bunch of documents to be 
>> generated (including Invoice templates, Quotes - stuff like that).
>
> High quality layouts, especially those containing (potentially complex
> tables), are very difficult to generate automatically.
>
> I do not suppose that you will find a generic solution - one applicable
> to a wide range of document classes and garanteeing high quality
> layout for almost all of its document instances.
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [RELEASED] Python 2.7.5

2013-05-15 Thread Carlos Nepomuceno
test_asynchat still hangs! What it does? Should I care?


> Date: Wed, 15 May 2013 23:19:06 -0500
> Subject: [RELEASED] Python 2.7.5
> From: benja...@python.org
> To: python-...@python.org; python-list@python.org; 
> python-announce-l...@python.org
>
> It is my greatest pleasure to announce the release of Python 2.7.5.
>
> 2.7.5 is the latest maintenance release in the Python 2.7 series. You may be
> surprised to hear from me so soon, as Python 2.7.4 was released slightly more
> than a month ago. As it turns out, 2.7.4 had several regressions and
> incompatibilities with 2.7.3. Among them were regressions in the zipfile, 
> gzip,
> and logging modules. 2.7.5 fixes these. In addition, a data file for testing 
> in
> the 2.7.4 tarballs and binaries aroused the suspicion of some virus
> checkers. The 2.7.5 release removes this file to resolve that issue.
>
> For details, see the Misc/NEWS file in the distribution or view it at
>
> http://hg.python.org/cpython/file/ab05e7dd2788/Misc/NEWS
>
> Downloads are at
>
> http://python.org/download/releases/2.7.5/
>
> As always, please report bugs to
>
> http://bugs.python.org/
>
> (Thank you to those who reported these bugs in 2.7.4.)
>
> This is a production release.
>
> Happy May,
> Benjamin Peterson
> 2.7 Release Manager
> (on behalf of all of Python 2.7's contributors)
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
I've got the following results on my desktop PC (Win7/Python2.7.5):

C:\src\Python>python -m timeit -cvn3 -r3 "execfile('fastwrite2.py')"
raw times: 123 126 125
3 loops, best of 3: 41 sec per loop

C:\src\Python>python -m timeit -cvn3 -r3 "execfile('fastwrite5.py')"
raw times: 34 34.3 34
3 loops, best of 3: 11.3 sec per loop

C:\src\Python>python -m timeit -cvn3 -r3 "execfile('fastwrite6.py')"
raw times: 0.4 0.447 0.391
3 loops, best of 3: 130 msec per loop


If you can just copy a preexisting file it will surely increase the speed to 
the levels you need, but doing the cStringIO operations can reduce the time in 
72%.

Strangely I just realised that the time it takes to complete such scripts is 
the same no matter what hard drive I choose to run them. The results are the 
same for an SSD (main drive) and a HDD.

I think it's very strange to take 11.3s to write 50MB (4.4MB/s) sequentially on 
a SSD which is capable of 140MB/s.

Is that a Python problem? Why does it take the same time on the HDD?


### fastwrite2.py ###  <<< this is your code
size = 50*1024*1024
value = 0
filename = 'fastwrite2.dat'
with open(filename, "w") as f:
    while f.tell()< size:
    f.write("{0}\n".format(value))
    value += 1
    f.close()


### fastwrite5.py ###
import cStringIO
size = 50*1024*1024
value = 0
filename = 'fastwrite5.dat'
x = 0
b = cStringIO.StringIO()
while x < size:
    line = '{0}\n'.format(value)
    b.write(line)
    value += 1
    x += len(line)+1
f = open(filename, 'w')
f.write(b.getvalue())
f.close()
b.close()


### fastwrite6.py ###
import shutil
src = 'fastwrite.dat'
dst = 'fastwrite6.dat'
shutil.copyfile(src, dst)




> Date: Fri, 17 May 2013 07:58:43 -0400
> From: da...@davea.name
> To: python-list@python.org
> Subject: Re: How to write fast into a file in python?
>
> On 05/17/2013 12:35 AM, lokeshkopp...@gmail.com wrote:
>> On Friday, May 17, 2013 8:50:26 AM UTC+5:30, lokesh...@gmail.com wrote:
>>> I need to write numbers into a file upto 50mb and it should be fast
>>>
>>> can any one help me how to do that?
>>>
>>> i had written the following code..
>>>
>>> 
>>> value = 0
>>>
>>> with open(filename, "w") as f:
>>>
>>> while f.tell()< size:
>>>
>>> f.write("{0}\n".format(value))
>>> 
> If you must use googlegroups, at least read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>>>
>>>
>>> it takes about 20sec i need 5 to 10 times less than that.
>> size = 50mb
>>
>
> Most of the time is spent figuring out whether the file has reached its
> limit size. If you want Python to go fast, just specify the data. On
> my Linux system, it takes 11 seconds to write the first 633 values,
> which is just under 50mb. If I write the obvious loop, writing that
> many values takes .25 seconds.
>
> --
> DaveA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
Thank you Steve! You are totally right!

It takes about 0.2s for the f.write() to return. Certainly because it writes to 
the system file cache (~250MB/s).

Using a little bit different approach I've got:

C:\src\Python>python -m timeit -cvn3 -r3 -s"from fastwrite5r import run" "run()"
raw times: 24 25.1 24.4
3 loops, best of 3: 8 sec per loop
    

This time it took 8s to complete from previous 11.3s.

Does those 3.3s are the time to "open, read, parse, compile" steps you told me?

If so, the execute step is really taking 8s, right?

Why does it take so long to build the string to be written? Can it get faster?

Thanks in advance!



### fastwrite5r.py ###
def run():
    import cStringIO
    size = 50*1024*1024
    value = 0
    filename = 'fastwrite5.dat'
    x = 0
    b = cStringIO.StringIO()
    while x < size:
    line = '{0}\n'.format(value)
    b.write(line)
    value += 1
    x += len(line)+1
    f = open(filename, 'w')
    f.write(b.getvalue())
    f.close()
    b.close()

if __name__ == '__main__':
    run()






> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: How to write fast into a file in python?
> Date: Fri, 17 May 2013 16:42:55 +
> To: python-list@python.org
>
> On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote:
>
>> I've got the following results on my desktop PC (Win7/Python2.7.5):
>>
>> C:\src\Python>python -m timeit -cvn3 -r3 "execfile('fastwrite2.py')" raw
>> times: 123 126 125
>> 3 loops, best of 3: 41 sec per loop
>
> Your times here are increased significantly by using execfile. Using
> execfile means that instead of compiling the code once, then executing
> many times, it gets compiled over and over and over and over again. In my
> experience, using exec, execfile or eval makes your code ten or twenty
> times slower:
>
> [steve@ando ~]$ python -m timeit 'x = 100; y = x/3'
> 100 loops, best of 3: 0.175 usec per loop
> [steve@ando ~]$ python -m timeit 'exec("x = 100; y = x/3")'
> 1 loops, best of 3: 37.8 usec per loop
>
>
>> Strangely I just realised that the time it takes to complete such
>> scripts is the same no matter what hard drive I choose to run them. The
>> results are the same for an SSD (main drive) and a HDD.
>
> There's nothing strange here. The time you measure is dominated by three
> things, in reducing order of importance:
>
> * the poor choice of execfile dominates the time taken;
>
> * followed by choice of algorithm;
>
> * followed by the time it actually takes to write to the disk, which is
> probably insignificant compared to the other two, regardless of whether
> you are using a HDD or SSD.
>
> Until you optimize the code, optimizing the media is a waste of time.
>
>
>> I think it's very strange to take 11.3s to write 50MB (4.4MB/s)
>> sequentially on a SSD which is capable of 140MB/s.
>
> It doesn't. It takes 11.3 seconds to open a file, read it into memory,
> parse it, compile it into byte-code, and only then execute it. My
> prediction is that the call to f.write() and f.close() probably take a
> fraction of a second, and nearly all of the rest of the time is taken by
> other calculations.
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
You've hit the bullseye! ;)

Thanks a lot!!!

> Oh, I forgot to mention: you have a bug in this function. You're already
> including the newline in the len(line), so there is no need to add one.
> The result is that you only generate 44MB instead of 50MB.

That's because I'm running on Windows.
What's the fastest way to check if '\n' translates to 2 bytes on file?

> Here are the results of profiling the above on my computer. Including the
> overhead of the profiler, it takes just over 50 seconds to run your file
> on my computer.
>
> [steve@ando ~]$ python -m cProfile fastwrite5.py
> 17846645 function calls in 53.575 seconds
>

Didn't know the cProfile module.Thanks a lot!

> Ordered by: standard name
>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 1 30.561 30.561 53.575 53.575 fastwrite5.py:1()
> 1 0.000 0.000 0.000 0.000 {cStringIO.StringIO}
> 5948879 5.582 0.000 5.582 0.000 {len}
> 1 0.004 0.004 0.004 0.004 {method 'close' of 'cStringIO.StringO' objects}
> 1 0.000 0.000 0.000 0.000 {method 'close' of 'file' objects}
> 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
> 5948879 9.979 0.000 9.979 0.000 {method 'format' of 'str' objects}
> 1 0.103 0.103 0.103 0.103 {method 'getvalue' of 'cStringIO.StringO' objects}
> 5948879 7.135 0.000 7.135 0.000 {method 'write' of 'cStringIO.StringO' 
> objects}
> 1 0.211 0.211 0.211 0.211 {method 'write' of 'file' objects}
> 1 0.000 0.000 0.000 0.000 {open}
>
>
> As you can see, the time is dominated by repeatedly calling len(),
> str.format() and StringIO.write() methods. Actually writing the data to
> the file is quite a small percentage of the cumulative time.
>
> So, here's another version, this time using a pre-calculated limit. I
> cheated and just copied the result from the fastwrite5 output :-)
>
> # fasterwrite.py
> filename = 'fasterwrite.dat'
> with open(filename, 'w') as f:
> for i in xrange(5948879): # Actually only 44MB, not 50MB.
> f.write('%d\n' % i)
>

I had the same idea but kept the original method because I didn't want to waste 
time creating a function for calculating the actual number of iterations needed 
to deliver 50MB of data. ;)

> And the profile results are about twice as fast as fastwrite5 above, with
> only 8 seconds in total writing to my HDD.
>
> [steve@ando ~]$ python -m cProfile fasterwrite.py
> 5948882 function calls in 28.840 seconds
>
> Ordered by: standard name
>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 1 20.592 20.592 28.840 28.840 fasterwrite.py:1()
> 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
> 5948879 8.229 0.000 8.229 0.000 {method 'write' of 'file' objects}
> 1 0.019 0.019 0.019 0.019 {open}
>

I thought there would be a call to format method by "'%d\n' % i". It seems the 
% operator is a lot faster than format.
I just stopped using it because I read it was going to be deprecated. :(
Why replace such a great and fast operator by a slow method? I mean, why format 
is been preferred over %?

> Without the overhead of the profiler, it is a little faster:
>
> [steve@ando ~]$ time python fasterwrite.py
>
> real 0m16.187s
> user 0m13.553s
> sys 0m0.508s
>
>
> Although it is still slower than the heavily optimized dd command,
> but not unreasonably slow for a high-level language:
>
> [steve@ando ~]$ time dd if=fasterwrite.dat of=copy.dat
> 90781+1 records in
> 90781+1 records out
> 46479922 bytes (46 MB) copied, 0.737009 seconds, 63.1 MB/s
>
> real 0m0.786s
> user 0m0.071s
> sys 0m0.595s
>
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-17 Thread Carlos Nepomuceno
Think the following update will make the code more portable:

x += len(line)+len(os.linesep)-1

Not sure if it's the fastest way to achieve that. :/

> On Fri, 17 May 2013 18:20:33 +0300, Carlos Nepomuceno wrote:
>
>> ### fastwrite5.py ###
>> import cStringIO
>> size = 50*1024*1024
>> value = 0
>> filename = 'fastwrite5.dat'
>> x = 0
>> b = cStringIO.StringIO()
>> while x < size:
>> line = '{0}\n'.format(value)
>> b.write(line)
>> value += 1
>> x += len(line)+1
>
> Oh, I forgot to mention: you have a bug in this function. You're already
> including the newline in the len(line), so there is no need to add one.
> The result is that you only generate 44MB instead of 50MB.
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
Python really writes '\n\r' on Windows. Just check the files.

Internal representations only keep '\n' for simplicity, but if you wanna keep 
track of the file length you have to take that into account. ;)


> Date: Sat, 18 May 2013 08:49:55 +0100 
> Subject: RE: How to write fast into a file in python? 
> From: fabiosantos...@gmail.com 
> To: carlosnepomuc...@outlook.com 
> CC: python-list@python.org 
>  
>  
> On 17 May 2013 19:38, "Carlos Nepomuceno"  
> mailto:carlosnepomuc...@outlook.com>>  
> wrote: 
> > 
> > Think the following update will make the code more portable: 
> > 
> > x += len(line)+len(os.linesep)-1 
> > 
> > Not sure if it's the fastest way to achieve that. :/ 
> > 
>  
> Putting len(os.linesep)'s value into a local variable will make  
> accessing it quite a bit faster. But why would you want to do that? 
>  
> You mentioned "\n" translating to two lines, but this won't happen.  
> Windows will not mess with what you write to your file. It's just that  
> traditionally windows and windows programs use \r\n instead of just \n.  
> I think it was for compatibility with os/2 or macintosh (I don't  
> remember which), which used \r for newlines. 
>  
> You don't have to follow this convention. If you open a \n-separated  
> file with *any* text editor other than notepad, your newlines will be  
> okay.   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Please help with Threading

2013-05-18 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: wlfr...@ix.netcom.com
> Subject: Re: Please help with Threading
> Date: Sat, 18 May 2013 15:28:56 -0400
>
> On Sat, 18 May 2013 01:58:13 -0700 (PDT), Jurgens de Bruin
>  declaimed the following in
> gmane.comp.python.general:
>
>> This is my first script where I want to use the python threading module. I 
>> have a large dataset which is a list of dict this can be as much as 200 
>> dictionaries in the list. The final goal is a histogram for each dict 16 
>> histograms on a page ( 4x4 ) - this already works.
>> What I currently do is a create a nested list [ [ {} ], [ {} ] ] each inner 
>> list contains 16 dictionaries, thus each inner list is a single page of 16 
>> histograms. Iterating over the outer-list and creating the graphs takes to 
>> long. So I would like multiple inner-list to be processes simultaneously and 
>> creating the graphs in "parallel".
>> I am trying to use the python threading for this. I create 4 threads loop 
>> over the outer-list and send a inner-list to the thread. This seems to work 
>> if my nested lists only contains 2 elements - thus less elements than 
>> threads. Currently the scripts runs and then seems to get hung up. I monitor 
>> the resource on my mac and python starts off good using 80% and when the 
>> 4-thread is created the CPU usages drops to 0%.
>>
>
> The odds are good that this is just going to run slower...

Just been told that GIL doesn't make things slower, but as I didn't know that 
such a thing even existed I went out looking for more info and found that 
document: http://www.dabeaz.com/python/UnderstandingGIL.pdf

Is it current? I didn't know Python threads aren't preemptive. Seems to be 
something really old considering the state of the art on parallel execution on 
multi-cores.

What's the catch on making Python threads preemptive? Are there any ongoing 
projects to make that?

> One: The common Python implementation uses a global interpreter lock
> to prevent interpreted code from interfering with itself in multiple
> threads. So "number cruncher" applications don't gain any speed from
> being partitioned into thread -- even on a multicore processor, only one
> thread can have the GIL at a time. On top of that, you have the overhead
> of the interpreter switching between threads (GIL release on one thread,
> GIL acquire for the next thread).
>
> Python threads work fine if the threads either rely on intelligent
> DLLs for number crunching (instead of doing nested Python loops to
> process a numeric array you pass it to something like NumPy which
> releases the GIL while crunching a copy of the array) or they do lots of
> I/O and have to wait for I/O devices (while one thread is waiting for
> the write/read operation to complete, another thread can do some number
> crunching).
>
> If you really need to do this type of number crunching in Python
> level code, you'll want to look into the multiprocessing library
> instead. That will create actual OS processes (each with a copy of the
> interpreter, and not sharing memory) and each of those can run on a core
> without conflicting on the GIL.

Which library do you suggest?

> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno

> Date: Sat, 18 May 2013 22:41:32 -0400
> From: da...@davea.name
> To: python-list@python.org
> Subject: Re: How to write fast into a file in python?
>
> On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote:
>> Python really writes '\n\r' on Windows. Just check the files.
>
> That's backwards. '\r\n' on Windows, IF you omit the b in the mode when
> creating the file.

Indeed! My mistake just made me find out that Acorn used that inversion on 
Acorn MOS.

According to this[1] (at page 449) the OSNEWL routine outputs '\n\r'.

What the hell those guys were thinking??? :p

"OSNEWL
This call issues an LF CR (line feed, carriage return) to the currently selected
output stream. The routine is entered at &FFE7."

[1] http://regregex.bbcmicro.net/BPlusUserGuide-1.07.pdf
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
Thanks Dan! I've never used CPython or PyPy. Will try them later.

I think the main difference between your create_file_numbers_file_like()
 and the fastwrite5.py I sent earlier is that I've used cStringIO 
instead of StringIO. It took 12s less using cStringIO.

My numbers are much greater, but I've used Python 2.7.5 instead:

C:\src\Python>python create_file_numbers.py
time taken to write a file of size 52428800  is  39.1199457743 seconds

time taken to write a file of size 52428800  is  14.8704800436 seconds

time taken to write a file of size 52428800  is  23.0011990985 seconds


I've downloaded bufsock.py and python2x3.py. The later one was hard to remove 
the source code from the web page.

Can I use them on my projects? I'm not used to the UCI license[1]. What's the 
difference to the GPL?




[1] http://stromberg.dnsalias.org/~dstromberg/UCI-license.html


> Date: Sat, 18 May 2013 12:38:30 -0700 
> Subject: Re: How to write fast into a file in python? 
> From: drsali...@gmail.com 
> To: lokeshkopp...@gmail.com 
> CC: python-list@python.org 
>  
>  
> With CPython 2.7.3: 
> ./t 
> time taken to write a file of size 52428800  is  15.86 seconds 
>  
> time taken to write a file of size 52428800  is  7.91 seconds 
>  
> time taken to write a file of size 52428800  is  9.64 seconds 
>  
>  
> With pypy-1.9: 
> ./t 
> time taken to write a file of size 52428800  is  3.708232 seconds 
>  
> time taken to write a file of size 52428800  is  4.868304 seconds 
>  
> time taken to write a file of size 52428800  is  1.93612 seconds 
>  

> Here's the code: 
> #!/usr/local/pypy-1.9/bin/pypy 
> #!/usr/bin/python 
>  
> import sys 
> import time 
> import StringIO 
>  
> sys.path.insert(0, '/usr/local/lib') 
> import bufsock 
>  
> def create_file_numbers_old(filename, size): 
>  start = time.clock() 
>  
>  value = 0 
>  with open(filename, "w") as f: 
>  while f.tell() < size: 
>  f.write("{0}\n".format(value)) 
>  value += 1 
>  
>  end = time.clock() 
>  
>  print "time taken to write a file of size", size, " is ", (end  
> -start), "seconds \n" 
>  
> def create_file_numbers_bufsock(filename, intended_size): 
>  start = time.clock() 
>  
>  value = 0 
>  with open(filename, "w") as f: 
>  bs = bufsock.bufsock(f) 
>  actual_size = 0 
>  while actual_size < intended_size: 
>  string = "{0}\n".format(value) 
>  actual_size += len(string) + 1 
>  bs.write(string) 
>  value += 1 
>  bs.flush() 
>  
>  end = time.clock() 
>  
>  print "time taken to write a file of size", intended_size, " is ",  
> (end -start), "seconds \n" 
>  
>  
> def create_file_numbers_file_like(filename, intended_size): 
>  start = time.clock() 
>  
>  value = 0 
>  with open(filename, "w") as f: 
>  file_like = StringIO.StringIO() 
>  actual_size = 0 
>  while actual_size < intended_size: 
>  string = "{0}\n".format(value) 
>  actual_size += len(string) + 1 
>  file_like.write(string) 
>  value += 1 
>  file_like.seek(0) 
>  f.write(file_like.read()) 
>  
>  end = time.clock() 
>  
>  print "time taken to write a file of size", intended_size, " is ",  
> (end -start), "seconds \n" 
>  
> create_file_numbers_old('output.txt', 50 * 2**20) 
> create_file_numbers_bufsock('output2.txt', 50 * 2**20) 
> create_file_numbers_file_like('output3.txt', 50 * 2**20) 
>  
>  
>  
>  
> On Thu, May 16, 2013 at 9:35 PM,  
> mailto:lokeshkopp...@gmail.com>> wrote: 
> On Friday, May 17, 2013 8:50:26 AM UTC+5:30,  
> lokesh...@gmail.com wrote: 
> > I need to write numbers into a file upto 50mb and it should be fast 
> > 
> > can any one help me how to do that? 
> > 
> > i had written the following code.. 
> > 
> >  
> ---
>  
> > 
> > def create_file_numbers_old(filename, size): 
> > 
> > start = time.clock() 
> > 
> > 
> > 
> > value = 0 
> > 
> > with open(filename, "w") as f: 
> > 
> > while f.tell()< size: 
> > 
> > f.write("{0}\n".format(value)) 
> > 
> > value += 1 
> > 
> > 
> > 
> > end = time.clock() 
> > 
> > 
> > 
> > print "time taken to write a file of size", size, " is ", (end  
> -start), "seconds \n" 
> > 
> >  
> --
>  
> > 
> > it takes about 20sec i need 5 to 10 times less than that. 
> size = 50mb 
> -- 
> 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: How to write fast into a file in python?

2013-05-18 Thread Carlos Nepomuceno
BTW, I've downloaded from the following places:

http://stromberg.dnsalias.org/svn/bufsock/trunk/bufsock.py
http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/python2x3-pysrc.html

Are those the latest versions?


> From: carlosnepomuc...@outlook.com
> To: python-list@python.org
> Subject: RE: How to write fast into a file in python?
> Date: Sun, 19 May 2013 08:31:08 +0300
> CC: lokeshkopp...@gmail.com
>
> Thanks Dan! I've never used CPython or PyPy. Will try them later.
>
> I think the main difference between your create_file_numbers_file_like()
> and the fastwrite5.py I sent earlier is that I've used cStringIO
> instead of StringIO. It took 12s less using cStringIO.
>
> My numbers are much greater, but I've used Python 2.7.5 instead:
>
> C:\src\Python>python create_file_numbers.py
> time taken to write a file of size 52428800  is  39.1199457743 seconds
>
> time taken to write a file of size 52428800  is  14.8704800436 seconds
>
> time taken to write a file of size 52428800  is  23.0011990985 seconds
>
>
> I've downloaded bufsock.py and python2x3.py. The later one was hard to remove 
> the source code from the web page.
>
> Can I use them on my projects? I'm not used to the UCI license[1]. What's the 
> difference to the GPL?
>
>
>
>
> [1] http://stromberg.dnsalias.org/~dstromberg/UCI-license.html
>
> 
>> Date: Sat, 18 May 2013 12:38:30 -0700
>> Subject: Re: How to write fast into a file in python?
>> From: drsali...@gmail.com
>> To: lokeshkopp...@gmail.com
>> CC: python-list@python.org
>>
>>
>> With CPython 2.7.3:
>> ./t
>> time taken to write a file of size 52428800 is 15.86 seconds
>>
>> time taken to write a file of size 52428800 is 7.91 seconds
>>
>> time taken to write a file of size 52428800 is 9.64 seconds
>>
>>
>> With pypy-1.9:
>> ./t
>> time taken to write a file of size 52428800 is 3.708232 seconds
>>
>> time taken to write a file of size 52428800 is 4.868304 seconds
>>
>> time taken to write a file of size 52428800 is 1.93612 seconds
>>
>
>> Here's the code:
>> #!/usr/local/pypy-1.9/bin/pypy
>> #!/usr/bin/python
>>
>> import sys
>> import time
>> import StringIO
>>
>> sys.path.insert(0, '/usr/local/lib')
>> import bufsock
>>
>> def create_file_numbers_old(filename, size):
>> start = time.clock()
>>
>> value = 0
>> with open(filename, "w") as f:
>> while f.tell() < size:
>> f.write("{0}\n".format(value))
>> value += 1
>>
>> end = time.clock()
>>
>> print "time taken to write a file of size", size, " is ", (end
>> -start), "seconds \n"
>>
>> def create_file_numbers_bufsock(filename, intended_size):
>> start = time.clock()
>>
>> value = 0
>> with open(filename, "w") as f:
>> bs = bufsock.bufsock(f)
>> actual_size = 0
>> while actual_size < intended_size:
>> string = "{0}\n".format(value)
>> actual_size += len(string) + 1
>> bs.write(string)
>> value += 1
>> bs.flush()
>>
>> end = time.clock()
>>
>> print "time taken to write a file of size", intended_size, " is ",
>> (end -start), "seconds \n"
>>
>>
>> def create_file_numbers_file_like(filename, intended_size):
>> start = time.clock()
>>
>> value = 0
>> with open(filename, "w") as f:
>> file_like = StringIO.StringIO()
>> actual_size = 0
>> while actual_size < intended_size:
>> string = "{0}\n".format(value)
>> actual_size += len(string) + 1
>> file_like.write(string)
>> value += 1
>> file_like.seek(0)
>> f.write(file_like.read())
>>
>> end = time.clock()
>>
>> print "time taken to write a file of size", intended_size, " is ",
>> (end -start), "seconds \n"
>>
>> create_file_numbers_old('output.txt', 50 * 2**20)
>> create_file_numbers_bufsock('output2.txt', 50 * 2**20)
>> create_file_numbers_file_like('output3.txt', 50 * 2**20)
>>
>>
>>
>>
>> On Thu, May 16, 2013 at 9:35 PM,
>> mailto:lokeshkopp...@gmail.com>> wrote:
>> On Friday, May 17, 2013 8:50:26 AM UTC+5:30,
>> lokesh...@gmail.com wrote:
>>> I need to write numbers into a file upto 50mb and it should be fast
>>>
>>> can any one help me how to do that?
>>>
>>> i had written the following code..
>>>
>>>
>> ---
>>>
>>> def create_file_numbers_old(filename, size):
>>>
>>> start = time.clock()
>>>
>>>
>>>
>>> value = 0
>>>
>>> with open(filename, "w") as f:
>>>
>>> while f.tell()< size:
>>>
>>> f.write("{0}\n".format(value))
>>>
>>> value += 1
>>>
>>>
>>>
>>> end = time.clock()
>>>
>>>
>>>
>>> print "time taken to write a file of size", size, " is ", (end
>> -start), "seconds \n"
>>>
>>>
>> --
>>>
>>> it takes about 20sec i need 5 to 10 times less than that.
>> size = 50mb
>> --
>> 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: How to write fast into a file in python?

2013-05-19 Thread Carlos Nepomuceno
ooops! I meant to say Cython. nevermind...


> Date: Sun, 19 May 2013 19:21:54 +1000
> Subject: Re: How to write fast into a file in python?
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sun, May 19, 2013 at 3:31 PM, Carlos Nepomuceno
>  wrote:
>> Thanks Dan! I've never used CPython or PyPy. Will try them later.
>
> CPython is the "classic" interpreter, written in C. It's the one
> you'll get from the obvious download links on python.org.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Question about ast.literal_eval

2013-05-20 Thread Carlos Nepomuceno
It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of 
expression because it's just for literals[2].

Why don't you use eval()?


[1] http://docs.python.org/2/library/ast.html#ast-helpers

[2] http://docs.python.org/2/reference/lexical_analysis.html#literals


> To: python-list@python.org
> From: fr...@chagford.com
> Subject: Question about ast.literal_eval
> Date: Mon, 20 May 2013 09:05:48 +0200
>
> Hi all
>
> I am trying to emulate a SQL check constraint in Python. Quoting from
> the PostgreSQL docs, "A check constraint is the most generic constraint
> type. It allows you to specify that the value in a certain column must
> satisfy a Boolean (truth-value) expression."
>
> The problem is that I want to store the constraint as a string, and I
> was hoping to use ast.literal_eval to evaluate it, but it does not work.
>
 x = 'abc'
 x in ('abc', xyz')
> True
 b = "x in ('abc', 'xyz')"
 eval(b)
> True
 from ast import literal_eval
 literal_eval(b)
> ValueError: malformed node or string: <_ast.Compare object at ...>
>
> Is there a safe way to do what I want? I am using python 3.3.
>
> Thanks
>
> Frank Millman
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno

> Date: Sun, 19 May 2013 13:10:36 +1000
> From: c...@zip.com.au
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
> Subject: Re: Please help with Threading
>
> On 19May2013 03:02, Carlos Nepomuceno  wrote:
> | Just been told that GIL doesn't make things slower, but as I
> | didn't know that such a thing even existed I went out looking for
> | more info and found that document:
> | http://www.dabeaz.com/python/UnderstandingGIL.pdf
> |
> | Is it current? I didn't know Python threads aren't preemptive.
> | Seems to be something really old considering the state of the art
> | on parallel execution on multi-cores.
> | What's the catch on making Python threads preemptive? Are there any ongoing 
> projects to make that?
>
> Depends what you mean by preemptive. If you have multiple CPU bound
> pure Python threads they will all get CPU time without any of them
> explicitly yeilding control. But thread switching happens between
> python instructions, mediated by the interpreter.

I meant operating system preemptive. I've just checked and Python does not 
start Windows threads.

> The standard answers for using multiple cores is to either run
> multiple processes (either explicitly spawning other executables,
> or spawning child python processes using the multiprocessing module),
> or to use (as suggested) libraries that can do the compute intensive
> bits themselves, releasing the while doing so so that the Python
> interpreter can run other bits of your python code.

I've just discovered the multiprocessing module[1] and will make some tests 
with it later. Are there any other modules for that purpose?

I've found the following articles about Python threads. Any suggestions?

http://www.ibm.com/developerworks/aix/library/au-threadingpython/
http://pymotw.com/2/threading/index.html
http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/


[1] http://docs.python.org/2/library/multiprocessing.html


> Plenty of OS system calls (and calls to other libraries from the
> interpreter) release the GIL during the call. Other python threads
> can run during that window.
>
> And there are other Python implementations other than CPython.
>
> Cheers,
> --
> Cameron Simpson 
>
> Processes are like potatoes. - NCR device driver manual   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno

> Date: Mon, 20 May 2013 17:45:14 +1000
> From: c...@zip.com.au
> To: fabiosantos...@gmail.com
> Subject: Re: Please help with Threading
> CC: python-list@python.org; wlfr...@ix.netcom.com
>
> On 20May2013 07:25, Fábio Santos  wrote:
> | On 18 May 2013 20:33, "Dennis Lee Bieber"  wrote:
> |> Python threads work fine if the threads either rely on intelligent
> |> DLLs for number crunching (instead of doing nested Python loops to
> |> process a numeric array you pass it to something like NumPy which
> |> releases the GIL while crunching a copy of the array) or they do lots of
> |> I/O and have to wait for I/O devices (while one thread is waiting for
> |> the write/read operation to complete, another thread can do some number
> |> crunching).
> |
> | Has nobody thought of a context manager to allow a part of your code to
> | free up the GIL? I think the GIL is not inherently bad, but if it poses a
> | problem at times, there should be a way to get it out of your... Way.
>
> The GIL makes individual python operations thread safe by never
> running two at once. This makes the implementation of the operations
> simpler, faster and safer. It is probably totally infeasible to
> write meaningful python code inside your suggested context
> manager that didn't rely on the GIL; if the GIL were not held the
> code would be unsafe.

I just got my hands dirty trying to synchronize Python prints from many threads.
Sometimes they mess up when printing the newlines. 

I tried several approaches using threading.Lock and Condition. None of them 
worked perfectly and all of them made the code sluggish. 

Is there a 100% sure method to make print thread safe? Can it be fast???


> It is easy for a C extension to release the GIL, and then to do
> meaningful work until it needs to return to python land. Most C
> extensions will do that around non-trivial sections, and anything
> that may stall in the OS.
>
> So your use case for the context manager doesn't fit well.
> --
> Cameron Simpson 
>
> Gentle suggestions being those which are written on rocks of less than 5lbs.
> - Tracy Nelson in comp.lang.c
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Question about ast.literal_eval

2013-05-20 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: fr...@chagford.com
> Subject: Re: Question about ast.literal_eval
> Date: Mon, 20 May 2013 09:50:02 +0200
>
> [Corrected top-posting]
>
>>> To: python-list@python.org
>>> From: fr...@chagford.com
>>> Subject: Question about ast.literal_eval
>>> Date: Mon, 20 May 2013 09:05:48 +0200
>>>
>>> Hi all
>>>
>>> I am trying to emulate a SQL check constraint in Python. Quoting from
>>> the PostgreSQL docs, "A check constraint is the most generic constraint
>>> type. It allows you to specify that the value in a certain column must
>>> satisfy a Boolean (truth-value) expression."
>>>
>>> The problem is that I want to store the constraint as a string, and I
>>> was hoping to use ast.literal_eval to evaluate it, but it does not work.
>>>
>
> On 20/05/2013 09:34, Carlos Nepomuceno wrote:
>
>> It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of 
>> expression
>> because it's just for literals[2].
>>
>> Why don't you use eval()?
>>
>
> Because users can create their own columns, with their own constraints.
> Therefore the string is user-modifiable, so it cannot be trusted.

I understand your motivation but I don't know what protection 
ast.literal_eval() is offering that eval() doesn't.

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


RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno

> Date: Mon, 20 May 2013 18:35:20 +1000
> From: c...@zip.com.au
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
> Subject: Re: Please help with Threading
>
> On 20May2013 10:53, Carlos Nepomuceno  wrote:
> | I just got my hands dirty trying to synchronize Python prints from many 
> threads.
> | Sometimes they mess up when printing the newlines.
> | I tried several approaches using threading.Lock and Condition.
> | None of them worked perfectly and all of them made the code sluggish.
>
> Show us some code, with specific complaints.
>
> Did you try this?
>
> _lock = Lock()
>
> def lprint(*a, **kw):
> global _lock
> with _lock:
> print(*a, **kw)
>
> and use lprint() everywhere?


It works! Think I was running the wrong script...

Anyway, the suggestion you've made is the third and latest attempt that I've 
tried to synchronize the print outputs from the threads.

I've also used:

### 1st approach ###
lock  = threading.Lock()
[...]
try:
    lock.acquire()
    [thread protected code]
finally:
    lock.release()


### 2nd approach ###
cond  = threading.Condition()
[...]
try:
    [thread protected code]
    with cond:
        print '[...]'


### 3rd approach ###
from __future__ import print_function

def safe_print(*args, **kwargs):
    global print_lock
    with print_lock:
    print(*args, **kwargs)
[...]
try:
    [thread protected code]
    safe_print('[...]')



Except for the first one all kind of have the same performance. The 
problem was I placed the acquire/release around the whole code block, 
instead of only the print statements.

Thanks a lot! ;)

> For generality the lock should be per file: the above hack uses one
> lock for any file, so that's going to stall overlapping prints to
> different files; inefficient.
>
> There are other things than the above, but at least individual prints will
> never overlap. If you have interleaved prints, show us.
>
> | Is there a 100% sure method to make print thread safe? Can it be fast???
>
> Depends on what you mean by "fast". It will be slower than code
> with no lock; how much would require measurement.
>
> Cheers,
> --
> Cameron Simpson 
>
> My own suspicion is that the universe is not only queerer than we suppose,
> but queerer than we *can* suppose.
> - J.B.S. Haldane "On Being the Right Size"
> in the (1928) book "Possible Worlds"
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to write fast into a file in python?

2013-05-20 Thread Carlos Nepomuceno
Oh well! Just got a flashback from the old times at the 8-bit assembly line.

Dirty deeds done dirt cheap! lol


> Date: Sun, 19 May 2013 16:44:55 +0100
> From: pyt...@mrabarnett.plus.com
> To: python-list@python.org
> Subject: Re: How to write fast into a file in python?
>
> On 19/05/2013 04:53, Carlos Nepomuceno wrote:
>> 
>>> Date: Sat, 18 May 2013 22:41:32 -0400
>>> From: da...@davea.name
>>> To: python-list@python.org
>>> Subject: Re: How to write fast into a file in python?
>>>
>>> On 05/18/2013 01:00 PM, Carlos Nepomuceno wrote:
>>>> Python really writes '\n\r' on Windows. Just check the files.
>>>
>>> That's backwards. '\r\n' on Windows, IF you omit the b in the mode when
>>> creating the file.
>>
>> Indeed! My mistake just made me find out that Acorn used that inversion on 
>> Acorn MOS.
>>
>> According to this[1] (at page 449) the OSNEWL routine outputs '\n\r'.
>>
>> What the hell those guys were thinking??? :p
>>
> Doing it that way saved a few bytes.
>
> Code was something like this:
>
> FFE3 .OSASCI CMP #&0D
> FFE5 BNE OSWRCH
> FFE7 .OSNEWL LDA #&0A
> FFE9 JSR OSWRCH
> FFEC LDA #&0D
> FFEE .OSWRCH ...
>
> This means that the contents of the accumulator would always be
> preserved by a call to OSASCI.
>
>> "OSNEWL
>> This call issues an LF CR (line feed, carriage return) to the currently 
>> selected
>> output stream. The routine is entered at &FFE7."
>>
>> [1] http://regregex.bbcmicro.net/BPlusUserGuide-1.07.pdf
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
sys.stdout.write() does not suffer from the newlines mess up when printing from 
many threads, like print statement does.

The only usage difference, AFAIK, is to add '\n' at the end of the string.

It's faster and thread safe (really?) by default.

BTW, why I didn't find the source code to the sys module in the 'Lib' directory?


> Date: Tue, 21 May 2013 11:50:17 +1000
> Subject: Re: Please help with Threading
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral
>  wrote:
>> OK, if the python interpreter has a global hiden print out
>> buffer of ,say, 2to 16 K bytes, and all string print functions
>> just construct the output string from the format to this string
>> in an efficient low level way, then the next question
>> would be that whether the uses can use functions in this
>> low level buffer for other string formatting jobs.
>
> You remind me of George.
> http://www.chroniclesofgeorge.com/
>
> Both make great reading when I'm at work and poking around with random
> stuff in our .SQL file of carefully constructed mayhem.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
> On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral
>  wrote:
>> OK, if the python interpreter has a global hiden print out
>> buffer of ,say, 2to 16 K bytes, and all string print functions
>> just construct the output string from the format to this string
>> in an efficient low level way, then the next question
>> would be that whether the uses can use functions in this
>> low level buffer for other string formatting jobs.
>
> You remind me of George.
> http://www.chroniclesofgeorge.com/
>
> Both make great reading when I'm at work and poking around with random
> stuff in our .SQL file of carefully constructed mayhem.
>
> ChrisA


lol I need more cowbell!!! Please!!! lol
  
-- 
http://mail.python.org/mailman/listinfo/python-list


PEP 378: Format Specifier for Thousands Separator

2013-05-20 Thread Carlos Nepomuceno
Is there a way to format integers with thousands separator (digit grouping) 
like the format specifier of str.format()?

I'm currently using the following:

>>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
Number = 12,345

'x' is unsigned integer so it's like using a sledgehammer to crack a nut!

I'd like to have something like:

sys.stdout.write('Number = %,u\n' % x)


Is that possible? How can I do it if not already available? 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: alyssonbr...@gmail.com 
> Date: Tue, 21 May 2013 09:03:13 -0300 
> Subject: Re: PEP 378: Format Specifier for Thousands Separator 
> To: python-list@python.org 
>  
> This work in 3.1+: 
>  
> $ python3 
> Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) 
> [GCC 4.4.5] on linux2 
> Type "help", "copyright", "credits" or "license" for more information. 
> >>> one_number = 1234567 
> >>> print('number={:,}'.format(one_number)) 
> number=1,234,567 
> >>> 
>  

Thank you, but let me rephrase it. I'm already using str.format() but I'd like 
to use '%' (BINARY_MODULO) operator instead.

I've looked into the source code of CPython 2.7.5 and I've found no evidence of 
the thousands separator been implemented on formatint() in 
"Objects/unicodeobject.c".

I also didn't find the _PyString_FormatLong() used in formatlong(). Where is 
_PyString_FormatLong() located?

So, the question is: Where would I change the CPython 2.7.5 source code to 
enable '%' (BINARY_MODULO) to format using the thousands separator like 
str.format() does, such as:

>>>sys.stderr.write('%,d\n' % 1234567)
1,234,567 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: kwpol...@gmail.com
> Date: Tue, 21 May 2013 21:06:11 +0200
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
>
> On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
>  wrote:
>> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
>> like to use '%' (BINARY_MODULO) operator instead.
>
> There is no real reason to do this. `str.format()` is the new shiny
> thing you should be using all the time. Also, '%' is BINARY_MODULO
> (where did you even get that name from?) if and only if you have two
> numbers, and it performs the modulo division (eg. 27 % 5 = 2)

I did:

>>> def fmt(s):
... return '%s' % s
...
>>> import dis
>>> dis.dis(fmt)
  2   0 LOAD_CONST   1 ('%s')
  3 LOAD_FAST    0 (s)
  6 BINARY_MODULO
  7 RETURN_VALUE
>>>

Then I've looked for 'BINARY_MODULO' in "Python/ceval.c" and found:

    case BINARY_MODULO:
    w = POP();
    v = TOP();
    if (PyString_CheckExact(v))
    x = PyString_Format(v, w);
    else
    x = PyNumber_Remainder(v, w);


Then I've looked for 'PyString_Format' and found it in "Objects/stringobject.c"

Analysing the code of "stringobject.c" I've found formatint() and formatlong().

I'm not using str.format() because it's slower than '%' and because I love '%'. 
str.format() looks like Java shit to me!

>> So, the question is: Where would I change the CPython 2.7.5 source code to 
>> enable '%' (BINARY_MODULO) to format using the thousands separator like 
>> str.format() does, such as:
>>
>>>>>sys.stderr.write('%,d\n' % 1234567)
>> 1,234,567
>
> This will make your code unportable and useless, depending on one
> patch you made. Please don’t do that. Instead,

I'm just learning how to improve things! ;)

>>>>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
>> Number = 12,345
>>
>> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut!
>
> In Python? Tough luck, every int is signed. And it isn’t just a
> sledgehammer, it’s something worse. Just do that:
>
>>>> sys.stdout.write('Number = {:,.0f}\n'.format(x))
>
> Much more peaceful.

Indeed! I just cut and pasted my code to create an example for the message. The 
actual format operation isn't done at the sys.stdout.write().

> You can also do a print, like everyone sane would. Where did you
> learn Python from? “Python Worst Practice for Dummies”?

lol I'm learning from my big mistakes up to now and a ton of online tutorials, 
besides "Dive into Python" (2004)[1], "Python Programming" (2012)[2] and 
"Programming Python, 3rd Ed" (2006) [print]

print isn't thread safe. That's why I've chosen sys.stdout.write() -- it's 
faster and thread safe by default.

I don't need any fancy formating, just need to send the string to screen.


[1] http://www.diveintopython.net/
[1] http://en.wikibooks.org/wiki/Python_Programming

> --
> Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
> stop html mail | always bottom-post
> http://asciiribbon.org | http://caliburn.nl/topposting.html   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno
> Analysing the code of "stringobject.c" I've found formatint() and 
> formatlong().

I mean _PyString_FormatLong() 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: breamore...@yahoo.co.uk
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Tue, 21 May 2013 20:26:41 +0100
>
> On 21/05/2013 20:13, Skip Montanaro wrote:
>>> Thank you, but let me rephrase it. I'm already using str.format() but I'd 
>>> like to use '%' (BINARY_MODULO) operator instead.
>>
>> That's unlikely to change. If not deprecated already string
>> interpolation using the modulo operator has lost favor to the string
>> object's format method.
>>

I used to think str.__mod__() was going to be deprecated until Steven told me 
it was a myth! Think I got that idea from the own Python docs, but it's gone by 
now. Nevermind...

The fact is I have no need for str.format(). It's slow and awkward. 
str.format() looks like COBOL/Java idiom to me. I love Python! '%' is much more 
cool!!!

> Please stop perpetuating this myth, see
> http://mail.python.org/pipermail/python-dev/2012-February/116789.html
> and http://bugs.python.org/issue14123
>
> --
> If you're using GoogleCrap™ please read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>
> Mark Lawrence
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> Date: Tue, 21 May 2013 14:53:54 -0500
> From: bahamutzero8...@gmail.com
> To: python-list@python.org
[...]
>>
> What myth? People should indeed be using .format(), but no one said % 
> formatting was going away soon. Also, the suggested change to the docs
> wasn't made and the issue is closed. The current docs do not say that % 
> formatting isn't going to be deprecated, but it does mention its
> caveats and suggests .format(). If you are trying to say that % formatting 
> will never ever go away, then you are wrong. It is highly
> unlikely to go away in a 3.x release, but /may/ get phased out in Python 4.0.

I vote for keeping str.__mod__()!

Anyway, is it possible to overload str.__mod__() without deriving a class? I 
mean to have something like:

old_mod = str.__mod__
def new_mod(x):
    global old_mod
    try:
        old_mod(x)
    except ValueError, ex:
    #catch ValueError: unsupported format character ',' (0x2c) at index 1
        #process new '%,d' format here
    return '{:,}'.format(x)  #just to illustrate the behaviour. it would 
have it's own faster code

str.__mod__ = new_mod  #this raises TypeError: can't set attributes of 
built-in/extension type 'str'
sys.stdout.write('num=%,d\n' % 1234567)


> --
> CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Carlos Nepomuceno
I was looking for something else and just found what I think is the place where 
I was first exposed to the myth[1]:

"Since str.format() is quite new, a lot of Python code still uses the % 
operator. However, because this old style of formatting will eventually be 
removed from the language, str.format() should generally be used."

Is this tutorial outdated or this still an issue?

[1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Wed, 22 May 2013 02:42:56 +
> To: python-list@python.org
>
> On Tue, 21 May 2013 23:22:24 +0300, Carlos Nepomuceno wrote:
>
>> Anyway, is it possible to overload str.__mod__() without deriving a
>> class? I mean to have something like:
>
> No, not in Python. If you want to monkey-patch built-in classes on the
> fly, with all the troubles that causes, use Ruby.
>

So, the only alternative to have "'%,d' % x" rendering the thousands separator 
output would a C source code modification?

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


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-21 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Wed, 22 May 2013 03:08:54 +
> To: python-list@python.org
[...]
>> So, the only alternative to have "'%,d' % x" rendering the thousands
>> separator output would a C source code modification?
>
> That's one alternative. But the language you would be then running will
> no longer be Python.
>
> Another alternative would be to write a pre-processor that parses your
> Python source code, extracts any reference to the above, and replaces it
> with a call to the appropriate format call. But not only is that a lot of
> work for very little gain, but it's also more or less impossible to do in
> full generality. And again, what you are running will be something
> different than Python, it will be Python plus a pre-processor.
>
>
> Don't fight the language. You will lose.

Not fighting the language. In fact it's not even a language issue.
All I need is a standard library[1] improvement: "%,d"! That's all!

Just to put in perspective the performance difference of str.__mod__() and 
str.format():

C:\Python27>python -m timeit -cv -n1000 "'%d'%12345"
raw times: 0.386 0.38 0.373
1000 loops, best of 3: 0.0373 usec per loop

C:\Python27>python -m timeit -cv -n1000 "'{:d}'.format(12345)"
raw times: 7.91 7.89 7.98
1000 loops, best of 3: 0.789 usec per loop

C:\Python27>python -m timeit -cv -n1000 "'{:,d}'.format(12345)"
raw times: 8.7 8.67 8.78
1000 loops, best of 3: 0.867 usec per loop

That shows str.format() is 20 times slower than str.__mod__() for a simple 
decimal integer literal formatting.
And it's additionally 10% slower if the thousands separator format specifier 
(',') is used.

[1] I think that translates to Python source code in 'Objects/stringobject.c' 
and maybe 'Objects/unicodeobject.c'

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


RE: Myth Busters: % "this old style of formatting will eventually be removed from the language"

2013-05-21 Thread Carlos Nepomuceno
Ok. Thanks!

bugs.python.org/issue18031


> Date: Tue, 21 May 2013 23:26:58 -0400
> From: n...@nedbatchelder.com
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
> Subject: Re: Myth Busters: % "this old style of formatting will eventually be 
> removed from the language"
>
> On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:
>> I was looking for something else and just found what I think is the place 
>> where I was first exposed to the myth[1]:
>>
>> "Since str.format() is quite new, a lot of Python code still uses the % 
>> operator. However, because this old style of formatting will eventually be 
>> removed from the language, str.format() should generally be used."
>>
>> Is this tutorial outdated or this still an issue?
>>
>> [1] http://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting
>
> That tutorial is out of date. %-formatting isn't being removed.
>
> --Ned.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> Date: Wed, 22 May 2013 07:25:13 -0400
> From: n...@nedbatchelder.com
[...]
> You have to keep in mind that 2.7 is not getting any new features, no
> matter how small they seem. If you create a patch that implements the
> comma flag in %-formatting, it *might* go into 3.x, but it will not go
> into 2.7.
>
> --Ned.

No problem. I have just discovered i was measuring the wrong thing.

My test case is been optimized at compile time by CPython that treats "'%d' % 
12345" as a constant.
My use case is different because I almost have no literals been used with % 
operator.

So my gain isn't that great. In fact it's faster with str.format() than %, and 
it's even faster if I use the default format specifier.

C:\Python27>python -m timeit -cv -n1000 -s"v=12345" "'%d'%v"
raw times: 10.5 10.7 10.7
1000 loops, best of 3: 1.05 usec per loop

C:\Python27>python -m timeit -cv -n1000 -s"v=12345" "'{:d}'.format(v)"
raw times: 8.11 8.09 8.02
1000 loops, best of 3: 0.802 usec per loop

C:\Users\Josue\Documents\Python>python -m timeit -cv -n1000 -s"v=12345" 
"'{}'.format(v)"
raw times: 5.3 5.5 5.62
1000 loops, best of 3: 0.53 usec per loop

Using variables (100% of cases) makes str.format() 50% faster than %.   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
Funny! I made a lot of assumptions regarding your requirements specification. 
Let me know if it isn't what you need:

### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
#    '10,11,12,13,14,15,16,17,18,19\n' \
#    '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0]   : file '1.txt'
# contents[1][2]    : 3rd row of file '2.txt'
# contents[3][4][5] : 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4])  : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'

filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents  = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] 
for x in filenames]
s1c  = [sum([r[0] for r in f]) for f in contents]
a1r  = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join([x for x in ['File "{}" has 1st row average = 
{:.2f}'.format(n,a1r[i]) if s1c[i]==50 else '' for i,n in enumerate(filenames)] 
if x])



> From: wilke...@gmail.com 
> Date: Thu, 23 May 2013 01:13:19 +0900 
> Subject: file I/O and arithmetic calculation 
> To: python-list@python.org 
>  
>  
> Dear all, 
>  
> I would appreciate if someone could write a simple python code for the  
> purpose below: 
>  
> I have five text files each of 10 columns by 10 rows as follows: 
>  
>  
>  
> file_one = 'C:/test/1.txt' 
> file_two = 'C:/test/2.txt' 
> . . . 
> file_five = 'C:/test/5.txt' 
>  
> I want to calculate the mean of first row (10 elements) for each file  
> (5 files), if mean of first column (10 elements) of each file (5  
> files) is 50. 
>  
> Thank you in advance. 
>  
> Keira 
>  
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> Date: Wed, 22 May 2013 13:26:23 -0700
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> From: prueba...@latinmail.com
> To: python-list@python.org
[...]
>
> Maybe a cformat(formatstring, variables) function should be created
> in the string module so people who prefer that can use it. I don't
> mind the C formatting syntax but I don't like the fact that the %
> operator does something totally different when the first variable is
> an integer and the fact that it misbehaves if the second variable is a
> tuple.
> --
> http://mail.python.org/mailman/listinfo/python-list

I still don't understand why % benefits from literals optimization 
("'%d'%12345") while '{:d}'.format(12345) doesn't.

What "totally different" you talking about? Please give me an example.  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Newbie question about evaluating raw_input() responses

2013-05-22 Thread Carlos Nepomuceno

> From: alister.w...@ntlworld.com
[...]
> Kevin
>
> Please write out 1000 time (without using any form of loop)
>
> "NEVER use input in python <3.0 it is EVIL"*
>
> as Chris A point out it executes user input an can cause major damage
> (reformatting the hard disk is not impossible!)
>

Indeed! input is eval(raw_input())! lol 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
[...]
>
> Do you find this code easy to read? I wouldn't write something like
> this and I certainly wouldn't use it when explaining something to a
> beginner.
>
> Rather than repeated list comprehensions you should consider using a
> single loop e.g.:
>
> for filename in filenames:
> # process each file
>
> This will make the code a lot simpler.
>
>
> Oscar

Indeed, but for that you can use Pascal.

List comprehensions it's what Python does best!

The code is pretty obvious to me, I mean there's no obfuscation at all. 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
># contents[3][4][5] : 6th column of 5th row of file '4.txt'

BTW, it should read

# contents[3][4][5] : 6th value of 5th row of file '4.txt'  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: denismfmcma...@gmail.com
[...]
>
> import re
> def v(s):
> l=len(s)
> t=0.
> for i in range(l):
> t=t+(abs(ord(s[i]))*1.)
> return t/(l*1.)
> for n in range(5):
> m="c:/test/"+str(n+1)+".txt"
> f=open(m,"r")
> d=[]
> t=0.
> for l in range(10):
> d=d+[re.findall(r"[0-9.eE+-]+",f.readline())]
> t=t+v(d[l][0])
> f.close()
> c=t/10.
> if c==50.:
> t=0.
> for u in range(10):
> t=t+v(d[0][u])
> r=t/10.
> print "%s C1: %f R1: %f"%(m,c,r)
>
> --
> Denis McMahon, denismfmcma...@gmail.com
> --
> http://mail.python.org/mailman/listinfo/python-list

Can you send it again without tabs?   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
> Date: Thu, 23 May 2013 01:34:37 +0100
> Subject: Re: file I/O and arithmetic calculation
> To: carlosnepomuc...@outlook.com
> CC: python-list@python.org
>
> On 23 May 2013 00:49, Carlos Nepomuceno  wrote:
>>
>> The code is pretty obvious to me, I mean there's no obfuscation at all.
>
> I honestly can't tell if you're joking.

I'm not! lol  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-22 Thread Carlos Nepomuceno

> From: oscar.j.benja...@gmail.com
> Date: Thu, 23 May 2013 01:30:53 +0100
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> To: carlosnepomuc...@outlook.com
> CC: prueba...@latinmail.com; python-list@python.org
>
> On 22 May 2013 23:31, Carlos Nepomuceno  wrote:
>>
>> I still don't understand why % benefits from literals optimization 
>> ("'%d'%12345") while '{:d}'.format(12345) doesn't.
>
> There's no reason why that optimisation can't happen in principle.
> However no one has written a patch for it. Why don't you look into
> what it would take to make it happen?
>
>
> Oscar

Maybe I'll look into that later, but I couldn't even find how the hell they 
made _Py_InsertThousandsGrouping() been called.

That's what I got when analysing % formating:

Thousands separator format specifier for str.__mod__()
==

@Objects/stringobject.c: implements formatint() for '%' processing
-Looking for code used in str.format()

@Objects/stringlib/formatter.h: implements str.format()
-It uses STRINGLIB_GROUPING() to do the job.

@Objects/stringlib/stringdefs.h: #define STRINGLIB_GROUPING   
_PyString_InsertThousandsGrouping
@Objects/stringlib/unicodedefs.h: #define STRINGLIB_GROUPING   
_PyUnicode_InsertThousandsGrouping
@Objects/stringobject.c: #define _Py_InsertThousandsGrouping 
_PyString_InsertThousandsGrouping
@Objects/stringobject.h: declares _PyString_InsertThousandsGrouping()
@???: ??? _PyString_InsertThousandsGrouping ??? _Py_InsertThousandsGrouping
@Objects/stringlib/localeutil.h: implements _Py_InsertThousandsGrouping()


Let me explain what that means. I found no relating declarations/definitions 
that turn _PyString_InsertThousandsGrouping into _Py_InsertThousandsGrouping.

So, I don't even know how that source code compiles without error.

:/ really strange...


Not to mention the lots of code inside header definition files! Weird   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
The last line of my noob piece can be improved. So this is it:

### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
#    '10,11,12,13,14,15,16,17,18,19\n' \
#    '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0]   : file '1.txt'
# contents[1][2]    : 3rd row of file '2.txt'
# contents[3][4][5] : value on the 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4])  : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'

filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents  = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] 
for x in filenames]
s1c  = [sum([r[0] for r in f]) for f in contents]
a1r  = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join(['File "{}" has 1st row average = {:.2f}'.format(n,a1r[i]) for 
i,n in enumerate(filenames) if s1c[i]==50]) 
   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Modules list-tool

2013-05-22 Thread Carlos Nepomuceno
Have you tried Inspect Shell[1]?

All you have to do to monitor your script is include "import inspect_shell" in 
the 1st line of you source code and then run:

"python inspect_shell.py"

When you get the prompt you can enter the following to show the list of modules:

localhost:1234> '\n'.join(['{}={}'.format(k,v) for k,v in sys.modules.items()])


[1] https://github.com/amoffat/Inspect-Shell



> Date: Wed, 22 May 2013 21:39:52 -0700 
> Subject: Re: Modules list-tool 
> From: drsali...@gmail.com 
> To: gva...@broadpark.no 
> CC: python-list@python.org 
>  
> On Tue, May 21, 2013 at 12:35 PM, Gisle Vanem  
> mailto:gva...@broadpark.no>> wrote: 
> Are anyone aware of a tool that can show me at run-time 
> which modules (pyd/dll) are loaded into a Python program at a specific  
> time (or over time)? 
>  
> To clarify, e.g. when running a sample from PyQt4 
> (examples\tutorials\addressbook\part1.pyw) and using Process Explorer [1], 
> I can launch WinDbg from it and get this list of modules: 
>  
>  
> ModLoad: 1d00 1d00a000   G:\ProgramFiler\Python27\python.EXE 
> ModLoad: 7c90 7c9b1000   F:\WINDOWS\system32\ntdll.dll 
> ModLoad: 7c80 7c8f7000   F:\WINDOWS\system32\kernel32.dll 
> ModLoad: 1e00 1e261000   f:\windows\system32\python27.dll 
> ModLoad: 7e41 7e4a1000   F:\WINDOWS\system32\USER32.dll 
> ModLoad: 77f1 77f59000   F:\WINDOWS\system32\GDI32.dll 
> ModLoad: 77dc 77e6a000   F:\WINDOWS\system32\ADVAPI32.dll 
> ModLoad: 77e7 77f03000   F:\WINDOWS\system32\RPCRT4.dll 
> ModLoad: 77fe 77ff1000   F:\WINDOWS\system32\Secur32.dll 
> ModLoad: 7c9c 7d1d8000   F:\WINDOWS\system32\SHELL32.dll 
> ModLoad: 77c0 77c58000   F:\WINDOWS\system32\msvcrt.dll 
> ModLoad: 77f6 77fd6000   F:\WINDOWS\system32\SHLWAPI.dll 
> ModLoad: 7852 785c3000
> f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCR90.dll
>  
> ModLoad: 7637 7638d000   f:\windows\system32\IMM32.DLL 
> ModLoad: 62f2 62f29000   f:\windows\system32\LPK.DLL 
> ModLoad: 7542 7548b000   f:\windows\system32\USP10.dll 
> ModLoad: 773c 774c3000  
> f:\windows\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202\comctl32.dll
>  
> ModLoad: 5d5d 5d66a000   F:\WINDOWS\system32\comctl32.dll 
> ModLoad: 78aa 78b5f000   f:\windows\system32\MSVCR100.dll 
> ModLoad: 00d9 00f29000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore.pyd 
> ModLoad: 6700 6726
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtCore4.dll 
> ModLoad: 774d 7760e000   F:\WINDOWS\system32\ole32.dll 
> ModLoad: 71aa 71ab7000   f:\windows\system32\WS2_32.dll 
> ModLoad: 71a9 71a98000   f:\windows\system32\WS2HELP.dll 
> ModLoad: 7848 7850e000
> f:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.6161_x-ww_31a54e43\MSVCP90.dll
>  
> ModLoad: 00a6 00a73000
> g:\ProgramFiler\Python27\lib\site-packages\sip.pyd 
> ModLoad: 011f 0177f000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui.pyd 
> ModLoad: 6500 657c4000
> g:\ProgramFiler\Python27\lib\site-packages\PyQt4\QtGui4.dll 
> ... 
>  
> - 
>  
> My example may be mooth since part1.pyw above (when I enter 
> the debugger) is just waiting for events. The stack of pythonw.exe as  
> shown in Process Explorer: 
> ... 
> ntdll.dll!ZwWaitForMultipleObjects+0xc 
> kernel32.dll!WaitForMultipleObjectsEx+0x12c 
> USER32.dll!RealMsgWaitForMultipleObjectsEx+0x13e 
> QtCore4.dll!QEventDispatcherWin32::processEvents+0x3c3 
> ntdll.dll!RtlAcquirePebLock+0x28 
>  
> Is there a tool that can do something similar? (written in Python  
> maybe?). But a bit simpler to use than my current method. Just launch  
> it from the command-line; something like "pyXX part1.pyw " 
>  
> [1] http://technet.microsoft.com/en-gb/sysinternals/bb896653 
>  
> --gv 
> --  
> http://mail.python.org/mailman/listinfo/python-list 
>  
> Python -v reports on modules. 
>  
> -- http://mail.python.org/mailman/listinfo/python-list
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Future standard GUI library

2013-05-23 Thread Carlos Nepomuceno
You don't! If your app needs local content just use a regular open() (or your 
browser) to read the files and render them as you see fit.

For remote content you just need the 'urllib2' module or something like 
'requests' module to get the data.


> Date: Wed, 22 May 2013 19:31:55 -0700
> Subject: Re: Future standard GUI library
> From: llanited...@veawb.coop
[...]
>
> I've been thinking about that myself for some future app ideas. If you have a 
> stand-alone app working from your web browser, don't you need an embedded web 
> server to utilize the file system? Is a system like Django for an app 
> overkill? Or is its embedded development server underkill for a single-user 
> browser-based application?
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-23 Thread Carlos Nepomuceno

> Date: Thu, 23 May 2013 06:44:05 -0700
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> From: prueba...@latinmail.com
> To: python-list@python.org
[...]
 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)?  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-23 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: tjre...@udel.edu
[...]
>> 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.
>
> The problem is that interpolating 1 to many items into a string is *not*
> a binary operation. The needed hack to pretend that it is, using a tuple
> to represent multiple items rather than just itself, was one of the
> reasons for making string formatting a honest function, where multiple
> items to be formatted are passed as multiple arguments.

Thanks so much guys! Now I understand why some people hate %-formatting!

I don't think that's a problem because there's no format specifier for tuples 
in the %-formatting definition[1].
So it's up to the user to make the necessary conversion.

I still love the %-formatting style!

Can str.format() do the following?

f = '%d %d %d'
v = '1,2,3'
print f % eval(v)

If yes, how?


[1] http://docs.python.org/2/library/stdtypes.html#string-formatting
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: file I/O and arithmetic calculation

2013-05-23 Thread Carlos Nepomuceno

> From: denismfmcma...@gmail.com
[...]
>> Dear all who involved with responding to my question - Thank you so much
>> for your nice code which really helped me.
>
> Hold on a sec? Someone posted code that gave the correct answer to a
> homework question?
>
> --
> Denis McMahon, denismfmcma...@gmail.com

Not sure what she've asked, but mine certainly do what I think she've asked.
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PEP 378: Format Specifier for Thousands Separator

2013-05-23 Thread Carlos Nepomuceno
Thank you! Hail Eris!!! :)


> Date: Thu, 23 May 2013 21:17:54 -0400 
> Subject: Re: PEP 378: Format Specifier for Thousands Separator 
> From: malaclyp...@gmail.com 
> To: carlosnepomuc...@outlook.com 
> CC: python-list@python.org 
>  
> On Thu, May 23, 2013 at 6:20 PM, Carlos Nepomuceno  
> mailto:carlosnepomuc...@outlook.com>>  
> wrote: 
> Can str.format() do the following? 
>  
> f = '%d %d %d' 
> v = '1,2,3' 
> print f % eval(v) 
>  
> ​Sure: 
>  
> Python 3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit  
> (Intel)] on win32 
> >>> f = "{} {} {}" 
> >>> v = "1,2,3" 
> >>> print(f.format(*eval(v))) 
> 1 2 3 
> >>> 
>  
> The * unpacks the tuple returned from eval(), so that you get 3  
> separate parameters passed to format(), instead of the single tuple.​ 
>  
> -- 
> ​ 
> Jerry​ 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-05-23 Thread Carlos Nepomuceno
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: 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 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: 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: 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


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: 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


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


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: 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


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 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<http://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 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: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 23:05:17 -0700
> Subject: Re: 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
[...]
> ya steven i had done the similar logic but thats not satisfying my professor
> he had given the following constrains
> 1. No in-built functions should be used
> 2. we are expecting a O(n) solution
> 3. Don't use count method

That's trivial!

# l is a list of numbers: 0,1,2
def order_n(l):
    r = []
    count = [0]*3
    count[2] = len(l)
    for i in range(len(l)):
    count[1] += abs((l[i]>0)-1)
    r.insert(count[l[i]], l[i])
    return r

'count' is a list I've defined to count the quantity of the elements in the 
argument, not the method.

I don't think it needs any explanations, but if you have any doubts just ask. ;)

Good luck!
-- 
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-25 Thread Carlos Nepomuceno

> Date: Sat, 25 May 2013 18:28:32 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sat, May 25, 2013 at 5:53 PM, Carlos Nepomuceno
>  wrote:
>> 
>>> Date: Fri, 24 May 2013 23:05:17 -0700
>>> 1. No in-built functions should be used
>> count[2] = len(l)
>
> Fail! :)
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list

lol I forgot to include this monkey patch! ;)

def length(l):
    x=0
    y=l[:]
    while y:
    x+=1
    y.pop()
    return x  
-- 
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-25 Thread Carlos Nepomuceno
lol

def absolute(x):
    return x if x>0 else -x

def reach(x):
    y=[]
    z=0
    while z Date: Sat, 25 May 2013 18:47:24 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sat, May 25, 2013 at 6:43 PM, Carlos Nepomuceno
>  wrote:
>> 
>> lol I forgot to include this monkey patch! ;)
>>
>> def length(l):
>> x=0
>> y=l[:]
>> while y:
>> x+=1
>> y.pop()
>> return x
>
> Nice. Now eliminate abs (easy) and range. :)
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
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-25 Thread Carlos Nepomuceno

> Date: Sat, 25 May 2013 19:01:09 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
[...]
> Very good. You are now in a position to get past the limitations of a
> restricted-environment eval/exec. Avoiding builtins is actually a fun
> skill to hone.
>
> ChrisA


I'm glad he didn't ask for a Pseudo-RNG without built-ins! ;)   
  
-- 
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-25 Thread Carlos Nepomuceno
lol http://search.dilbert.com/comic/Random%20Nine


> Date: Sat, 25 May 2013 19:14:57 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sat, May 25, 2013 at 7:10 PM, Carlos Nepomuceno
>  wrote:
>> 
>>> Date: Sat, 25 May 2013 19:01:09 +1000
>>> Subject: Re: help how to sort a list in order of 'n' in python without 
>>> using inbuilt functions??
>>> From: ros...@gmail.com
>>> To: python-list@python.org
>> [...]
>>> Very good. You are now in a position to get past the limitations of a
>>> restricted-environment eval/exec. Avoiding builtins is actually a fun
>>> skill to hone.
>>>
>>> ChrisA
>>
>>
>> I'm glad he didn't ask for a Pseudo-RNG without built-ins! ;)
>
> def random_number():
> return 7
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
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-25 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: breamore...@yahoo.co.uk
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> Date: Sat, 25 May 2013 13:01:06 +0100
[...]
> In my book this is another fail as lists are inbuilt (yuck!) and so is
> the add function that'll be called for z+=1.

Indeed! It's a joke Mark! lol
;)
-- 
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-25 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> Date: Sat, 25 May 2013 14:28:33 +
> To: python-list@python.org
>
> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote:
>
>> def random_number():
>> return 7
>
> I call shenanigans! That value isn't generated randomly, you just made it
> up! I rolled a die *hundreds* of times and not once did it come up seven!


lol It worked fine on my d8! lol  
-- 
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-25 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 01:41:58 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano
>  wrote:
>> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote:
>>
>>> def random_number():
>>> return 7
>>
>> I call shenanigans! That value isn't generated randomly, you just made it
>> up! I rolled a die *hundreds* of times and not once did it come up seven!
>
> You've obviously never used a REAL set of dice. Now, I have here with
> me a set used for maths drill (to be entirely accurate, what I have
> here is the company's stock of them, so there are multiples of each of
> these - anyone need to buy dice?) with everything except the classic 1
> through 6 that everyone knows:
>
> * Six sides, faces marked 7 through 12
> * Six sides, faces marked "+x-\xf7+" and a "wild" marker (yes, two of +)
> * Ten sides, numbered 0 through 9
> * Eight sides, numbered 1 through 8
> * Twelve sides, as above
> * Twenty sides, as above
>
> Now, tabletop roleplayers will recognize the latter four as the ones
> notated as d10, d8, d12, and d20, but these are NOT for gameplay, they
> are for serious educational purposes! Honest!
>
> Anyway, all of those can roll a 7... well, one of them has to roll a
> \xf7, but close enough right? Plus, if you roll 2d6 (that is, two
> regular six-sided dice and add them up), 7 is statistically the most
> likely number to come up with. Therefore it IS random.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list


def f(x):
    return x+1

or you can just go:

f(roll_d6())

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


RE: Learning Python

2013-05-25 Thread Carlos Nepomuceno

> Date: Sat, 25 May 2013 18:11:11 +0530 
> Subject: Learning Python 
> From: pythona...@gmail.com 
> To: Python-list@python.org 
>  
> Hi All , 
>  
>   I have started leaning Python through web . Would like to know  
> if I should follow any book so that basics become clear with examples  
> also want to know like in perl i use to invoke perl -d to get a  
> debugged output is there any option in python. 
>  
> THanks, 
>  
> -- http://mail.python.org/mailman/listinfo/python-list


I have used those:

"Dive into Python" (2004)[1]
"Python Programming" (2012)[2]
"Programming Python, 3rd Ed" (2006) [print]
  
[1] http://www.diveintopython.net/
[1] http://en.wikibooks.org/wiki/Python_Programming 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Magazine

2013-05-25 Thread Carlos Nepomuceno

> From: r...@panix.com
> Subject: Re: Python Magazine
> Date: Sat, 25 May 2013 11:24:03 -0400
> To: python-list@python.org
>
> In article ,
> Chris Angelico  wrote:
>
>>> Also, comparison of Python flavors (CPython, PyPy, Cython, Stackles, etc.)
>
> Stackles? That sounds like breakfast cereal.
>
> "New all-natural stackles, with 12 essential vitamins, plus fiber!"
> --
> http://mail.python.org/mailman/listinfo/python-list

lol pardon my typo! I'm really considering that cereal! lol 
  
-- 
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-25 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 03:23:44 +1000
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: ros...@gmail.com
> To: python-list@python.org
>
> On Sun, May 26, 2013 at 3:17 AM, Carlos Nepomuceno
>  wrote:
>> def f(x):
>> return x+1
>>
>> or you can just go:
>>
>> f(roll_d6())
>
> Hmm. Interesting. So now we have a question: Does adding 1 to a random
> number make it less random? It adds determinism to the number; can a
> number be more deterministic while still no less random?
>
> Ah! I know. The answer comes from common sense:
>
> a = random() # a is definitely a random number
> a -= random() # a is no longer random, we subtracted all the randomness from 
> it
>
> Of course, since number-number => number, a is still a number. And so
> we can conclude that adding 1 to a random dice roll does indeed leave
> all the randomness still in it. But wait! That means we can do
> better!!
>
> a = random() # a is a random number
> a *= 5 # a is clearly five times as random now!
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list

It depends if the result (any operation) is in the required range.

For example: "int(random.random()+1)" it's not random at all!

But "int(random.random()*1000)" my look random if it fits your needs.

;)
-- 
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-25 Thread Carlos Nepomuceno

> Date: Fri, 24 May 2013 23:05:17 -0700
> Subject: Re: help how to sort a list in order of 'n' in python without using 
> inbuilt functions??
> From: lokeshkopp...@gmail.com
[...]

> ya steven i had done the similar logic but thats not satisfying my professor
> he had given the following constrains
> 1. No in-built functions should be used
> 2. we are expecting a O(n) solution
> 3. Don't use count method


PS: If you find something faster please let me know!
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Magazine

2013-05-25 Thread Carlos Nepomuceno

> Date: Sat, 25 May 2013 20:04:28 -0700
> Subject: Re: Python Magazine
> From: john_lada...@sbcglobal.net
> To: python-list@python.org
>
> A perfectly fair point, Roy. It's just when you started suggesting connecting 
> to your neighbor's file server -- well, that's not something that many people 
> would ordinarily do. So, my mind leaped to the possibility of uninvited 
> connections.
>
> Related question: would denial-of-service attacks be more pernicious without 
> a NAT?
> --
> http://mail.python.org/mailman/listinfo/python-list

I don't think so.

IP blocking still a very common mitigation approach to DDoS, but it may cause 
denial of service to legitimate clients who share the same blocked public IP 
address used by the malicious clients. So, NAPT will still benefit DDoS 
attackers, at least temporarily (until the IP is unblocked).
   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: CrazyHTTPd - HTTP Daemon in Python

2013-05-25 Thread Carlos Nepomuceno
Your code isn't threaded. I suggest you consider[1] and take that road! ;) Good 
luck!

[1] http://bulk.fefe.de/scalable-networking.pdf


> To: python-list@python.org
> From: breamore...@yahoo.co.uk
> Subject: Re: CrazyHTTPd - HTTP Daemon in Python
> Date: Sun, 26 May 2013 05:06:50 +0100
>
> On 26/05/2013 04:55, cdorm...@gmail.com wrote:
>> This is a small little Project that I have started. Its a light little Web 
>> Server (HTTPd) coded in python. Requirements: Python 2.7 =< And Linux / BSD. 
>> I believe this could work in a CLI Emulator in windows too.
>> Welcome to check out the website powered by CrazyHTTPd: 
>> http://web.crazycoder.me:14081/index.html
>>
>> Please Email me with any bugs, errors, and/or comments about my little 
>> project: cdorm...@gmail.com
>>
>
> IMHO writing a project right now that is limited to Python 2 is about as
> much use as a chocolate teapot.
>
> --
> If you're using GoogleCrap™ please read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>
> Mark Lawrence
>
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Magazine

2013-05-25 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 14:31:57 +1000
> Subject: Re: Python Magazine
> From: ros...@gmail.com
> To: python-list@python.org
[...]
> I expect that IP blocks will be upgraded to /64 block blocks, if that
> starts being a problem. But it often won't, and specific IP address
> blocks will still be the norm.
>
> ChrisA


Blocking a whole network (/65) is totally undesirable and may even become 
illegal.

Currently it may not only happen at the target of the DDoS attack, but be 
spread all over the internet where block lists are enforced.

I don't expect that to happen and if it happens I'm surely in favor of 
protection against this type of 'solution' because it will block not only 
malicious clients but potentially many other legitimate clients.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 06:00:51 -0700
> Subject: Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 
> 'tuple'
> From: nikos.gr...@gmail.com
> To: python-list@python.org
>
> Anyone seeign somethign wrong?
> --
> http://mail.python.org/mailman/listinfo/python-list

I don't know any module 'http' in Python standard library.

Think you mean the 'http.cookies' module in Python 3.   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Solving the problem of mutual recursion

2013-05-26 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 10:21:05 -0700
> Subject: Re: Solving the problem of mutual recursion
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
>
> On May 26, 5:09 pm, Jussi Piitulainen 
> wrote:
>>
>> A light-weighter way is to have each task end by assigning the next
>> task and returning, instead of calling the next task directly. When a
>> task returns, a driver loop will call the assigned task, which again
>> does a bounded amount of work, assigns the next task, and returns.
>> Tasks can even pass parameters in the same way.
>>
> Yes, that's true - there are a number of ways of making it linear.
>
> What I'm particularly pleased about with my method is the parallelism
> that it achieves - with so little effort! The simulation is going to
> be computationally intense and this is going to make sure that the
> CPUs are all giving it their best shot. When I run this on my macbook,
> the python interpreter takes over 140% of CPU - with a bit of fine-
> tuning, it should be possible to have more concurrent threads and to
> use the four cores optimally.
>
> Naturally I'll need to be careful with the concurrency, but this is so
> simple and clean that it should be easy to avoid the main problems
> with accessing the same variables.
> --
> http://mail.python.org/mailman/listinfo/python-list

Python threads run in the same process and won't run concurrently:

"CPython implementation detail: In CPython, due to the Global Interpreter Lock, 
only one thread can execute Python code at once (even though certain 
performance-oriented libraries might overcome this limitation). If you want 
your application to make better use of the computational resources of 
multi-core machines, you are advised to use multiprocessing. However, threading 
is still an appropriate model if you want to run multiple I/O-bound tasks 
simultaneously."[1]

How can you get 140% of CPU? IS that a typo??

[1] http://docs.python.org/2/library/threading.html 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 10:52:14 -0700
> Subject: Cutting a deck of cards
> From: rvinc...@gmail.com
> To: python-list@python.org
>
> Suppose I have a deck of cards, and I shuffle them
>
> import random
> cards = []
> decks = 6
> cards = list(range(13 * 4 * decks))
> random.shuffle(cards)
>
> So now I have an array of cards. I would like to cut these cards at some 
> random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that 
> to the top half of the cards array.
>
> For some reason, I can't see how this can be done (I know that it must be a 
> simple line or two in Python, but I am really stuck here). Anyone have any 
> direction they can give me on this? Thanks, RVic, python newbie
>
> --
> http://mail.python.org/mailman/listinfo/python-list


list(range(13 * 4 * decks)) == range(13 * 4 * decks)

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


RE: Solving the problem of mutual recursion

2013-05-26 Thread Carlos Nepomuceno

> Date: Sun, 26 May 2013 11:13:12 -0700
> Subject: Re: Solving the problem of mutual recursion
> From: peter.h.m.bro...@gmail.com
> To: python-list@python.org
[...]
>> How can you get 140% of CPU? IS that a typo??
>>
> No, on a multi-core machine it's normal. The machine shows python
> running multiple threads - and the number of threads change as the
> program runs. Perhaps the OS/X implementation of python does allow
> concurrency when others don't. It certainly looks like it!


I pretty sure it doesn't run on multiple cores on Linux and Windows.

I've tested it and have been trying to find a better way achieve concurrency in 
Python. One of the ways is the multiprocessing module[1].

Do Mac OS shows "140%" CPU load when more than a single core is been used? lol 
Apple sucks!!! lol


[1] http://docs.python.org/2/library/multiprocessing.html   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Future standard GUI library

2013-05-26 Thread Carlos Nepomuceno

> From: felip...@gmx.net
> Subject: Re: Future standard GUI library
> Date: Sun, 26 May 2013 19:43:10 +0200
> To: python-list@python.org
[...]
> one, HTTP will never be a suitable transport layer for a RPC protocol.
>
> Sincerely,
>
> Wolfgang


Please give me an example of a "suitable transport layer for a RPC protocol".   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Help with implementing callback functions using ctypes

2013-05-26 Thread Carlos Nepomuceno
https://cffi.readthedocs.org/en/release-0.6/


> Date: Sun, 26 May 2013 09:12:10 -0700
> Subject: Re: Help with implementing callback functions using ctypes
> From: samj...@gmail.com
> To: python-list@python.org
>
> On Friday, May 24, 2013 8:56:28 AM UTC+5:30, Dan Stromberg wrote:
>> Cython is good. So is the new cffi, which might be thought of as a
>> safer (API-level) version of ctypes (which is ABI-level).
>
> Hi -- can you clarify what is this new CFFI and where I can get it? In the 
> Python 3 library reference I seem to see only CTypes.
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

> From: usenetm...@solar-empire.de
[...]
> Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
> False
>
> Adiaŭ
> Marc


What does "list(range(13 * 4 * decks))" returns in Python 3?
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: breamore...@yahoo.co.uk
[...]
> No wonder the Greek economy is so screwed up.
>
> --
> If you're using GoogleCrap™ please read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>
> Mark Lawrence

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


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

> To: python-list@python.org
> From: breamore...@yahoo.co.uk
[...]
> Wrong if you're using Python 3 :(
>
> --
> If you're using GoogleCrap™ please read this
> http://wiki.python.org/moin/GoogleGroupsPython.
>
> Mark Lawrence


Thanks guys! I've been delaying my dive into Python 3 (because I don't need it 
for now) but I'd like to run some code just to learn how different it is from 
Python 2 and even other Python flavors.

So, I'd like to know if it's possible to have multiple Python installations on 
the same machine (Windows 7 in my particular case) without messing one with 
each other. What care must I take not to mess up with them?

I've just found this[1] awesome service, but ridiculously it's PHP powered!!! 
lol Come on!!!

Why there aren't more Python powered websites available? What's the catch?


[1] http://www.compileonline.com/execute_python3_online.php 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

> Date: Mon, 27 May 2013 08:42:56 +1000
> Subject: Re: Cutting a deck of cards
> From: ros...@gmail.com
[...]
> Easy. Just grab the standard installer and hit it. You'll get two
> separate directories (or more; I have \Python26, \Python27, \Python32,
> \Python33 on this box), and you can run whichever you want. The one
> thing to take care of is .py associations; I haven't actually done it
> (on here, all I actually do is IDLE, pretty much), but as of 3.3, you
> should be able to use a Unix-style shebang to indicate which Python
> you want to invoke.
>
> ChrisA

I'm not even using shebangs in Windows because I thought it wouldn't make any 
difference. I'm used to run scripts like "python filename.py" from the command 
line. No problem!

So, Python 3.3 will honor if I insert "#!C:\Python27\python.exe"? if I install 
it after Python 2.7? Cool!!!   
-- 
http://mail.python.org/mailman/listinfo/python-list


Python error codes and messages location

2013-05-26 Thread Carlos Nepomuceno
Where can I find all error codes and messages that Python throws (actual codes 
and messages from exceptions raised by stdlib)?

I've already found the module 'errno' and got a dictionary (errno.errorcode) 
and some system error messages (os.strerror(errno.ENAMETOOLONG)) but there's 
more I couldn't find.   
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-05-26 Thread Carlos Nepomuceno
pipes usually consumes disk storage at '/tmp'. Are you sure you have enough 
room on that filesystem? Make sure no other processes are competing against for 
that space. Just my 50c because I don't know what's causing Errno 0. I don't 
even know what are the possible causes of such error. Good luck!


> Date: Sun, 26 May 2013 16:58:57 -0700
> Subject: Re: Piping processes works with 'shell = True' but not otherwise.
> From: luca.cer...@gmail.com
> To: python-list@python.org
[...]
> I tried to redirect the output to /dev/null using the Popen argument:
> 'stdin = os.path.devnull' (having imported os of course)..
> But this seemed to cause even more troubles...
>
>> Lastly, you may want to consider using a wrapper library such as 
>> http://plumbum.readthedocs.org/en/latest/ , which makes it easier to do 
>> pipelining and other such "fancy" things with subprocesses, while still 
>> avoiding the many perils of the shell.
>>
>>
> Thanks, I didn't know this library, I'll give it a try.
> Though I forgot to mention that I was using the subprocess module, because I 
> want the code to be portable (even though for now if it works in Unix 
> platform is OK).
>
> Thanks a lot for your help,
> Cheers,
> Luca
> --
> http://mail.python.org/mailman/listinfo/python-list   
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python error codes and messages location

2013-05-26 Thread Carlos Nepomuceno

> From: steve+comp.lang.pyt...@pearwood.info
> Subject: Re: Python error codes and messages location
> Date: Mon, 27 May 2013 00:53:41 +
> To: python-list@python.org
>
> On Mon, 27 May 2013 02:13:54 +0300, Carlos Nepomuceno wrote:
>
>> Where can I find all error codes and messages that Python throws (actual
>> codes and messages from exceptions raised by stdlib)?
>
> There is no list. It is subject to change from version to version,
> including point releases.
>
> Many functions and methods document which exceptions they can be expected
> to raise, or at least the *usual* exceptions, but many more do not. And
> the error messages themselves are implementation details and are subject
> to change without notice, even if the exception type is a documented part
> of the API.
>
> You can see a full list of built-in exception types in the docs:
>
> http://docs.python.org/3/library/exceptions.html
>
> but of course since they are classes, they can be subclassed, and in
> principle a function that raises (say) ValueError might sometimes raise a
> subclass of ValueError without documenting it.
>
> So the actual answer to your question is:
>
> "Read the source code."
>
>
> Sorry :-(

That's bad! I'd like to check all the IOError codes that may be raised by a 
function/method but the information isn't there.

Take open() for example[1]. It only says it raises an IOError exception.

I've had to try "open('','r')" to discover that Errno 22 is the one "IOError: 
[Errno 22] invalid mode ('r') or filename: ''"

Will I only be able to get all error codes reading the source code of open()?

Is there a way to simulate the errors instead of actually causing them? I mean 
not raising an instance of IOError that I create (like "raise IOError(666,'Hell 
happens')"), but one with the actual contents 'args = (errno, strerr)' that 
open() would raise?

Something like:

f=open('filename','r')
for x in range(25):
    try:
    f.raise_errno(x)
    except IOError, e:
    if   e.errno == 1:
    treat_err1()
    continue
    elif e.errno == 2:
    treat_err2()
    continue
...



[1] http://docs.python.org/2/library/functions.html#open

>> I've already found the module 'errno' and got a dictionary
>> (errno.errorcode) and some system error messages
>> (os.strerror(errno.ENAMETOOLONG)) but there's more I couldn't find.
>
> These are the standard C operating system and file system error codes,
> not Python exceptions.

Yes, the docs say it's from "linux/include/errno.h".
  
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >