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

2013-05-18 Thread Fábio Santos
On 17 May 2013 19:38, "Carlos Nepomuceno" 
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


Please help with Threading

2013-05-18 Thread Jurgens de Bruin
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%. 

My thread creating is based on the following : 
http://www.tutorialspoint.com/python/python_multithreading.htm

Any help would be create!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote:

> 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%.
> 
> My thread creating is based on the following :
> http://www.tutorialspoint.com/python/python_multithreading.htm
> 
> Any help would be create!!!

Can you show us the code?

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


python script is not running

2013-05-18 Thread Avnesh Shakya
hi,
i want to run python script which generating data into json fromat, I am 
using crontab, but it's not executing...
my python code--
try.py --

import json
import simplejson as json
import sys

def tryJson():
saved = sys.stdout
correctFile = file('data.json', 'a+')
sys.stdout = correctFile
result = []
i = 1
for i in range(5):
info = {
'a': i+1,
'b': i+2,
'c': i+3,
   }
result.append(info)

if result:
print json.dumps(result, indent=6)
sys.stdout = saved
correctFile.close()
tryJson()

now i m doing ion terminal-
avin@hp:~$ crontab -e
then type -
*/2 * * * * python /home/avin/data/try.py

and save

but it's not executing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to run another file inside current file?

2013-05-18 Thread fjct...@gmail.com
subprocess?



发自我的小米手机

Avnesh Shakya 编写:

>hi,
>   I want to run a another file inside a ached.add_cron_job(..). how is it 
> possible, please help me, I have a file otherFile.py for execution inside 
> current file.
>I know it is very easy question but i m unable to get anything, please help me.
>example --
>
>import otherFile
>from apscheduler.scheduler import Scheduler
>sched = Scheduler()
>sched.start()
>
>def job_function():
># Can I here add that file for execution, Or can i add that file directly 
> inside cron?
>   
>sched.add_cron_job(job_function, month='1-12', day='1-31', 
>hour='0-23',minute='44-49')
>-- 
>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 88888 Dihedral
Steven D'Aprano於 2013年5月18日星期六UTC+8下午12時01分13秒寫道:
> On Fri, 17 May 2013 21:18:15 +0300, Carlos Nepomuceno wrote:
> 
> 
> 
> > 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 %?
> 
> 
> 
> That is one of the most annoying, pernicious myths about Python, probably 
> 
> second only to "the GIL makes Python slow" (it actually makes it fast). 
> 
> 

The print function in python  is designed to print 
any printable object with a valid string representation.

The format part of the print function has to construct 
a printable string according to the format string 
and the variables passed in on the fly. 

If the acctual string to be printed in the format processing
is obtained in the high level OOP way , then it is definitely 
slow due to the high level overheads and generality requirements.





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


Re: how to run another file inside current file?

2013-05-18 Thread Kevin Xi
Hi,
It's better to specify version of python you work with. I know nothing
about python 3 but in python 2 you can do this with `exec`. Example:

> f = file('otherFile.py')
> exec f

For more, read the doc:
http://docs.python.org/2.7/reference/simple_stmts.html#the-exec-statement
HTH


   Kevin

2013/5/18 Avnesh Shakya 

> hi,
>I want to run a another file inside a ached.add_cron_job(..). how is it
> possible, please help me, I have a file otherFile.py for execution inside
> current file.
> I know it is very easy question but i m unable to get anything, please
> help me.
> example --
>
> import otherFile
> from apscheduler.scheduler import Scheduler
> sched = Scheduler()
> sched.start()
>
> def job_function():
> # Can I here add that file for execution, Or can i add that file
> directly inside cron?
>
> sched.add_cron_job(job_function, month='1-12', day='1-31',
> hour='0-23',minute='44-49')
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
让我们忠于理想,让我们面对现实。
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python script is not running

2013-05-18 Thread fjct...@gmail.com
make sure data.json is absolute path
make sure you test it directly without crontab 
in the crontab, execute the script in such way, python scripty > /tmp/log 2>&1 
check the log 



发自我的小米手机

Avnesh Shakya 编写:

>hi,
>i want to run python script which generating data into json fromat, I am 
> using crontab, but it's not executing...
>my python code--
>try.py --
>
>import json
>import simplejson as json
>import sys
>
>def tryJson():
>saved = sys.stdout
>correctFile = file('data.json', 'a+')
>sys.stdout = correctFile
>result = []
>i = 1
>for i in range(5):
>info = {
>'a': i+1,
>'b': i+2,
>'c': i+3,
>   }
>result.append(info)
>
>if result:
>print json.dumps(result, indent=6)
>sys.stdout = saved
>correctFile.close()
>tryJson()
>
>now i m doing ion terminal-
>avin@hp:~$ crontab -e
>then type -
>*/2 * * * * python /home/avin/data/try.py
>
>and save
>
>but it's not executing.
>-- 
>http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with Threading

2013-05-18 Thread Jurgens de Bruin
I will post code - the entire scripts is 1000 lines of code - can I post the 
threading functions only?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote:

> I will post code - the entire scripts is 1000 lines of code - can I post
> the threading functions only?

Try to condense it to the relevant parts, but make sure that it can be run 
by us.

As a general note, when you add new stuff to an existing longish script it 
is always a good idea to write it in such a way that you can test it 
standalone so that you can have some confidence that it will work as 
designed once you integrate it with your old code.

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


Re: Two Dictionaries and a Sum!

2013-05-18 Thread Roy Smith
In article <6012d69f-b65e-4d65-90c4-f04876853...@googlegroups.com>,
 Bradley Wright  wrote:

> Confusing subject for a confusing problem (to a novice like me of course!)
> Thx for the help in advance folks
> 
> I have (2) dictionaries:
> 
> prices = {
> "banana": 4,
> "apple": 2,
> "orange": 1.5,
> "pear": 3
> }
> 
> stock = {
> "banana": 6,
> "apple": 0,
> "orange": 32,
> "pear": 15
> }
> 
> Here's my instructions:

Hmmm, homework for a class?

> consider this as an inventory and calculate the sum (thats 4*6 = 24 bananas!)

I suspect what you're trying to say is that bananas cost BTC 4 each, and 
since you've got 6 bananas, you've got BTC 24 worth of bananas, yes?  
And now you want to find the total value of your fruit supply?

>> HERES MY CODE:
> 
> for key in prices:
> print prices[key]*stock[key]
> 
> HERES THE OUTPUT:
> 
> 48.0
> 45
> 24
> 0

So far, so good.  A couple of things you may have noticed along the way:

1) Your orange unit price was a float, so the total value of all your 
oranges is a float as well.  That's how math works in Python.

2) The keys are presented in random order.  To make the output easier to 
interpret, you might want to do:

print key, prices[key]*stock[key]


> ISSUE:
> I need to find a way to add all of those together...any pointers?

The most straight-forward way would be something like:

total = 0
for key in prices:
fruit_subtotal = prices[key]*stock[key]
total += fruit_subtotal
print key, fruit_subtotal

print total


There are better ways to do this in Python, but start like this and get 
that to work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python script is not running

2013-05-18 Thread Chris Angelico
On Sat, May 18, 2013 at 8:12 PM, Avnesh Shakya  wrote:
> avin@hp:~$ crontab -e
> then type -
> */2 * * * * python /home/avin/data/try.py
>

You may need to put an explicit path to your Python interpreter. Type:

$ which python

and put that into your crontab.

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


Re: python script is not running

2013-05-18 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Sat, May 18, 2013 at 8:12 PM, Avnesh Shakya  wrote:
> > avin@hp:~$ crontab -e
> > then type -
> > */2 * * * * python /home/avin/data/try.py
> >
> 
> You may need to put an explicit path to your Python interpreter. Type:
> 
> $ which python
> 
> and put that into your crontab.

True.  Somewhat more generally, jobs run under cron have a far more 
barren environment than most people realize.  Or, looking at it a 
different way, most people don't even realize all the ways they depend 
on their environment being set up properly by the login process.

If you've set things like PYTHONPATH, you won't have them set right for 
cron jobs unless you explicitly reset them in your crontab.

It's often instructive to run something like "env > /tmp/xxx" under 
cron, and compare that to what you get when you run "env" at a 
command-line prompt.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with Threading

2013-05-18 Thread Dave Angel

On 05/18/2013 04:58 AM, Jurgens de Bruin wrote:

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%.

My thread creating is based on the following : 
http://www.tutorialspoint.com/python/python_multithreading.htm

Any help would be create!!!



CPython, and apparently (all of?) the other current Python 
implementations, uses a GIL to prevent multi-threaded applications from 
shooting themselves in the foot.


However the practical effect of the GIL is that CPU-bound applications 
do not multi-thread efficiently;  the single-threaded version usually 
runs faster.


The place where CPython programs gain from multithreading is where each 
thread spends much of its time waiting for some external trigger.


(More specifically, if such a wait is inside well-written C code, it 
releases the GIL so other threads can get useful work done.  Example is 
a thread waiting for internet activity, and blocks inside a system call)



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


Future standard GUI library

2013-05-18 Thread Beinan Li
Not sure if this is the right place to talk about this. Even less sure if I
can
move this discussion to tkinter list, so here I am...

I know this may sound a silly question because no one can see the future.
But ...
Do you think tkinter is going to be the standard python built-in gui
solution as long as python exists?

I couldn't help but wonder if wx or PySide receives better py2 and py3
support, or anything else that prevent
them from getting into the standard python distributions, whether or not
this scene could start to shift ...

I believe this "which one of tkinter, wx, qt, is the best gui toolkit for
python" flame war has been going on
for ages. I love the fact that python ships a built-in gui solution which
makes shipping a pure-python desktop
application a viable choice. But tkinter does not appear to be the most
time-saving way to write a gui app.
The layout designer support, for one, is next to zero. I tried many
3rd-party designers
and loved PAGE (http://page.sourceforge.net) for a few minutes, then came
the author's comment:

"For release 4.0, I spent about two months working with the “Theme” part of
Ttk and have had only partial success. I now believe that the “Theme” part
of Ttk is really a very poor piece of software at all levels - concept,
implementation, and especially documentation. My guess is if it had been
well documented it would have been recognized by even the author as junk. I
find it hard to believe that the people who control Tcl/Tk allowed it in
the code base. I continue to support ttk because of the paned window,
notebook and treeview widgets."

And ttk seems to be a major attraction that keeps people coming back to tk
for the looks. This worries me very much
about whether I should start a gui app using python. Because if ttk is not
a "mature" technology, I'd avoid premature adoption.
If ttk is out of the question, tkinter will be too. I'd then be forced to
use a 3rd-party solution like wx or qt, which I really don't want to see.

Anyways, this is just some concerns that I hope someone may give his/her
opinions about.

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


Fwd: Re: python script is not running

2013-05-18 Thread Vincent Vande Vyvre




 Message original 
Sujet:  Re: python script is not running
Date :  Sat, 18 May 2013 12:36:55 +0200
De :Vincent Vande Vyvre 
Pour :  Avnesh Shakya 



Le 18/05/2013 12:12, Avnesh Shakya a écrit :

hi,
 i want to run python script which generating data into json fromat, I am 
using crontab, but it's not executing...
my python code--
try.py --

import json
import simplejson as json
import sys

def tryJson():
 saved = sys.stdout
 correctFile = file('data.json', 'a+')
 sys.stdout = correctFile
 result = []
 i = 1
 for i in range(5):
 info = {
 'a': i+1,
 'b': i+2,
 'c': i+3,
}
 result.append(info)

 if result:
 print json.dumps(result, indent=6)
 sys.stdout = saved
 correctFile.close()
tryJson()

now i m doing ion terminal-
avin@hp:~$ crontab -e
then type -
*/2 * * * * python /home/avin/data/try.py

and save

but it's not executing.

Have a look at /var/mail/yourname, this is a log created by crontab.

--
Vincent V.V.
Oqapy  . Qarte
 . PaQager 



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


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

2013-05-18 Thread Chris Angelico
On Sat, May 18, 2013 at 5:49 PM, Fábio Santos  wrote:
> 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.


Into two characters, not two lines, but yes. A file opened in text
mode on Windows will have its lines terminated with two characters.
(And it's old Macs that used to use \r. OS/2 follows the DOS
convention of \r\n, but again, many apps these days are happy with
Unix newlines there too.)

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


Re: Future standard GUI library

2013-05-18 Thread Kevin Walzer

Hello,

On 5/18/13 10:03 AM, Beinan Li wrote:


I know this may sound a silly question because no one can see the
future. But ...
Do you think tkinter is going to be the standard python built-in gui
solution as long as python exists?


I don't see any significant clamoring among the Python core developers 
to make a change.




I couldn't help but wonder if wx or PySide receives better py2 and py3
support, or anything else that prevent
them from getting into the standard python distributions, whether or not
this scene could start to shift ...


I am not going to engage in the old UI toolkit flame ware; I will limit 
myself to factual observations and a few opinions about Tkinter without 
placing it against other toolkits.


Python has the PEP process for suggesting changes to the core language 
and libraries. Changing the default UI toolkit would require someone to 
submit a proposal, get it approved, provide the implementation, and 
commit to maintaining the implementation over the long term. You propose 
it, you own it.


Thus far no one has done this. I would think the only person who would 
be in a position to propose wxPython would be Robin Dunn since he is the 
primary copyright holder, and to my knowledge he has never done so. As 
for Pyside, it was not part of the transition of Qt from Nokia to Digia, 
and so it appears to be orphaned. PyQt might be an alternative, but I 
don't think Phil Thompson would ever submit it, as it would likely 
affect his livelihood.


Given these facts, it's safe to say that Tkinter will remain the default 
GUI toolkit in the stdlib for some years to come.




I believe this "which one of tkinter, wx, qt, is the best gui toolkit
for python" flame war has been going on
for ages. I love the fact that python ships a built-in gui solution
which makes shipping a pure-python desktop
application a viable choice. But tkinter does not appear to be the most
time-saving way to write a gui app.
The layout designer support, for one, is next to zero. I tried many
3rd-party designers
and loved PAGE (http://page.sourceforge.net) for a few minutes, then
came the author's comment:


PAGE strikes me as an odd choice for a Python developer to develop a Tk 
UI. It's a descendent of the old Visual Tcl tool, and is run from Tcl 
and not Python. VTcl was always famous for producing a huge pot of 
spaghetti UI code that couldn't be easily modified outside the tool. I 
have also tried many Tk UI tools including VTcl, SpecTcl, and the 
orphaned tool from ActiveState, and have concluded that writing my own 
code is both simpler and faster. As always, your mileage may vary.




"For release 4.0, I spent about two months working with the “Theme” part
of Ttk and have had only partial success. I now believe that the “Theme”
part of Ttk is really a very poor piece of software at all levels -
concept, implementation, and especially documentation. My guess is if it
had been well documented it would have been recognized by even the
author as junk. I find it hard to believe that the people who control
Tcl/Tk allowed it in the code base. I continue to support ttk because of
the paned window, notebook and treeview widgets."


The implementation of the ttk widgets is quite complex--that, in turn, 
makes their documentation complex, and the complexity is a drawback. 
It's hard to customize the ttk themes, especially compared to 
customizing standard Tk widgets. I'm one of the core Tk developers, and 
I don't fully understand the themed widgets' internals or how to 
customize them. But it's not fair to say that they are "junk." The 
author of PAGE may think so, but many would disagree. I think the 
widgets work quite well, especially if used in their default mode. It's 
difficult to overstate the improvement in the look and feel of my Tk 
apps on the Mac when I switched to using the themed widgets.




And ttk seems to be a major attraction that keeps people coming back to
tk for the looks. This worries me very much
about whether I should start a gui app using python. Because if ttk is
not a "mature" technology, I'd avoid premature adoption.
If ttk is out of the question, tkinter will be too. I'd then be forced
to use a 3rd-party solution like wx or qt, which I really don't want to see.


ttk is a mature technology. The initial specification, code, and docs 
were developed by Joe English nearly a decade ago (see 
http://tktable.sourceforge.net/tile/tile-tcl2004.pdf), and they had been 
accepted into Tcl/Tk's core in version 8.5 (released in 2007). The 
earliest work on integrating these widgets into Python began in 2008, 
and they were formally released in 2010.  I would say that ttk is 
mature, stable, and unlikely to undergo radical change in the future.


Guilherme Polo has done superb work in integrating the themed widgets 
into Python--it's the most significant UI advance in Python's stdlib in 
years. You are quite safe in developing against this API, unless your 
taste simply does not run to using the tt

Re: python script is not running

2013-05-18 Thread Terry Jan Reedy

On 5/18/2013 6:12 AM, Avnesh Shakya wrote:

hi,
 i want to run python script which generating data into json fromat, I am 
using crontab, but it's not executing...
my python code--
try.py --

import json
import simplejson as json
import sys

def tryJson():
 saved = sys.stdout
 correctFile = file('data.json', 'a+')
 sys.stdout = correctFile


Don't need to change stdout.


 result = []
 i = 1
 for i in range(5):
 info = {
 'a': i+1,
 'b': i+2,
 'c': i+3,
}
 result.append(info)


What is you want to add print result for debugging?


 if result:
 print json.dumps(result, indent=6)


Either use print >> correctFile, correctFile.write (do you really want 
the extra '\n' that print adds?), or, do the future import of print as 
function and pass correctFile as the file argument



 sys.stdout = saved
 correctFile.close()
tryJson()



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


Re: how to run another file inside current file?

2013-05-18 Thread Terry Jan Reedy

On 5/18/2013 7:15 AM, Kevin Xi wrote:

Hi,
It's better to specify version of python you work with.


Absolutely.


 I know nothing

about python 3 but in python 2 you can do this with `exec`. Example:

 > f = file('otherFile.py')
 > exec f


Py 2 has execfile that does the above. Py 3 do as above except that exec 
is a function.


with open('otherfile.py') as f:
  exex(f)



For more, read the doc:
http://docs.python.org/2.7/reference/simple_stmts.html#the-exec-statement
HTH





--
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: python script is not running

2013-05-18 Thread woooee
The obvious question, do you have the shebang on the first line so the
OS knows it's to be run as a Python program?  Also I would change
tryJson() to
if __name__ == "__main__':
tryJson()
This probably won't make any difference but you will have the bases
covered.

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


Re: python script is not running

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 3:35 AM, woooee  wrote:
> The obvious question, do you have the shebang on the first line so the
> OS knows it's to be run as a Python program?

That won't make any difference; the cron job specifically stipulates
the interpreter. It just needs to be done with a full path.

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


SQLObject 1.4.0

2013-05-18 Thread Oleg Broytman
Hello!

I'm pleased to announce version 1.4.0, the first stable release of branch
1.4 of SQLObject.


What's new in SQLObject
===

Features & Interface


* Support for PostgreSQL 8.1 is dropped. The minimal supported version of
  PostgreSQL is 8.2 now.

* Optimization in PostgresConnection: use INSERT...RETURNING id
  to get the autoincremented id in one query instead of two
  (INSERT + SELECT id).

* Changed the way to get if the table has identity in MS SQL.

* NCHAR/NVARCHAR and N''-quoted strings for MS SQL.

Contributors for this release are Ken Lalonde and Andrew Ziem.


For a more complete list, please see the news:
http://sqlobject.org/News.html


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
https://pypi.python.org/pypi/SQLObject/1.4.0

News and changes:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python script is not running

2013-05-18 Thread Vincent Vande Vyvre

Le 18/05/2013 19:59, Chris Angelico a écrit :

On Sun, May 19, 2013 at 3:35 AM, woooee  wrote:

The obvious question, do you have the shebang on the first line so the
OS knows it's to be run as a Python program?

That won't make any difference; the cron job specifically stipulates
the interpreter. It just needs to be done with a full path.

ChrisA

Not necessary, I use crontab without problem with this line:

25 16 18 5 * export DISPLAY=:0 & LC_CTYPE="fr_FR.utf-8" 
Lang="fr_FR.utf-8" python /usr/bin/qarte -a 1


... on Ubuntu.

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Dan Stromberg
I'm getting the error in the subject, from the following code:
def add(self, key):
"""
Adds a node containing I{key} to the subtree
rooted at I{self}, returning the added node.
"""
node = self.find(key)
if not node:
node.key = key
# placeholder
node.left, node.right = self.__class__(parent=node),
self.__class__(parent=node)
return (False, node)
else:
if random.random() < 0.5:
print('node.left is %s' % node.left)
return BinaryTree.add(self=node.left, key=key)
else:
print('node.right is %s' % node.left)
return BinaryTree.add(self=node.right, key=key)

The above add() method is part of a BinaryTree(object) class, whose
subclass is RedBlackTree.

We need to explicitly call BinaryTree.add() with an explict self, to avoid
inappropriately calling RedBlackTree.add().; BinaryTree.add() is being
called with a RedBlackTree instance as self.

The debugging print and traceback look like:
node.left is  0 -1 red
Traceback (most recent call last):
  File "app_main.py", line 51, in run_toplevel
  File "test-red_black_tree_mod", line 328, in 
test()
  File "test-red_black_tree_mod", line 316, in test
all_good &= test_duplicates()
  File "test-red_black_tree_mod", line 194, in test_duplicates
tree.add(value)
  File
"/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py",
line 919, in add
(replaced, node) = super(RedBlackTree, self).add(key=key)
  File
"/home/dstromberg/src/home-svn/red-black-tree-mod/trunk/duncan/red_black_bag_mod.py",
line 376, in add
return BinaryTree.add(self=node.left, key=key)
TypeError: unbound method add() must be called with BinaryTree instance as
first argument (got nothing instead)

Why is it complaining that .add() is getting nothing, when node.left isn't
None?  As you can see above the traceback, it's got a value represented by
"node.left is  0 -1 red".

python 2.x, python 3.x and pypy all give this same error, though jython
errors out at a different point in the same method.

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


Re: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Peter Otten
Dan Stromberg wrote:

> I'm getting the error in the subject, from the following code:
> def add(self, key):
> """
> Adds a node containing I{key} to the subtree
> rooted at I{self}, returning the added node.
> """
> node = self.find(key)
> if not node:
> node.key = key
> # placeholder
> node.left, node.right = self.__class__(parent=node),
> self.__class__(parent=node)
> return (False, node)
> else:
> if random.random() < 0.5:
> print('node.left is %s' % node.left)
> return BinaryTree.add(self=node.left, key=key)
> else:
> print('node.right is %s' % node.left)
> return BinaryTree.add(self=node.right, key=key)
> 
> The above add() method is part of a BinaryTree(object) class, whose
> subclass is RedBlackTree.
> 
> We need to explicitly call BinaryTree.add() with an explict self, to avoid
> inappropriately calling RedBlackTree.add().; BinaryTree.add() is being
> called with a RedBlackTree instance as self.
> 
> The debugging print and traceback look like:
> node.left is  0 -1 red
> Traceback (most recent call last):
>   File "app_main.py", line 51, in run_toplevel
>   File "test-red_black_tree_mod", line 328, in 
> test()
>   File "test-red_black_tree_mod", line 316, in test
> all_good &= test_duplicates()
>   File "test-red_black_tree_mod", line 194, in test_duplicates
> tree.add(value)
>   File
> "/home/dstromberg/src/home-svn/red-black-tree-
mod/trunk/duncan/red_black_bag_mod.py",
> line 919, in add
> (replaced, node) = super(RedBlackTree, self).add(key=key)
>   File
> "/home/dstromberg/src/home-svn/red-black-tree-
mod/trunk/duncan/red_black_bag_mod.py",
> line 376, in add
> return BinaryTree.add(self=node.left, key=key)
> TypeError: unbound method add() must be called with BinaryTree instance as
> first argument (got nothing instead)
> 
> Why is it complaining that .add() is getting nothing, when node.left isn't
> None?  As you can see above the traceback, it's got a value represented by
> "node.left is  0 -1 red".
> 
> python 2.x, python 3.x and pypy all give this same error, though jython
> errors out at a different point in the same method.
> 
> Thanks!

I never ran into that, but apparently you cannot pass self as a keyword 
parameter:

>>> class A(object):
... def add(self): pass
... 
>>> a = A()
>>> A.add(a)
>>> A.add(self=a)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unbound method add() must be called with A instance as first 
argument (got nothing instead)


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


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

2013-05-18 Thread Dan Stromberg
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,  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


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

2013-05-18 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos
>  declaimed the following in
> gmane.comp.python.general:
> 
> 
> > 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.
> >
>   Neither... It goes back to Teletype machines where one sent a
> carriage return to move the printhead back to the left, then sent a line
> feed to advance the paper (while the head was still moving left), and in
> some cases also provided a rub-out character (a do-nothing) to add an
> additional character time delay.

The delay was important.  It took more than one character time for the 
print head to get back to the left margin.  If you kept sending 
printable characters while the print head was still flying back, they 
would get printed in the middle of the line (perhaps blurred a little).

There was also a dashpot which cushioned the head assembly when it 
reached the left margin.  Depending on how well adjusted things were 
this might take another character time or two to fully settle down.

You can still see the remnants of this in modern Unix systems:

$ stty -a
speed 9600 baud; rows 40; columns 136; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 
= M-^?; swtch = ; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon 
-ixoff -iuclc ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 
vt0 ff0
isig icanon iexten echo echoe -echok -echonl -noflsh -xcase -tostop 
-echoprt echoctl echoke

The "nl0" and "cr0" mean it's configured to insert 0 delay after 
newlines and carriage returns.  Whether setting a non-zero delay 
actually does anything useful anymore is an open question, but the 
drivers still accept the settings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Peter Otten
Dan Stromberg wrote:

> python 2.x, python 3.x and pypy all give this same error, though jython
> errors out at a different point in the same method.

By the way, 3.x doesn't have unbound methods, so that should work.

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


Re: Future standard GUI library

2013-05-18 Thread Terry Jan Reedy

On 5/18/2013 10:03 AM, Beinan Li wrote:

Not sure if this is the right place to talk about this.


It is.


Even less sure if I can
move this discussion to tkinter list,


The idea of replacing tkinter is not about improving tkinter ;-).


Do you think tkinter is going to be the standard python built-in gui
solution as long as python exists?


AT the moment, there is nothing really comparable that is a realistic 
candidate to replace tkinter. Tkinter is a tcl-based c gui library. wx 
and qt4 are gui application frameworks that include a gui library -- and 
much more that duplicate part of Python's stdlib. They, and consequently 
their Python wrappers, are too big. That is quite aside from the fact 
that the authors of the wrappers have good reason to not donate their 
code, but stay independent.


PyGui was designed as a gui library comparable to tkinter and a possible 
replacement. But according to the web page, it is still not completely 
ready for py 3 (the last update was July 2011).

http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

I think a tkinter replacement should be written for at least 3.4+, so it 
can use the new 3.3 unicode implementation and use or at least integrate 
with the new 3.4 event loop that will be part of the planned new async 
library.


One test for any new gui library is whether idle can be rewritten in it. 
It heavily uses the tag features of the tk text widget.


TJR



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


Re: TypeError: unbound method add() must be called with BinaryTree instance as first argument (got nothing instead)

2013-05-18 Thread Terry Jan Reedy

On 5/18/2013 3:46 PM, Peter Otten wrote:

Dan Stromberg wrote:


python 2.x, python 3.x and pypy all give this same error, though jython
errors out at a different point in the same method.


By the way, 3.x doesn't have unbound methods, so that should work.


It does for this example (3.3.1)
>>> c = C()
>>> c.m()
<__main__.C object at 0x033FC5F8>
>>> C.m(c)
<__main__.C object at 0x033FC5F8>
>>> C.m(self=c)
<__main__.C object at 0x033FC5F8>



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


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

2013-05-18 Thread Fábio Santos
On 18 May 2013 20:19, "Dennis Lee Bieber"  wrote:
>
> tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos
>  declaimed the following in
> gmane.comp.python.general:
>
>
> > 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.
> >
> Neither... It goes back to Teletype machines where one sent a
> carriage return to move the printhead back to the left, then sent a line
> feed to advance the paper (while the head was still moving left), and in
> some cases also provided a rub-out character (a do-nothing) to add an
> additional character time delay.
>
> TRS-80 Mod 1-4 used  for "new line", I believe Apple used 
> for "new line"... And both lost the ability to move down the page
> without also resetting the carriage to the left. In a world where both
>  is used, one could draw a vertical line of | by just spacing
> across the first line, printing |, then repeat | until done.
> To do the same with conventional  is "new line/return" one has to
> transmit all those spaces for each line...
>
> At 300baud, that took time



On Sat, May 18, 2013 at 6:00 PM, Carlos Nepomuceno
 wrote:
> 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. ;)


On Sat, May 18, 2013 at 3:29 PM, Chris Angelico  wrote:
> Into two characters, not two lines, but yes. A file opened in text
> mode on Windows will have its lines terminated with two characters.
> (And it's old Macs that used to use \r. OS/2 follows the DOS
> convention of \r\n, but again, many apps these days are happy with
> Unix newlines there too.)
>
> ChrisA

Thanks for your corrections and explanations. I stand corrected and
have learned something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-18 Thread Steven D'Aprano
On Sat, 18 May 2013 10:03:02 -0400, Beinan Li wrote:

> Do you think tkinter is going to be the standard python built-in gui
> solution as long as python exists?

Probably.

> I couldn't help but wonder if wx or PySide receives better py2 and py3
> support, or anything else that prevent them from getting into the
> standard python distributions, whether or not this scene could start to
> shift ...

One of the major issues preventing projects being added to the standard 
library is the maintenance schedule. Python's schedule for new releases 
is quite conservative and slow. If, say, wxPython was added to the std 
lib, it would have to follow Python's schedule:

* most backwards incompatible changes would be forbidden;

* those that are allowed would require a minimum of two major releases 
(three years) before removing functionality;

* about four bug-fix releases (I think?) per year.

If a project is used to (say) weekly releases, dropping down to Python's 
schedule can be rather painful.

Once something has been added to the standard library, it more or less 
has to have a stable API, become conservative about changes, and care 
more about backwards-compatibility than new features. Stability and 
consistency become paramount. Many excellent, popular packages cannot 
live under those restrictions, and so will never be part of the standard 
library.

Tkinter is good in this regard, because it is a wrapper around Tk/Tcl, 
which is equally stable and conservative as Python. Possibly even more so.



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


Re: Future standard GUI library

2013-05-18 Thread Beinan Li
Thanks for the clarification, Kevin.
It's nice to have a tk dev standing out :-)
This more or less convinced me about the trend.

I also agree that it would be probably a simpler and more maintainable way
to write my own tk(inter) code than using any existing 3rd-party designers.


Beinan

On Sat, May 18, 2013 at 1:40 PM,  wrote:

>
>
> -- Forwarded message --
> From: Kevin Walzer 
> To: python-list@python.org
> Cc:
> Date: Sat, 18 May 2013 11:32:04 -0400
> Subject: Re: Future standard GUI library
> Hello,
>
> On 5/18/13 10:03 AM, Beinan Li wrote:
>
>  I know this may sound a silly question because no one can see the
>> future. But ...
>> Do you think tkinter is going to be the standard python built-in gui
>> solution as long as python exists?
>>
>
> I don't see any significant clamoring among the Python core developers to
> make a change.
>
>
>> I couldn't help but wonder if wx or PySide receives better py2 and py3
>> support, or anything else that prevent
>> them from getting into the standard python distributions, whether or not
>> this scene could start to shift ...
>>
>
> I am not going to engage in the old UI toolkit flame ware; I will limit
> myself to factual observations and a few opinions about Tkinter without
> placing it against other toolkits.
>
> Python has the PEP process for suggesting changes to the core language and
> libraries. Changing the default UI toolkit would require someone to submit
> a proposal, get it approved, provide the implementation, and commit to
> maintaining the implementation over the long term. You propose it, you own
> it.
>
> Thus far no one has done this. I would think the only person who would be
> in a position to propose wxPython would be Robin Dunn since he is the
> primary copyright holder, and to my knowledge he has never done so. As for
> Pyside, it was not part of the transition of Qt from Nokia to Digia, and so
> it appears to be orphaned. PyQt might be an alternative, but I don't think
> Phil Thompson would ever submit it, as it would likely affect his
> livelihood.
>
> Given these facts, it's safe to say that Tkinter will remain the default
> GUI toolkit in the stdlib for some years to come.
>
>
>> I believe this "which one of tkinter, wx, qt, is the best gui toolkit
>> for python" flame war has been going on
>> for ages. I love the fact that python ships a built-in gui solution
>> which makes shipping a pure-python desktop
>> application a viable choice. But tkinter does not appear to be the most
>> time-saving way to write a gui app.
>> The layout designer support, for one, is next to zero. I tried many
>> 3rd-party designers
>> and loved PAGE (http://page.sourceforge.net) for a few minutes, then
>> came the author's comment:
>>
>
> PAGE strikes me as an odd choice for a Python developer to develop a Tk
> UI. It's a descendent of the old Visual Tcl tool, and is run from Tcl and
> not Python. VTcl was always famous for producing a huge pot of spaghetti UI
> code that couldn't be easily modified outside the tool. I have also tried
> many Tk UI tools including VTcl, SpecTcl, and the orphaned tool from
> ActiveState, and have concluded that writing my own code is both simpler
> and faster. As always, your mileage may vary.
>
>
>> "For release 4.0, I spent about two months working with the “Theme” part
>> of Ttk and have had only partial success. I now believe that the “Theme”
>> part of Ttk is really a very poor piece of software at all levels -
>> concept, implementation, and especially documentation. My guess is if it
>> had been well documented it would have been recognized by even the
>> author as junk. I find it hard to believe that the people who control
>> Tcl/Tk allowed it in the code base. I continue to support ttk because of
>> the paned window, notebook and treeview widgets."
>>
>
> The implementation of the ttk widgets is quite complex--that, in turn,
> makes their documentation complex, and the complexity is a drawback. It's
> hard to customize the ttk themes, especially compared to customizing
> standard Tk widgets. I'm one of the core Tk developers, and I don't fully
> understand the themed widgets' internals or how to customize them. But it's
> not fair to say that they are "junk." The author of PAGE may think so, but
> many would disagree. I think the widgets work quite well, especially if
> used in their default mode. It's difficult to overstate the improvement in
> the look and feel of my Tk apps on the Mac when I switched to using the
> themed widgets.
>
>
>> And ttk seems to be a major attraction that keeps people coming back to
>> tk for the looks. This worries me very much
>> about whether I should start a gui app using python. Because if ttk is
>> not a "mature" technology, I'd avoid premature adoption.
>> If ttk is out of the question, tkinter will be too. I'd then be forced
>> to use a 3rd-party solution like wx or qt, which I really don't want to
>> see.
>>
>
> ttk is a mature technology. The initial specification

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

2013-05-18 Thread Steven D'Aprano
On Sat, 18 May 2013 15:14:31 -0400, Dennis Lee Bieber wrote:

> tOn Sat, 18 May 2013 08:49:55 +0100, Fábio Santos
>  declaimed the following in
> gmane.comp.python.general:
> 
> 
>> You mentioned "\n" translating to two lines, but this won't happen.
>> Windows will not mess with what you write to your file. 

Windows certainly may mess with what you write to your file, if it is 
opened in Text mode instead of Binary mode. In text mode, Windows will:

- interpret Ctrl-Z characters as End Of File when reading;

- convert \r\n to \n when reading;

- convert \n to \r\n when writing.

http://msdn.microsoft.com/en-us/library/z5hh6ee9(v=vs.80).aspx


>> 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.
>>
>   Neither... It goes back to Teletype machines where one sent a
> carriage return to move the printhead back to the left, then sent a line
> feed to advance the paper (while the head was still moving left), and in
> some cases also provided a rub-out character (a do-nothing) to add an
> additional character time delay.

Yes, if you go back far enough, you get to teletype machines. But Windows 
inherits its text-mode behaviour from DOS, which inherits it from CP/M. 


>   TRS-80 Mod 1-4 used  for "new line", I believe Apple used 
> for "new line"... 

I can't comment about TRS, but classic Apple Macs (up to System 9) used 
carriage return \r as the line separator.



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


Re: python script is not running

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 4:43 AM, Vincent Vande Vyvre
 wrote:
> Le 18/05/2013 19:59, Chris Angelico a écrit :
>
>> On Sun, May 19, 2013 at 3:35 AM, woooee  wrote:
>>>
>>> The obvious question, do you have the shebang on the first line so the
>>> OS knows it's to be run as a Python program?
>>
>> That won't make any difference; the cron job specifically stipulates
>> the interpreter. It just needs to be done with a full path.
>>
>> ChrisA
>
> Not necessary, I use crontab without problem with this line:
>
> 25 16 18 5 * export DISPLAY=:0 & LC_CTYPE="fr_FR.utf-8" Lang="fr_FR.utf-8"
> python /usr/bin/qarte -a 1
>
> ... on Ubuntu.

Everything's configurable. I'd like to hear back from the OP though;
as Roy said, checking 'env' from a cron job will reveal much.

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


Re: Python for philosophers

2013-05-18 Thread 88888 Dihedral
Chris Angelico於 2013年5月14日星期二UTC+8上午12時24分44秒寫道:
> On Tue, May 14, 2013 at 12:53 AM, rusi  wrote:
> 
> > int fact(int n, int acc)
> 
> > {
> 
> >   return !n? acc : fact(n-1,acc*n);
> 
> > }
> 
> > -
> 
> > When I run these, the C happily keeps giving answers until a million
> 
> >
> 
> > However examined closely we find that though the C is giving answers
> 
> > its giving junk after around 12
> 
> > fact 17 is -288522240
> 
> > And 35 onwards its 0 (!!)
> 
> 
> 
> That'll depend on your integer size. If it's a 32-bit integer, you
> 
> can't store numbers greater than 2**31-1 (if you declared it as
> 
> 'unsigned int', you could go all the way to 2**32-1). I'm sure you
> 
> could write this to use the GNU Multi-Precision library, but it'd be a
> 
> lot more complicated. However, as far as I know, the Turing machine
> 
> never promises that; its cells aren't meant to be infinite integers.
> 
> 
> 
> The Python script is, of course, governed by sys.setrecursionlimit().
> 
> But by adding a simple driver, we can test the real limit:
> 
> 
> 
> import sys
> 
> 
> 
> def fact(n,acc=1):
> 
> return acc if not n else fact(n-1,n*acc)
> 
> 
> 
> n=2
> 
> while True:
> 
> sys.setrecursionlimit(n+2)
> 
> print("fact",n,"has",len(str(fact(n))),"digits")
> 
> n*=2
> 
> 
> 
> On my 64-bit system, running a recent trunk build of CPython 3.4, it
> 
> can calculate 8192! but not 16384! (segfault). The limit seems to be
> 
> 12772; after that, boom. Your crash-point will quite probably vary,
> 
> and I'd say there'll be compile-time options that would change that.
> 
> 
> 
> Of course, after playing with this in Python, I had to try out Pike.
> 
> Using the exact same code you proposed for C, but with a different
> 
> main() to save me the hassle of keying in numbers manually, I get
> 
> this:
> 
> 
> 
> fact 8192 has 28504 digits - 0.026 secs
> 
> fact 16384 has 61937 digits - 0.097 secs
> 
> fact 32768 has 133734 digits - 0.389 secs
> 
> fact 65536 has 287194 digits - 1.628 secs
> 
> fact 131072 has 613842 digits - 7.114 secs
> 
> fact 262144 has 1306594 digits - 31.291 secs
> 
> fact 524288 has 2771010 digits - 133.146 secs
> 
> 
> 
> It's still going. One core consumed, happily working on 1048576!, and
> 
> not actually using all that much memory. Hmm looks like the Pike
> 
> optimizer has turned this non-recursive. Okay, let's tweak it so it's
> 
> not tail-recursion-optimizable:
> 
> 
> 
>   return n?n*fact(n-1,1):1;
> 
> 
> 
> Now it bombs at 65536, saying:
> 
> 
> 
> Svalue stack overflow. (99624 of 10 entries on stack, needed 256
> 
> more entries)
> 
> 
> 
> Hey, it's better than a segfault, which is what C would have done :)
> 
> And it's a tweakable value, though I don't know what the consequences
> 
> are of increasing it (presumably increased RAM usage for all Pike
> 
> programs).
> 
> 
> 
> Your final conclusion is of course correct; nothing we build can be
> 
> truly infinite. But we can certainly give some very good
> 
> approximations, if we're prepared to pay for them. The reality is,
> 
> though, that we usually do not want to pay for approximations to
> 
> infinity; why is IEEE 754 floating point so much more used than, say,
> 
> arbitrary-precision rational? Most of the time, we'd rather have good
> 
> performance and adequate accuracy than abysmal performance and perfect
> 
> accuracy. But hey, if you want to render a Mandelbrot set and zoom in
> 
> to infinity, the option IS there.
> 
> 
> 
> ChrisA

Hey, ChisA, are you delibrately to write a recursive version
to demonstrate the stack depth problem in Python?

def fact(n):
   ret=1
   if n>1: # integer checking is not used but can be added
  for x in xrange(n): ret*=x
   #print ret # debugging only for long integers 
   return ret 



In a 32 or 64 bit system, this non-recursive verssion
will be limited by the heap space not by the stack limit.
-- 
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: Python for philosophers

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 9:56 AM, 8 Dihedral
 wrote:
> Hey, ChisA, are you delibrately to write a recursive version
> to demonstrate the stack depth problem in Python?
>
> def fact(n):
>ret=1
>if n>1: # integer checking is not used but can be added
>   for x in xrange(n): ret*=x
>#print ret # debugging only for long integers
>return ret
>
>
>
> In a 32 or 64 bit system, this non-recursive verssion
> will be limited by the heap space not by the stack limit.

And just when we're sure Dihedral's a bot, a post like this comes through.

Dihedral, are you intelligent? I'm still in two minds about this...
which may be why you so often appear to have no minds. I dunno.
Mathematics somewhere I fancy.

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


Re: Please help with Threading

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 10:02 AM, Carlos Nepomuceno
 wrote:
> 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?

Preemption isn't really the issue here. On the C level, preemptive vs
cooperative usually means the difference between a stalled thread
locking everyone else out and not doing so. Preemption is done at a
lower level than user code (eg the operating system or the CPU),
meaning that user code can't retain control of the CPU.

With interpreted code eg in CPython, it's easy to implement preemption
in the interpreter. I don't know how it's actually done, but one easy
implementation would be "every N bytecode instructions, context
switch". It's still done at a lower level than user code (N bytecode
instructions might all actually be a single tight loop that the
programmer didn't realize was infinite), but it's not at the OS level.

But none of that has anything to do with multiple core usage. The
problem there is that shared data structures need to be accessed
simultaneously, and in CPython, there's a Global Interpreter Lock to
simplify that; but the consequence of the GIL is that no two threads
can simultaneously execute user-level code. There have been
GIL-removal proposals at various times, but the fact remains that a
global lock makes a huge amount of sense and gives pretty good
performance across the board. There's always multiprocessing when you
need multiple CPU-bound threads; it's an explicit way to separate the
shared data (what gets transferred) from local (what doesn't).

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


mutable ints: I think I have painted myself into a corner

2013-05-18 Thread Cameron Simpson
TL;DR: I think I want to modify an int value "in place".

Yesterday I was thinking about various "flag set" objects I have
floating around which are essentially bare "object"s whose attributes
I access, for example:

  flags = object()
  flags.this = True
  flags.that = False

and then elsewhere:

  if flags.that:
do that ...

Nice and readable, but I thought to myself: so bulky!

The use case for flags is essentially boolean/binary, and so a int
accessed as a bitmask should be smaller.

So I pulled out my BitMask int subclass (which mostly transcribes
the int as "A|B|C" for readability purposes, partly to dillute Nick
Coglan's liking for bulky strings over compact ints on readability
grounds:-), and gave the subclass attribute access.

This works just fine for querying the flags object, with code exactly
like the "if" statement above.

But setting up a flags object? What I _want_ to write is code like this:

  Flags = BitMask('this', 'that')

  # set default state
  flags = Flags()
  flags.this = False
  flags.that = True
  ... iterate over some options ...: flags.this = True

and there's my problem. This would modify the int in place. There's
no way to do that. For the base type (int) this makes perfect sense,
as they're immutable.

Before I toss this approach and retreat to my former "object"
technique, does anyone see a way forward to modify an int subclass
instance in place? (That doesn't break math, preferably; I don't
do arithmetic with these things but they are, after all, ints...)

Cheers,
-- 
Cameron Simpson 

Why does "philosophy of consciousness/nature of reality" seem to interest you
so much?  Take away consciousness and reality and there's not much left.
- Greg Egan, interview in Eidolon 15
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mutable ints: I think I have painted myself into a corner

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 10:26 AM, Cameron Simpson  wrote:
> Before I toss this approach and retreat to my former "object"
> technique, does anyone see a way forward to modify an int subclass
> instance in place? (That doesn't break math, preferably; I don't
> do arithmetic with these things but they are, after all, ints...)
>

Why is it an int subclass? Because there are places where you want to
use it as though it were an int? It might be easier to render those,
instead, eg by creating a __int__ method. (Or is it "an __int__
method"? Not sure.)

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


Re: mutable ints: I think I have painted myself into a corner

2013-05-18 Thread Cameron Simpson
On 19May2013 11:11, Chris Angelico  wrote:
| On Sun, May 19, 2013 at 10:26 AM, Cameron Simpson  wrote:
| > Before I toss this approach and retreat to my former "object"
| > technique, does anyone see a way forward to modify an int subclass
| > instance in place? (That doesn't break math, preferably; I don't
| > do arithmetic with these things but they are, after all, ints...)
| 
| Why is it an int subclass? Because there are places where you want to
| use it as though it were an int? It might be easier to render those,
| instead, eg by creating a __int__ method. (Or is it "an __int__
| method"? Not sure.)

I don't want to use it as an int, on the outside. I want to use an
int on the inside as the implementation.

It's an int _subclass_ so that it is no bigger than an int. Otherwise
I may as well just make an ordinary object and be back where I
started.  Bulky:-(

The reason it is an _int_ subclass, versus something else, is that
a bitmap is a type of int. So the functional mapping is direct.

I _do_ _not_ want to operate on it from the outside as an int (doing
overt addition, for example, though I can imagine doing bitwise
activities); I want to operate on in _internally_ as a int to decide
what names-by-an-attribute flags are on or off.

So an object with an __int__() method is right out; it's the wrong
interface because it would mean an int() call (possibly implicit)
in exterior code.

Cheers,
-- 
Cameron Simpson 

Hoping to shave precious seconds off the time it would take me to get
through the checkout process and on my way home, I opted for the express
line ("9 Items Or Less [sic]"  Why nine items?  Where do they come up with
these rules, anyway?  It's the same way at most stores -- always some
oddball number like that, instead of a more understandable multiple of
five.  Like "five.")
- Geoff Miller, geo...@purplehaze.corp.sun.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for philosophers

2013-05-18 Thread 88888 Dihedral
Chris Angelico於 2013年5月19日星期日UTC+8上午8時04分45秒寫道:
> On Sun, May 19, 2013 at 9:56 AM, 8 Dihedral
> 
>  wrote:
> 
> > Hey, ChisA, are you delibrately to write a recursive version
> 
> > to demonstrate the stack depth problem in Python?
> 
> >
> 
> > def fact(n):
> 
> >ret=1
> 
> >if n>1: # integer checking is not used but can be added
> 
> >   for x in xrange(n): ret*=x
> 
> >#print ret # debugging only for long integers
> 
> >return ret
> 
> >
> 
> >
> 
> >
> 
> > In a 32 or 64 bit system, this non-recursive verssion
> 
> > will be limited by the heap space not by the stack limit.
> 
> 
> 
> And just when we're sure Dihedral's a bot, a post like this comes through.
> 
> 
> 
> Dihedral, are you intelligent? I'm still in two minds about this...
> 
> which may be why you so often appear to have no minds. I dunno.
> 
> Mathematics somewhere I fancy.
> 
> 
> 
> ChrisA

I am too lazy to write a factorial computations with primes
here.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-05-18 Thread Dave Angel

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.




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


Re: Future standard GUI library

2013-05-18 Thread llanitedave
I'm curious about how commonly tkinter is actually used among Python app 
developers as compared to wx, Pyside, or PyQT.  I get the impression that more 
distributed apps are built with wxPython, at least, than tkinter.  My 
impression is far from actual knowledge, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help with Threading

2013-05-18 Thread Cameron Simpson
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.

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.

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: 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: Python for philosophers

2013-05-18 Thread Michael Torrie
On 05/18/2013 08:30 PM, 8 Dihedral wrote:
> I am too lazy to write a factorial computations with primes
> here.

Ahh, that's better.
-- 
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: any cherypy powred sites I can check out?

2013-05-18 Thread Chris Angelico
On Fri, May 17, 2013 at 10:09 AM, alex23  wrote:
> On May 17, 10:00 am, visphatesj...@gmail.com wrote:
>> is a cherrypy list accessible here on web thru google groups?
>
> Is an apology for your offensive response to Chris Angelico
> forthcoming?

In complete absence of all semblance of context, I do not see the
profane post as addressing me personally. But in lieu of an apology,
I'd settle for a little more content in the posts or some evidence
that he's read ESR Question. You know what, I'd settle for the latter
in lieu of pretty much anything.

I still think we should use that as a penance. Go and say three Our
Fathers, do a Stations of the Cross, and read esr's article on smart
questions. You are forgiven, my son.

ChrisA

(Caveat: I am not a Catholic, so I haven't much of a clue as to how
confession usually goes.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Fwd: Fwd: Fwd: Python for philosophers

2013-05-18 Thread Citizen Kant
rusi said:

> And let me suggest that you follow your own advise -- Can you say what
> you have to say in 1/10th the number of words? Ok if not 1/10th then
> 1/5th? 1-third?

Thanks for the suggestion. I apologize for being that expansive; maybe you
are right about this. In my world less use to be less. I'll try to review
my doubts in order to express them in a much more concise format.

Of course this is not trolling at all, and I'm intrigued by how fast
someone can fall into that kind of conclusions...

I'm pretty much interested in the topic, so I'll review the stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any cherypy powred sites I can check out?

2013-05-18 Thread Chris Angelico
On Sat, May 18, 2013 at 3:15 AM, Mark Lawrence  wrote:
> On 17/05/2013 01:00, visphatesj...@gmail.com wrote:
>>
>> fuck straight off
>>
>
> I assume you're the author of "How to win friends and influence people"?

Not quite. He's the author of the social networking version, "How to
win influence and friend people".

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