Re: CSV writer question

2011-10-24 Thread Chris Angelico
On Mon, Oct 24, 2011 at 4:18 PM, Jason Swails  wrote:
> my_csv = csv.writer(open('temp.1.csv', 'wb'))
>

Have you confirmed, or can you confirm, whether or not the file gets
closed automatically when the writer gets destructed? If so, all you
need to do is:

my_csv = something_else
# or:
del my_csv

to unbind what I assume is the only reference to the csv.writer, upon
which it should promptly clean itself up.

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


Re: Books to lean Python 3 Web Programming?

2011-10-24 Thread moijes12
On Oct 23, 3:18 am, Jonathan Loescher  wrote:
> Can anyone recommend a good book to learn the web programming aspects
> of Python 3?

Hi

You can check "Dive into Python 3" by Mark Pilgrim. It does cover some
aspects of web programming. I haven't read it myself,but I've been
reading "Dive into Python".

I hope this helps.

regards
Alexander

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


Re: 回复: install lxml

2011-10-24 Thread Stefan Behnel

水静流深, 24.10.2011 07:31:

The latest version is lxml 2.3.1, released 2011-09-25,
1.download it
2.extract it  ,put  it  in  the  /home/user/Python-3.2.2/libxml2-2.7.8
3.cd   /home/user/Python-3.2.2/libxml2-2.7.8
4.   ./configure
5.make
6.sudo make  install


Not libxml2. lxml.



when i finished
~$ python3.2
Python 3.2.2 (default, Oct 24 2011, 10:33:35)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import lxml

Traceback (most recent call last):
   File "", line 1, in
ImportError: No module named lxml

there is still the problem!!


You can get a binary build for Windows from PyPI:

http://pypi.python.org/pypi/lxml/2.3

Oh, and please avoid cross-posting (and top-posting in replies).

Stefan

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


Re: shutil _isindir

2011-10-24 Thread Peter Otten
David Hoese wrote:

> I was about to submit a bug report, but while testing I have figured out
> that my specific problem has been solved in Python 2.7 (server that I
> was using had 2.6 on it).  You can see the differences here:
> 
> 2.6: http://hg.python.org/cpython/file/b9a95ce2692c/Lib/shutil.py
> 2.7: http://hg.python.org/cpython/file/d30482d51c25/Lib/shutil.py
> 
> You'll notice that in move(), there is now a check for the same file,
> which if they're not the same file you don't get unexpected deleted
> files.  If you still think I should submit a bug report let me know and
> provide me with the test case...or just submit the bug yourself.

Aren't there still problems that can be avoided with the change you propose? 
I think the bug report is worthwhile.

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


Re: Job Offer: 3 Python Backend Developer and other Positions in Berlin

2011-10-24 Thread webcrowd.net

Am 23.10.11 20:25, schrieb Waldek M.:

On Sun, 23 Oct 2011 17:50:54 +0200, webcrowd.net wrote:

hope it is okay to post job offers here. If not sorry for the spam and
please let me know!


Not really. It's a newsgroup on Python *language*, not
on Python-everything.

You might want to post here instead, though:
http://www.python.org/community/jobs/

Best regards,
Waldek


Thanks Waldek, will do so in future!
Best Regards,
Ivo
--
http://mail.python.org/mailman/listinfo/python-list


Re: logging: warn() methods and function to be deprecated.

2011-10-24 Thread Vinay Sajip
> I think that is a real shame - it seems to be gratuitous breakage for almost 

> zero benefit.  That issue shows that Trac makes heavy use of .warn, I've use 
> .warn almost exclusively for many years, and code.google.com shows it is used 
> extensively in the wild.

Okay, but it's easy enough to change, and people are getting a reasonable 
amount of time to deal with it.

> Is there still a chance to reconsider?

I'm not dogmatic about things like this; warn() is just a hangover from a long 
time ago and bit of a nit, that's all. I suppose I should have removed it when 
3.0 was released, but it went under my radar at that time.

Hence my post here, to get feedback from logging users about this proposed 
change.

Regards,

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


Re: What is wrong with my code?

2011-10-24 Thread Dave Angel
(Don't top-post.  Put your response after the part you're quoting from 
earlier messages.  And include enough that somebody can help with 
minimal effort.)


On 10/24/2011 12:30 AM, apometron wrote:

The problem is that it is not reporting any error.

The do something and quits silently.

No rename action is done and no error.

Running Python 2.7 on Windows Seven.

Your link http://pastebin.com/dExFtTkp  shows two copies of the code.  
I'm assuming they're identical, and using the second one.


How do you know no rename action is done?  Did you do a dir before and 
after running it?  Were there any files that actually had underscores in 
them?  Did you try adding a print to the innermost if statement to see 
if it ever ran?  Did you try adding a print right after the os.rename 
that showed both nome and final?


When I run it in CPython 2.7 on Linux, it successfully renamed the file 
(dumm_1.txt) I had supplied.


davea@think:~/pytests$ ls
dumm_1.txt  itpone.itp~  lina.py~pdbone.pdb~  prim.py~
itpone.itp  lina.py  pdbone.pdb  prim.py  whatswrong.py
davea@think:~/pytests$ python whatswrong.py dumm_1.txt
davea@think:~/pytests$ ls
dumm 1.txt  itpone.itp~  lina.py~pdbone.pdb~  prim.py~
itpone.itp  lina.py  pdbone.pdb  prim.py  whatswrong.py
davea@think:~/pytests$

(I had to delete the following part, since you put yours out of order)



--

DaveA

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


spawnl issues with Win 7 access rights

2011-10-24 Thread Propad
Hello everybody,
I have some trouble with a program I run both on a WinXP and on Win 7.
It boils down to this several lines:

import os
vePath = r'C:\Programme\RA Consulting_Webservices\DiagRA-MCD
\DiagRA_D.exe'
#vePath = r'C:\Windows\notepad.exe'
process_id = os.spawnl(os.P_NOWAIT, vePath)

Under Win XP they  open DiagRA just fine; under Win 7 I'm getting:
OSError: [Errno 22] Invalid argument
Needless to say, I checked the path under Win 7; it is correct.

As you can see, I tried the same lines with notepad, just in case;
same result. Works fine under XP, IOError under Win 7.

So I'm pretty sure it's some kind of Win 7 access rights issue... Can
anybody point me to a concise overview of the issues involved, and
maybe even the known solutions? Again, it's os.spawnl in Python 2.2,
under Win 7.

Thank you very much in advance.

Cheers,

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


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Tim Golden

On 24/10/2011 13:43, Propad wrote:

Hello everybody,
I have some trouble with a program I run both on a WinXP and on Win 7.
It boils down to this several lines:

import os
vePath = r'C:\Programme\RA Consulting_Webservices\DiagRA-MCD
\DiagRA_D.exe'
#vePath = r'C:\Windows\notepad.exe'
process_id = os.spawnl(os.P_NOWAIT, vePath)

Under Win XP they  open DiagRA just fine; under Win 7 I'm getting:
OSError: [Errno 22] Invalid argument
Needless to say, I checked the path under Win 7; it is correct.

As you can see, I tried the same lines with notepad, just in case;
same result. Works fine under XP, IOError under Win 7.

So I'm pretty sure it's some kind of Win 7 access rights issue... Can
anybody point me to a concise overview of the issues involved, and
maybe even the known solutions? Again, it's os.spawnl in Python 2.2,
under Win 7.


That's impressive. I ran this (on Python 2.7 on Win7):


import os

os.spawnl (os.P_NOWAIT, r"c:\windows\notepad.exe")



and Python crashed hard! Long time since I've seen that happen.

This may or may not be related to what you're seeing but it's
definitely a problem. I'll check the bugs database and/or
file a bug.

I *can* reproduce your problem running Python22 on Win7. Now,
no-one's going to be applying patches to Python 2.2 at this
stage: in the 2.x series, only 2.7 is getting anything other
than urgent security fixes. And even 2.7's only getting clear
bugfixes. Just so you know.

Without checking the code, I'm going to assume that the 2.2 codebase
is handing off to the MS C Runtime Library for posix-related calls
such as the spawn* family. So it may not even be Python's code directly
which is returning this error.


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


Python as a replacement to PL/SQL

2011-10-24 Thread Alec Taylor
Good morning,

Is there a set of libraries for python which can be used as a complete
replacement to PL/SQL?

Alternatively, is there a python library for generating PL/SQL?

(I am speaking from the context of Oracle DB, PL/Python only works
with PostgreSQL)

Thanks for all suggestions,

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


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Propad
Hello Tim,
thanx for the fast answer. Sorry to hear there are such issues.
I'm obviously not free to choose my version of Python, or I'would be
using the latest'n'greatest. It's more like this: I'm obliged to use
the version delivered with dSpace tools (which is HiL - ECU-testing
software for the automotive and aerospace industries).
I'just might be able to use 2.5, which dSpace delivered  2-3 years
ago; but I'm not sure of that, and not sure it would help in any way.
So some solution without tweaking the code or anything would be realy
nice. I can't imagine anything of such importance was not tested at
all during the beta phase - so it could be the tests were not run with
such a tricky configuration of windows.

Any hints are appreciated!

Cheers,
Nenad

On 24 Okt., 15:18, Tim Golden  wrote:
> On 24/10/2011 13:43, Propad wrote:
>
>
>
>
>
> > Hello everybody,
> > I have some trouble with a program I run both on a WinXP and on Win 7.
> > It boils down to this several lines:
>
> > import os
> > vePath = r'C:\Programme\RA Consulting_Webservices\DiagRA-MCD
> > \DiagRA_D.exe'
> > #vePath = r'C:\Windows\notepad.exe'
> > process_id = os.spawnl(os.P_NOWAIT, vePath)
>
> > Under Win XP they  open DiagRA just fine; under Win 7 I'm getting:
> > OSError: [Errno 22] Invalid argument
> > Needless to say, I checked the path under Win 7; it is correct.
>
> > As you can see, I tried the same lines with notepad, just in case;
> > same result. Works fine under XP, IOError under Win 7.
>
> > So I'm pretty sure it's some kind of Win 7 access rights issue... Can
> > anybody point me to a concise overview of the issues involved, and
> > maybe even the known solutions? Again, it's os.spawnl in Python 2.2,
> > under Win 7.
>
> That's impressive. I ran this (on Python 2.7 on Win7):
>
> 
> import os
>
> os.spawnl (os.P_NOWAIT, r"c:\windows\notepad.exe")
>
> 
>
> and Python crashed hard! Long time since I've seen that happen.
>
> This may or may not be related to what you're seeing but it's
> definitely a problem. I'll check the bugs database and/or
> file a bug.
>
> I *can* reproduce your problem running Python22 on Win7. Now,
> no-one's going to be applying patches to Python 2.2 at this
> stage: in the 2.x series, only 2.7 is getting anything other
> than urgent security fixes. And even 2.7's only getting clear
> bugfixes. Just so you know.
>
> Without checking the code, I'm going to assume that the 2.2 codebase
> is handing off to the MS C Runtime Library for posix-related calls
> such as the spawn* family. So it may not even be Python's code directly
> which is returning this error.
>
> TJG- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

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


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Tim Golden

On 24/10/2011 14:18, Tim Golden wrote:
I ran this (on Python 2.7 on Win7):



import os

os.spawnl (os.P_NOWAIT, r"c:\windows\notepad.exe")



and Python crashed hard! Long time since I've seen that happen.

This may or may not be related to what you're seeing but it's
definitely a problem. I'll check the bugs database and/or
file a bug.

I *can* reproduce your problem running Python22 on Win7. Now,
no-one's going to be applying patches to Python 2.2 at this
stage: in the 2.x series, only 2.7 is getting anything other
than urgent security fixes. And even 2.7's only getting clear
bugfixes. Just so you know.


OK; the python 2.7 issues is http://bugs.python.org/issue8036

Let's see if I can get a fix in before the next release!

Not quite sure whether the 2.2 issue is the same but it's
looking like being a W7 / CRT-related issue. I'll keep
looking

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


Re: logging: warn() methods and function to be deprecated.

2011-10-24 Thread Jean-Michel Pichavant

Vinay Sajip wrote:
I think that is a real shame - it seems to be gratuitous breakage for almost 



  
zero benefit.  That issue shows that Trac makes heavy use of .warn, I've use 
.warn almost exclusively for many years, and code.google.com shows it is used 
extensively in the wild.



Okay, but it's easy enough to change, and people are getting a reasonable 
amount of time to deal with it.

  

Is there still a chance to reconsider?



I'm not dogmatic about things like this; warn() is just a hangover from a long 
time ago and bit of a nit, that's all. I suppose I should have removed it when 
3.0 was released, but it went under my radar at that time.

Hence my post here, to get feedback from logging users about this proposed 
change.

Regards,

Vinay Sajip
  
I'm not using python 3, I'm not sure my feedback matters, but I wouldn't 
mind refactoring warn into warning If I'd have to. It's better to use 
documented API anyway.


JM

PS : I also had an issue with my logging wrappers where I did not 
implement warn, quite confusing the first time I had this error.

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


Re: logging: warn() methods and function to be deprecated.

2011-10-24 Thread Mike C. Fletcher
On 11-10-24 04:28 AM, Vinay Sajip wrote:
>> I think that is a real shame - it seems to be gratuitous breakage for almost 
>> zero benefit.  That issue shows that Trac makes heavy use of .warn, I've use 
>> .warn almost exclusively for many years, and code.google.com shows it is 
>> used 
>> extensively in the wild.
> Okay, but it's easy enough to change, and people are getting a reasonable 
> amount of time to deal with it.
I'd have to echo Mark's sentiment here.  There is a *lot* of (fairly
old) code around that uses .warn, and I'd wager even a lot of new code
written by old programmers (such as myself) that uses it.  Breaking it
to avoid having an undocumented method seems wrong; suggest just adding
documentation:

"logger.warn(...) -- an alias to logger.warning provided for
backward compatibility"

>> Is there still a chance to reconsider?
> I'm not dogmatic about things like this; warn() is just a hangover from a 
> long time ago and bit of a nit, that's all. I suppose I should have removed 
> it when 3.0 was released, but it went under my radar at that time.
>
> Hence my post here, to get feedback from logging users about this proposed 
> change.
I actually consider .warning() a nit :) .  After all, it's 3 extra
characters :) , and *who* actually reads documentation instead of just
poking around and finding the shortest-named method in the instance?

Anyway, I personally don't see this as worth the breakage.

Just my $0.02,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Python as a replacement to PL/SQL

2011-10-24 Thread Alain Ketterlin
Alec Taylor  writes:

> Is there a set of libraries for python which can be used as a complete
> replacement to PL/SQL?

This doesn't make much sense: PL/SQL lets you write server-side code,
i.e., executed by the DBMS. Oracle can't execute python code directly,
so python can only be used on the client side (I meant "client of the
DBMS"), i.e., not to write stored procedures. There is no "complete
replacement" of PL/SQL besides Java.

This page shows you how to _call_ PL/SQL procedures from a python script:

http://www.oracle.com/technetwork/articles/dsl/python-091105.html

> (I am speaking from the context of Oracle DB, PL/Python only works
> with PostgreSQL)

PL/Python is a different beast, it lets you write stored functions in
python. There is no such thing, afaik, with Oracle.

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


Re: Python as a replacement to PL/SQL

2011-10-24 Thread Alec Taylor
Hmm...

What else is there besides PL/Python (for any DB) in the context of
writing stored procedures in function?

Thanks for all suggestions,

Alec Taylor

On Tue, Oct 25, 2011 at 1:45 AM, Alain Ketterlin
 wrote:
> Alec Taylor  writes:
>
>> Is there a set of libraries for python which can be used as a complete
>> replacement to PL/SQL?
>
> This doesn't make much sense: PL/SQL lets you write server-side code,
> i.e., executed by the DBMS. Oracle can't execute python code directly,
> so python can only be used on the client side (I meant "client of the
> DBMS"), i.e., not to write stored procedures. There is no "complete
> replacement" of PL/SQL besides Java.
>
> This page shows you how to _call_ PL/SQL procedures from a python script:
>
> http://www.oracle.com/technetwork/articles/dsl/python-091105.html
>
>> (I am speaking from the context of Oracle DB, PL/Python only works
>> with PostgreSQL)
>
> PL/Python is a different beast, it lets you write stored functions in
> python. There is no such thing, afaik, with Oracle.
>
> -- Alain.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert DDL to ORM

2011-10-24 Thread Alec Taylor
Good morning,

I'm often generating DDLs from EER->Logical diagrams using tools such
as PowerDesigner and Oracle Data Modeller.

I've recently come across an ORM library (SQLalchemy), and it seems
like a quite useful abstraction.

Is there a way to convert my DDL to ORM code?

Thanks for all suggestions,

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


Re: Python as a replacement to PL/SQL

2011-10-24 Thread Martin Komoň
PostgreSQL supports PL/SQL, PL/TCL, PL/Python, PL/Perl and I've also
seen PL/Java add on module.

Martin

On 10/24/2011 4:59 PM, Alec Taylor wrote:
> Hmm...
> 
> What else is there besides PL/Python (for any DB) in the context of
> writing stored procedures in function?
> 
> Thanks for all suggestions,
> 
> Alec Taylor
> 
> On Tue, Oct 25, 2011 at 1:45 AM, Alain Ketterlin
>  wrote:
>> Alec Taylor  writes:
>>
>>> Is there a set of libraries for python which can be used as a complete
>>> replacement to PL/SQL?
>>
>> This doesn't make much sense: PL/SQL lets you write server-side code,
>> i.e., executed by the DBMS. Oracle can't execute python code directly,
>> so python can only be used on the client side (I meant "client of the
>> DBMS"), i.e., not to write stored procedures. There is no "complete
>> replacement" of PL/SQL besides Java.
>>
>> This page shows you how to _call_ PL/SQL procedures from a python script:
>>
>> http://www.oracle.com/technetwork/articles/dsl/python-091105.html
>>
>>> (I am speaking from the context of Oracle DB, PL/Python only works
>>> with PostgreSQL)
>>
>> PL/Python is a different beast, it lets you write stored functions in
>> python. There is no such thing, afaik, with Oracle.
>>
>> -- Alain.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert DDL to ORM

2011-10-24 Thread Martin Komoň
Hi,

for the project I'm working on right now I've written a simple "SQL
create script to ORM generator". I use SQLalchemy as well and this
generator takes all tables and prepares classes, maps them to tables,
introspects them and creates explicit attribute definitions in the
classes. Contact me off-list for more details.

Martin

On 10/24/2011 6:30 PM, Alec Taylor wrote:
> Good morning,
> 
> I'm often generating DDLs from EER->Logical diagrams using tools such
> as PowerDesigner and Oracle Data Modeller.
> 
> I've recently come across an ORM library (SQLalchemy), and it seems
> like a quite useful abstraction.
> 
> Is there a way to convert my DDL to ORM code?
> 
> Thanks for all suggestions,
> 
> Alec Taylor
-- 
http://mail.python.org/mailman/listinfo/python-list


randrange exceptional behavior

2011-10-24 Thread candide
Where is documented the behaviour of the standard function randrange  in 
the case of an empty list ? for instance randrange(42,33) ? May I rely 
on an ValueError type error?

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


Re: CSV writer question

2011-10-24 Thread Jason Swails
On Mon, Oct 24, 2011 at 2:08 AM, Chris Rebert  wrote:

> On Sun, Oct 23, 2011 at 10:18 PM, Jason Swails 
> wrote:
>
> > unless, of course, I add an explicit reference to track the open file
> object
> > and manually close or flush it
> > (but I'd like to avoid it if possible).
>
> Why? Especially when the performance cost is likely to be nontrivial...
>

Because if the CSV API exposed the file object, I wouldn't have to create
that extra reference, and the class that is handling this stuff already has
enough attributes without having to add a separate one for each CSV writer
it instantiates.  It's not a serious objection to creating it, just one I'd
rather not do (it's less elegant IMO, whatever that's worth).


> > Is there a way to do that directly via the CSV API,
>
> Very doubtful; csv.writer (and reader for that matter) is implemented
> in C, doesn't expose a ._file or similar attribute, and has no
> .close() or .flush() methods.
>

The machinery implemented in C, but they are wrapped in Python, and it's a
Python file object being passed to the writer, so I thought maybe there was
a 'standard' method of exposing file objects in these types of cases that I
just wasn't aware of, but it appears not.

Thanks for the info!
Jason
-- 
http://mail.python.org/mailman/listinfo/python-list


Gui Builder for Python an wxPython

2011-10-24 Thread blueeagle2
I am just getting into gui building in python and I am trying to find a
designer that is easy to use.  I tried wxGlade and though it looks promising
I could not get anywhere with it.  It would not let me create a simple
dialog application.  If I were using MonoDevelop it would be a snap, but
there does not seem to be any descent tutorials anywhere that I can find.
One would think it would be rather intuitive, but it is not or at least not
for me.  I have looked at wxFormBuilder and QT4 with python and they both
looked better.  I was just wondering what anyone else would consider a good
wxPython designer.  I would even be willing to buy one if it was not too
expensive and had descent tutorials and documentation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Importing a module from a non-cwd

2011-10-24 Thread candide

Hi,

It's easy to open a file not located in the current working directory 
(cwd). But how about importing a module?


For instance, suppose I have a file, say my_file.py, located in the cwd, 
say /home/candide/ and suppose the module to be imported, say 
my_module.py, is located in the /home/candide/foo/ directory.




How my_file.py can import the my_module.py module ?

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


Re: randrange exceptional behavior

2011-10-24 Thread MRAB

On 24/10/2011 20:26, candide wrote:

Where is documented the behaviour of the standard function randrange in
the case of an empty list ? for instance randrange(42,33) ? May I rely
on an ValueError type error?


It's the same back to at least Python 2.5, so you can probably rely on
that behaviour.

Interestingly, the documentation says:

"""This is equivalent to choice(range(start, stop, step)), but doesn’t 
actually build a range object."""


but for choice(seq) it says:

"""If seq is empty, raises IndexError."""

so it's not entirely equivalent.
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV writer question

2011-10-24 Thread Jason Swails
On Mon, Oct 24, 2011 at 3:03 AM, Chris Angelico  wrote:

> On Mon, Oct 24, 2011 at 4:18 PM, Jason Swails 
> wrote:
> > my_csv = csv.writer(open('temp.1.csv', 'wb'))
> >
>
> Have you confirmed, or can you confirm, whether or not the file gets
> closed automatically when the writer gets destructed? If so, all you
> need to do is:
>
> my_csv = something_else
> # or:
> del my_csv
>

I'm not sure why I decided against this approach in the first place.  This
does work (at least with my test), so it's what I'll do.  I probably wasn't
confident that it would clean itself up properly, but that's probably rather
un-pythonic and would not have made it into the stdlib if that was the case.

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


Re: CSV writer question

2011-10-24 Thread Andrew McLean

On 24/10/2011 08:03, Chris Angelico wrote:

On Mon, Oct 24, 2011 at 4:18 PM, Jason Swails  wrote:

my_csv = csv.writer(open('temp.1.csv', 'wb'))


Have you confirmed, or can you confirm, whether or not the file gets
closed automatically when the writer gets destructed? If so, all you
need to do is:

my_csv = something_else
# or:
del my_csv

to unbind what I assume is the only reference to the csv.writer, upon
which it should promptly clean itself up.
My understanding is that in cpython the file does get closed when the 
writer is deleted, however, it's not guaranteed to happen in other 
Python implementations (e.g. IronPython, PyPy and Jython).


Andrew

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


Re: randrange exceptional behavior

2011-10-24 Thread candide

Le 24/10/2011 22:09, MRAB a écrit :


but for choice(seq) it says:



Ah of course, I should have checked there


"""If seq is empty, raises IndexError."""

>


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


Re: Importing a module from a non-cwd

2011-10-24 Thread John Gordon
In <[email protected]> candide  
writes:

> For instance, suppose I have a file, say my_file.py, located in the cwd, 
> say /home/candide/ and suppose the module to be imported, say 
> my_module.py, is located in the /home/candide/foo/ directory.

> How my_file.py can import the my_module.py module ?

If PYTHONPATH and/or sys.path contain /home/candide/foo/, then you should
be able to:

  import my_module

Or, if foo/ is a real module (i.e. it contains an __init__.py file), this
should work:

  import foo.my_module

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


[ANN] New free multifactor analysis tool for experiment planning

2011-10-24 Thread dmitrey
Hi all,

you may be interested in new free multifactor analysis tool for
experiment planning (in physics, chemistry, biology etc). It is based
on numerical optimization solver BOBYQA, released in 2009 by Michael
J.D. Powell, and has easy and convenient GUI frontend, written in
Python + tkinter. Maybe other (alternative) engines will be available
in future.

See its webpage for details:
http://openopt.org/MultiFactorAnalysis

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


Re: CSV writer question

2011-10-24 Thread Peter Otten
Jason Swails wrote:

> Hello,
> 
> I have a question about a csv.writer instance.  I have a utility that I
> want to write a full CSV file from lots of data, but due to performance
> (and memory) considerations, there's no way I can write the data
> sequentially. Therefore, I write the data in chunks to temporary files,
> then combine them
> all at the end.  For convenience, I declare each writer instance via a
> statement like
> 
> my_csv = csv.writer(open('temp.1.csv', 'wb'))
> 
> so the open file object isn't bound to any explicit reference, and I don't
> know how to reference it inside the writer class (the documentation
> doesn't
> say, unless I've missed the obvious).  Thus, the only way I can think of
> to make sure that all of the data is written before I start copying these
> files sequentially into the final file is to unbuffer them so the above
> command is changed to
> 
> my_csv = csv.writer(open('temp.1.csv', 'wb', 0))
> 
> unless, of course, I add an explicit reference to track the open file
> object
> and manually close or flush it (but I'd like to avoid it if possible).  My
> question is 2-fold.  Is there a way to do that directly via the CSV API,
> or is the approach I'm taking the only way without binding the open file
> object
> to another reference?  Secondly, if these files are potentially very large
> (anywhere from ~1KB to 20 GB depending on the amount of data present),
> what kind of performance hit will I be looking at by disabling buffering
> on these types of files?
> 
> Tips, answers, comments, and/or suggestions are all welcome.
> 
> Thanks a lot!
> Jason
> 
> As an afterthought, I suppose I could always subclass the csv.writer class
> and add the reference I want to that, which I may do if there's no other
> convenient solution.

A contextmanager might help:

import csv
from contextlib import contextmanager

@contextmanager
def filewriter(filename):
with open(filename, "wb") as outstream:
yield csv.writer(outstream)


if __name__ == "__main__":
with filewriter("tmp.csv") as writer:
writer.writerows([
["alpha", "beta"],
["gamma", "delta"]])


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


Creating very similar functions with different parameters

2011-10-24 Thread Andrew Berg
I want to create a decorator with two different (but very similar)
versions of the wrapper function, but without copying giant chunks of
similar code. The main difference is that one version takes extra
parameters.

def test_dec(func, extra=False):
if extra:
def wrapper(ex_param1, ex_param2, *args, **kwargs):
print('bla bla')
print('more bla')
print(ex_param1)
print(ex_param2)
func(ex_param1, ex_param2, *args, **kwargs)
else:
def wrapper(*args, **kwargs):
print('bla bla')
print('more bla')
func(*args, **kwargs)
return wrapper

If the function I'm wrapping takes ex_param1 and ex_param2 as
parameters, then the decorator should print them and then execute the
function, otherwise just execute the function. I'd rather not write
separate wrappers that are mostly the same.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a replacement to PL/SQL

2011-10-24 Thread Ben Finney
Alec Taylor  writes:

> What else is there besides PL/Python (for any DB) in the context of
> writing stored procedures in function?

I know of no server-side language other than SQL which can reasonably be
expected to work “for any DB”.

PostgreSQL supports PL/pgSQL, PL/Python, PL/tcl, PL/Perl, and others
http://www.postgresql.org/docs/current/static/xplang.html>.

-- 
 \   Moriarty: “Forty thousand million billion dollars? That money |
  `\must be worth a fortune!” —The Goon Show, _The Sale of |
_o__)   Manhattan_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Terry Reedy

On 10/24/2011 10:18 AM, Tim Golden wrote:

On 24/10/2011 14:18, Tim Golden wrote:
I ran this (on Python 2.7 on Win7):



import os

os.spawnl (os.P_NOWAIT, r"c:\windows\notepad.exe")



and Python crashed hard! Long time since I've seen that happen.


Same with 3.2 and Win7, interpreter or IDLE.


OK; the python 2.7 issues is http://bugs.python.org/issue8036


The example there used P_WAIT instead of P_NOWAIT, but I added comment.

--
Terry Jan Reedy

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


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Terry Reedy

On 10/24/2011 9:47 AM, Propad wrote:
y

nice. I can't imagine anything of such importance was not tested at
all during the beta phase - so it could be the tests were not run with
such a tricky configuration of windows.


The coverage of the test suite is still being improved as people 
volunteer to write more tests. This mostly happens as part of bug fixing.


--
Terry Jan Reedy

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


Re: spawnl issues with Win 7 access rights

2011-10-24 Thread Miki Tebeka
Please use the subprocess module, it's the one who's actively maintained.
http://docs.python.org/library/subprocess.html#replacing-the-os-spawn-family
-- 
http://mail.python.org/mailman/listinfo/python-list


Stack Architecture - was "Good books in computer science?"

2011-10-24 Thread Phil Runciman
This was part of an earlier discussion in this forum.

I want to correct the impression created by Lawrence D'Oliveiro that those who 
implemented stacks were not designing for efficiency.

> What I can say is that for scientific/engineering calculations the RPN of
> KDF9 was Great because assembler was no harder than using algol60 for the
> calculations part of the problems I worked on.

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand 

  Mon Jun 22 03:52:55 CEST 2009
Unfortunately, we had to learn the hard way that machine instruction sets
must be designed for efficiency of execution, not ease of use by humans.
Stack-based architectures, for all their charm, cannot match register-based
ones in this regard.


FWIW: "Efficiency" is a slippery notion with contextual connotations.

KDF9 had two stacks in its CPU. (The SJNS and the Nesting Store or Nest - see 
Eric's thesis.)

I am not suggesting that you are ill-informed, but that stacks are 
insufficiently represented in the literature.

The use of call return stacks to support subroutine returns is almost universal.

For the evaluation of arithmetical expressions, the use of hardware stacks is 
the most efficient. From what I have read, it is compiler writers who find it 
hard to emulate the efficiencies achieved by assembler programmers. Are 
hardware designers considering the compiler writers' problems when they design 
their hardware? This would be heavy irony indeed. That is why stacks came into 
existence in the first place.

Regards,

Phil




References:
http://is.uwaterloo.ca/Eric_LaForest_Thesis.pdf  discusses the confusion of 
first and second generation stack-based architectures. It includes a rebuttal 
of the arguments against stack computers, cited by Hennessy and Patterson, 
showing that they are applicable to the first generation of stack computers, 
but not the second.

Christopher Bailey's "Optimisation Techniques for Stack-Based Processors", PhD 
thesis, University of Teesside, UK, July 1996, Amongst other things, analyzes 
the use of stack buffers to reduce memory traffic.

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


python royals @@@@@@@@@

2011-10-24 Thread n v
 http://123maza.com/48/silver424/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating very similar functions with different parameters

2011-10-24 Thread alex23
Guido wrote an article on a quick and easy multimethod implementation
using a decorator:
http://www.artima.com/weblogs/viewpost.jsp?thread=101605
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: revive a generator

2011-10-24 Thread alex23
On Oct 21, 11:46 am, Yingjie Lan  wrote:
> I am still not sure why should we enforce that 
> a generator can not be reused after an explicit 
> request to revive it?

No one is "enforcing" anything, you're simply resisting implementing
this yourself. Consider the following generator:

  import random
  def randgen():
for _ in xrange(10):
  yield random.choice(['Hi','Lo'])

  >>> [x for x in randgen()]
  ['Hi', 'Hi', 'Lo', 'Hi', 'Lo', 'Lo', 'Lo', 'Lo', 'Hi', 'Hi']

What would you expect when you reset that generator? A newly
randomised set of values, or the _same_ set of values?

What if the generator is reading from an external source, like
temperature values? Once revived, should it return the exact same
sequence it originally did, or should it retrieve new values?

Now, no matter which decision you made, why is your expectation of
behaviour the right one? Why should the generator protocol support
your convience in particular?

If you need your generator to be re-usable, make a factory that
creates it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: revive a generator

2011-10-24 Thread alex23
On Oct 21, 12:09 pm, Yingjie Lan  wrote:
> Secondly, it would be nice to automatically revive it.

Sure, it's always nice when your expectation of a language feature
exactly matches with its capabilities.

When it doesn't, you suck it up and code around it.

Because at the very least it's a hell of a lot quicker than waiting
for the language to change for you.


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


Re: Creating very similar functions with different parameters

2011-10-24 Thread Steven D'Aprano
On Mon, 24 Oct 2011 16:29:25 -0500, Andrew Berg wrote:

> I want to create a decorator with two different (but very similar)
> versions of the wrapper function, but without copying giant chunks of
> similar code. The main difference is that one version takes extra
> parameters.
> 
> def test_dec(func, extra=False):
>   if extra:
>   def wrapper(ex_param1, ex_param2, *args, **kwargs):
>   print('bla bla')
>   print('more bla')
>   print(ex_param1)
>   print(ex_param2)
>   func(ex_param1, ex_param2, *args, **kwargs)
>   else:
>   def wrapper(*args, **kwargs):
>   print('bla bla')
>   print('more bla')
>   func(*args, **kwargs)
>   return wrapper
> 
> If the function I'm wrapping takes ex_param1 and ex_param2 as
> parameters, then the decorator should print them and then execute the
> function, otherwise just execute the function. I'd rather not write
> separate wrappers that are mostly the same.

In principle you could inspect the function's calling signature using the 
inspect module, and then decide how to decorate it from that. But I 
recommend against that: it's too much like magic.

This is how I would do it:


from functools import wraps

def decorator_factory(extras=None):
"""Factory function which returns a decorator.

Usage:

@decorator_factory():  # Note you need the parentheses.
def spam(...):
return ...

@decorator_factory((extra1, extra2)):
def spam(...):
return ...

"""
# Inner function performing common functionality.
def preamble():
print('bla bla')
print('more bla')
# Decide what sort of decorator is needed.
if extras is None:
# Create decorator style 1.
def decorator(func):
@wraps(func)
def inner(*args, **kwargs):
preamble()
return func(*args, **kwargs)
return inner
else:
# Create decorator style 2.
extra1, extra2 = extras
def decorator(func):
@wraps(func)
def inner(*args, **kwargs):
preamble()
print(extra1)
print(extra2)
return func(extra1, extra2, *args, **kwargs)
return inner
return decorator



If you don't like nested functions inside nested functions, you can pull 
out the inner functions:


def preamble():
print('bla bla')
print('more bla')

def plain_decorator(func):
@wraps(func)
def inner(*args, **kwargs):
preamble()
return func(*args, **kwargs)
return inner

def extra_decorator(func):
@wraps(extra1, extra2, func)
def inner(*args, **kwargs):
preamble()
print(extra1)
print(extra2)
return func(extra1, extra2, *args, **kwargs)
return inner


def decorator_factory(plain):
if plain:
return plain_decorator
else:
return extra_decorator




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