Re: What text editor is everyone using for Python

2009-05-26 Thread Ben Finney
Lacrima  writes:

> I am new to python.
> And now I am using trial version of Wing IDE.
> But nobody mentioned it as a favourite editor.
> So should I buy it when trial is expired or there are better choices?

I think your time will be better spent learning a powerful, mature,
well-supported, free-software, programmable editor with support for an
enormous range of text processing tasks.

Either of Vim or Emacs qualify. Language-specific IDEs do not.

-- 
 \ “Ladies are requested not to have children in the bar.” |
  `\  —cocktail lounge, Norway |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Ben Finney
Steven D'Aprano  writes:

> nano is basically an updated (forked?) version of pico.

Re-implemented http://www.nano-editor.org/dist/v1.2/faq.html#6>.
Pico was under a non-free license, so Nano was written to be a
feature-compatible free-software clone.

-- 
 \ “If you ever catch on fire, try to avoid seeing yourself in the |
  `\mirror, because I bet that's what REALLY throws you into a |
_o__) panic.” —Jack Handey |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Paul Rudin
Lawrence D'Oliveiro  writes:

> In message , Jean-Michel 
> Pichavant wrote:
>
>> Why buy an IDE when you just need a text editor ?
>
> Because all the cool kids have one. If you want to be different and 
> individual like them, you have to have what they have.

Of course it's not always clear what the difference is in any
case. Emacs, for example, has most of the features of many IDEs (not to
mention many features that they lack).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-26 Thread Lawrence D'Oliveiro
In message , Roy Smith wrote:

> In article ,
>  Lawrence D'Oliveiro  wrote:
> 
>> In message , Roy Smith wrote:
>> 
>> > In article ,
>> >  Lawrence D'Oliveiro  wrote:
>> > 
>> >> The right thing to do is try to ensure that all your connections are
>> >> properly closed at shutdown. That may not be enough (if your server
>> >> crashes due to bugs), so the other thing you need to do is retry the
>> >> socket open, say, at 30-second intervals, until it succeeds.
>> > 
>> > That may be a reasonable thing to do for production code, but when
>> > you're building and debugging a server, it's a real pain to not be able
>> > to restart it quickly whenever you want (or need) to.
>> 
>> On the contrary, I run exactly the same logic--and that includes socket-
>> handling logic--in both test and production servers. How else can I be
>> sure it'll work properly in production?
> 
> I was just pointing out how it can be useful in cases such as the OP's,
> where he's getting bind errors when he restarts his server.

And I was pointing out how important it was to make sure your code deals 
gracefully with those errors.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Lawrence D'Oliveiro
In message , Teguh 
Iskanto wrote:

> Have you tried vim ? it has got tons of tons of features ...

So has everything else these days.

> for example: you're working in the office and connected to your remote
> CVS server ...

Wouldn't it be easier to use a distributed VCS?

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Teguh Iskanto
Have you tried vim ? it has got tons of tons of features, like ( just
to name a few)  : file manager, color syntax, tab screen,
command/syntax completion (cache only) , vertical split, horizontal
split, colorful diffing, create a patch, etc .. you name it  !! .
There's also plugins / script that people share @
http://www.vim.org/scripts/index.php. Also Vim comes in Windows/Unix
version :)

IMO, you don't even need an IDE, if you combined vim + "screen" ( man
screen ) as both are really powerful tools
for example: you're working in the office and connected to your remote
CVS server, with "screen" you can lock the screen with password &
detach it. once you're @ home and want to continue to work , you just
need to log in to that cvs server again and do "screen -r" and voila
your session is still there :)

BTW: "screen" does split screen too :)

HTH




On Wed, May 27, 2009 at 2:56 PM, Ankit  wrote:
> On May 26, 6:04 pm, J Kenneth King  wrote:
>> Lacrima  writes:
>> > I am new to python.
>> > And now I am using trial version of Wing IDE.
>> > But nobody mentioned it as a favourite editor.
>> > So should I buy it when trial is expired or there are better choices?
>>
>
> I will suggest u to use TEXTPAD 4 on windows and
> Emacs or Vi or RocketEdit on your Linux machine
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Jaime Fernandez del Rio
On Tue, May 26, 2009 at 8:42 PM, Sumitava Mukherjee
 wrote:
> On May 26, 11:39 pm, Sumitava Mukherjee  wrote:
>
> [Oh, I forgot to mention. I am looking for sampling without replacement.]

That means that, you'll have to code something that updates the sums
of probabilities after each extraction...

Would there be a smart way of doing this, of just adding the whole
updated list again is the best, or at least good enough?

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Ankit
On May 26, 6:04 pm, J Kenneth King  wrote:
> Lacrima  writes:
> > I am new to python.
> > And now I am using trial version of Wing IDE.
> > But nobody mentioned it as a favourite editor.
> > So should I buy it when trial is expired or there are better choices?
>

I will suggest u to use TEXTPAD 4 on windows and
Emacs or Vi or RocketEdit on your Linux machine

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


Re: 4 hundred quadrillonth?

2009-05-26 Thread Steven D'Aprano
On Wed, 27 May 2009 11:33:51 +1200, Lawrence D'Oliveiro wrote:

> Chaitin is trying to use only computable numbers. Pi is computable, as
> is e, sqrt(2), the Feigenbaum constant, and many others familiar to us
> all.
> 
> Trouble is, they only make up 0% of the reals. It's the other 100% he
> wants to get rid of.


+1 QOTD


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


Re: What text editor is everyone using for Python

2009-05-26 Thread John Yeung
On May 26, 9:43 am, Mel  wrote:

>  SciTE
> I like one big uncomplicated window, tabbed file panes,
> syntax coloring and help with indentation.  There's
> nothing to it I hate.  It would be nice if
> customization were easier.

This is a decent summary of SciTE, but I kind of marvel at how few
people complain about its Python indentation.  (I'd like to think it's
because anyone who edits Python code in SciTE has downloaded my patch,
but I am confident that is not the case.)

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Lawrence D'Oliveiro
In message , Roy Smith wrote:

> The real problem is when you get dumped into some editor other than you
> one you expected and don't realize it for a while.  It's really amazing
> how much damage you can do to a file by typing (for example) emacs
> commands at vi.

Doesn't work the other way round, though. All you'll likely succeed in doing 
is putting the vi commands into the file.

This, ladies and gentlemen of the jury, points up the essential difference 
between a modal and a non-modal way of doing things.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Lawrence D'Oliveiro
In message , Jean-Michel 
Pichavant wrote:

> Why buy an IDE when you just need a text editor ?

Because all the cool kids have one. If you want to be different and 
individual like them, you have to have what they have.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Lawrence D'Oliveiro
In message , Arnaud Delobelle wrote:

> That's why I use ed.

After 20 years of suffering with vi, I finally decided to switch to Emacs. 
Yes, it has lots of fancy features and "modes" and things, but it wasn't 
hard to figure out how to turn the intrusive stuff off, and still leave a 
very powerful and useful editor.

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


Re: How does Python's OOP feel?

2009-05-26 Thread Teguh Iskanto
Ikon wrote:
>I'm rather new to Python. I have PHP for my main language and I do
>some Java. They all have a very strict OO schema. As I red through
>Python's tutorial it seams it has nothing of those rules. No statical,
>abstract classes, functions, or variables.
>
>I wish someone, who has experience in both Java/PHP/C# and Python
>would tell me how mush better/worse is it to program in a language
>that misses most of the OO parts!
>

Here's a view from a seasonal programmer :

My day job is mostly doing some networking/security stuffs,
I only do programmings only if I had to (like creating
tools/automation/etc) or if no one in my network team was able/didn't
want to do it :(
Just a couple months back we had an engineering issue and we needed to
create/design a robust broker system that works in a background.
This system would take orders from different systems in a form of XML
and should be able to 'talk' to cluster firewalls (range in hundreds
of firewalls) and should be able to add/remove/check/verify/edit
objects on the individual firewall.

Knowing the complexity of the problem and the time constraint that we
had (my manager gave me 2.5 months to get this thing to work) , I had
no other resolution other than turning my self into python. At first I
was a bit doubtful but I kept moving on esp knowing that running a big
and complex project with perl would be like 'digging my own graveyard'
(especially in terms of modularity & maintenance ).

As it turned out, I enjoyed doing big projects with python especially
with its OOP style : simple & really easy --without having to go into
too much OOP details or bogged down with OOP theory-- it just works !
and  it's as easy as if you're running a 'plug & play' module and
playing LEGO. Long story short, I was able to present the whole system
in time and the system is now being used in production for a mission
critical F/W deployment ( I've used pyexpect,XML and Threading to
speed up the process )

The good thing about python is : it 'tastes' like what it was being
advertised (eg: Makes things easy and makes complex problem possible )
and I agree 100% with that. If a seasonal programmer like me find it
easy, then it should be much easier for you.

BTW: Before this project, I've programmed in C/PHP/Perl/Tcl but never
had a chance to really try Python in a full-blown OOP complex project.
HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to ask smart questions question

2009-05-26 Thread Martin P. Hellwig

Martin P. Hellwig wrote:


I can do a quick one albeit without citation:

- Have you googled/searched?
- No really, have you?
- Are you really, really sure?

- So what did you 'search for|tried before' which didn't returned a 
result you can work with?

- What does that tell you about yourself?
- So what do _you_ think _you_ should do first to solve _your_ problem?

- Okay, fair enough, tell me your problem, give me some background, give 
me some examples, skip the waffling, be polite I am here out of my own 
good will.


A: See you haven't searched properly | Hmm intriguing | Seems like a 
bug, contact the author




Oh I forgot:
- Be complete, don't forget essential things
- Write simple sentences, I don't want to guess the meaning of your epistle
- Use a spell checker
- It doesn't hurt to reread before hitting the send button

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Roy Smith
In article ,
 "Rhodri James"  wrote:

> On Tue, 26 May 2009 14:22:29 +0100, Roy Smith  wrote:
> 
> > My pet peeve is syntax-aware editors which get things wrong.  For  
> > example,
> > the version of emacs I'm using now doesn't parse this properly:
> >
> > '''A triple-quoted string.  Some editors won't get this right'''
> >
> > The solution is to change the outer quotes to double-quotes, but it  
> > annoys me when I have to change my code to appease a tool.
> 
> It's the separate python-mode that gets this (and much else) wrong.
> The Python mode that Ubuntu packages with emacs 22.2.1 works just
> fine.

Cool.  I'll see if I can snarf that and use it instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to ask smart questions question

2009-05-26 Thread Martin P. Hellwig

Carl Banks wrote:

On May 26, 7:48 am, Gary Herron  wrote:

John wrote:

I'm okay with init, but it seems to me that enter is redundant since
it appears that anything you want to execute in enter can be done in
init.

The proper response to a question like this has to be
   http://www.catb.org/~esr/faqs/smart-questions.html
as anything else is complete guesswork.


Is there a Cliff's Notes version of this?

I may be a cynic but I would think the people who ask bad questions
are the same sort of people who won't have the patience to sit though
this behemoth of an essay.

And I may be a romantic but I would think most people who post this
are really trying to be helpful and not just saying, "Out of my midst,
vile newbie, until thou hearkenst unto the sacred words".

So, it would seem that a summary (with citations) of the essay would
be useful.


Carl Banks


I can do a quick one albeit without citation:

- Have you googled/searched?
- No really, have you?
- Are you really, really sure?

- So what did you 'search for|tried before' which didn't returned a 
result you can work with?

- What does that tell you about yourself?
- So what do _you_ think _you_ should do first to solve _your_ problem?

- Okay, fair enough, tell me your problem, give me some background, give 
me some examples, skip the waffling, be polite I am here out of my own 
good will.


A: See you haven't searched properly | Hmm intriguing | Seems like a 
bug, contact the author


--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


How to ask smart questions question

2009-05-26 Thread Carl Banks
On May 26, 7:48 am, Gary Herron  wrote:
> John wrote:
> > I'm okay with init, but it seems to me that enter is redundant since
> > it appears that anything you want to execute in enter can be done in
> > init.
>
> The proper response to a question like this has to be
>    http://www.catb.org/~esr/faqs/smart-questions.html
> as anything else is complete guesswork.

Is there a Cliff's Notes version of this?

I may be a cynic but I would think the people who ask bad questions
are the same sort of people who won't have the patience to sit though
this behemoth of an essay.

And I may be a romantic but I would think most people who post this
are really trying to be helpful and not just saying, "Out of my midst,
vile newbie, until thou hearkenst unto the sacred words".

So, it would seem that a summary (with citations) of the essay would
be useful.


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


Re: What text editor is everyone using for Python

2009-05-26 Thread Rhodri James

On Tue, 26 May 2009 14:22:29 +0100, Roy Smith  wrote:

My pet peeve is syntax-aware editors which get things wrong.  For  
example,

the version of emacs I'm using now doesn't parse this properly:

'''A triple-quoted string.  Some editors won't get this right'''

The solution is to change the outer quotes to double-quotes, but it  
annoys me when I have to change my code to appease a tool.


It's the separate python-mode that gets this (and much else) wrong.
The Python mode that Ubuntu packages with emacs 22.2.1 works just
fine.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Roy Smith
In article ,
 Bar Shirtcliff  wrote:

> I can't say a thing about other editors, except that when some shell
> script perversely dumped me into vi a month ago, I felt as horrified
> as if some actually living bugs had crawled out of my own reflection
> on the computer screen and fallen, clicking and scraping, onto the
> keyboard.  That's a personal reaction - totally irrelevant, of course.

 : q ! 

All the vi you ever need to know :-)

The real problem is when you get dumped into some editor other than you one 
you expected and don't realize it for a while.  It's really amazing how 
much damage you can do to a file by typing (for example) emacs commands at 
vi.  Especially if you accidentally stumble upon the sequence for "save 
file".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Roy Smith
In article ,
 Arnaud Delobelle  wrote:

> That's why I use ed.  Ed is the standard text editor [1].  Ed is open
> source [2].

I still use ed sometimes.  If I'm on a box which doesn't have emacs 
installed (or using something whose terminal emulation is totally broken), 
it lets me get work done.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 hundred quadrillonth?

2009-05-26 Thread Lawrence D'Oliveiro
In message , Steven 
D'Aprano wrote:

> On Sun, 24 May 2009 22:47:51 +1200, Lawrence D'Oliveiro
>  declaimed the following in
> gmane.comp.python.general:
> 
>> .. Gregory Chaitin among others has been trying to rework physics to get
>> rid of real numbers altogether.
> 
> (1/2) If you "get rid of real numbers", then obviously you must have a
> smaller set of numbers, not a larger.

Chaitin is trying to use only computable numbers. Pi is computable, as is e, 
sqrt(2), the Feigenbaum constant, and many others familiar to us all.

Trouble is, they only make up 0% of the reals. It's the other 100% he wants 
to get rid of.

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


Re: any lib to extract pages form pdf and then merge?

2009-05-26 Thread David Boddie
On Tuesday 26 May 2009 06:47, oyster wrote:

> I want to extract some pages from vary pdf files, then write them
> with/witout rotation into one new pdf file. something likes this

[...]

> I have tried pypdf, but it errs and exits on some of my pdfs(no, the
> files have no password)

Maybe you could get in touch with the author to try and work around these
problems.

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


RE: What text editor is everyone using for Python

2009-05-26 Thread Benjamin J. Racine
I use Textmate (with vim keybindings) on OS X or just vim on the others OS's.

I still can't decide on which IDE between Wing, PyDev and Netbeans.

Ben Racine



 

-Original Message-
From: python-list-bounces+bjracine=glosten@python.org 
[mailto:python-list-bounces+bjracine=glosten@python.org] On Behalf Of Dave 
Angel
Sent: Tuesday, May 26, 2009 2:36 PM
Cc: python-list@python.org; Lacrima
Subject: Re: What text editor is everyone using for Python

Lacrima wrote:
>> I am new to python.
>> And now I am using trial version of Wing IDE.
>> But nobody mentioned it as a favourite editor.
>> So should I buy it when trial is expired or there are better choices?
>
I'm a little surprised nobody has explicitly mentioned Komodo IDE (the full 
version).  Although it's not free, it has plenty of useful features, is very 
configurable, supports Python and a host of other languages, and is a full IDE 
with an out-of-process debugger.  This means you can step through GUI code, 
without it interfering with the debugger's event loop.

You can customize it in four ways:
  1) through Edit->Preferences
  2) through recorded macros
  3) through macros written in Javascript
  4) through macros written in Python


A subset of Komodo IDE is available as Komodo Edit, which is open source.

Apparently Komodo is developed from some of the same code base as Firefox, so 
they can be integrated more tightly when debugging internet stuff.  I haven't 
tried anything of the sort, so  I can't say how well this works, and for what.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Dave Angel

Lacrima wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?


I'm a little surprised nobody has explicitly mentioned Komodo IDE (the 
full version).  Although it's not free, it has plenty of useful 
features, is very configurable, supports Python and a host of other 
languages, and is a full IDE with an out-of-process debugger.  This 
means you can step through GUI code, without it interfering with the 
debugger's event loop.


You can customize it in four ways:
 1) through Edit->Preferences
 2) through recorded macros
 3) through macros written in Javascript
 4) through macros written in Python


A subset of Komodo IDE is available as Komodo Edit, which is open source.

Apparently Komodo is developed from some of the same code base as 
Firefox, so they can be integrated more tightly when debugging internet 
stuff.  I haven't tried anything of the sort, so

I can't say how well this works, and for what.

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


Re: Passing string from python programs to external programs

2009-05-26 Thread psykeedelik
On May 26, 9:16 pm, Jeff McNeil  wrote:
> On May 26, 2:12 pm, lone_eagle  wrote:
>
> > Hi all,
>
> > On Linux, I do something like this
>
> > $ program_to_execute < input_file
> > ... get some output ...
>
> > I have the content of the input_file as a string inside a python
> > program and would like to pass this string to the external program
> > from inside the python program and get back the programs output in a
> > string/file. Can someone tell me how to achieve this. I have been
> > through the documentation for Popen, but this one beats me.
>
> > Cheers,
> > Chaitanya
>
> Sounds like subprocess is what you want.  Here's a quick ad-hoc
> example. You can find more information on the module 
> athttp://docs.python.org/library/subprocess.html.
>
> [GCC 4.3.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import subprocess
> >>> sub = subprocess.Popen('/bin/gzip', stdin=subprocess.PIPE, 
> >>> stdout=subprocess.PIPE)
> >>> g = sub.communicate('Please, sir, gzip me?')
> >>> import gzip
> >>> import StringIO
> >>> gzip.GzipFile(fileobj=StringIO.StringIO(g[0])).read()
>
> 'Please, sir, gzip me?'
>
>
>
> Thanks,
>
> Jeff
> mcjeff.blogspot.com

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


Re: multiprocessing / forking memory usage

2009-05-26 Thread Piet van Oostrum
> Randall Smith  (RS) wrote:

>RS> I'm trying to get a grasp on how memory usage is affected when forking as
>RS> the multiprocessing module does.  I've got a program with a parent process
>RS> using wx and other memory intensive modules. It spawns child processes (by
>RS> forking) that should be very lean (no wx required, etc). Based on
>RS> inspection using "ps v" and psutil, the memory usage (rss) is much higher
>RS> than I would expect for the subprocess.

The child is a clone of the parent. So both its virtual memory usage and
its resident memory usage will be equal to the parent's ones immediately
after the fork(). But the actual physical memory has only one copy
resident, although ps will show it on both processes (at least I think
that's how ps works). Of course later they will diverge.

>RS> My understanding is that COW is used when forking (on Linux).  

I think this is true of all modern Unix systems.

>RS> So maybe "ps v pid" is reflecting that. If that's the case, is
>RS> there a way to better determine the child's memory usage?
 
Define `memory usage' in the light of the above.

As long as the parent is still around and you don't run out of virtual
memory in the child, not much harm is done.

If the parent stops and you don't run out of virtual memory in the
child, the excessive pages will eventually be paged out, and then no
longer occupy physical memory. As long as you have enough swap space it
shouldn't be a big problem. The extra paging activity is a bit of a
loss, however.

If you run out of virtual memory in the child you have a problem, however.

>RS> If it's not the case and I'm using
>RS> modules I don't need, how can I reduce the memory usage to what the child
>RS> actually uses instead of including everything the parent is using?

The best would be to fork the child before you import the excess modules
in the parent. If that is not possible you could try to delete as much
in the child as you can, for example by
del wx; del sys.modules['wx'] etc, delete all variables that you don't
need, and hope the garbage collector will clean up enough. But it will
make you application quite complicated. From the python level you can't
get rid of loaded shared libraries, however. And trying to do that from
the C level is probably close to committing suicide.

My advise: don't worry until you really experience memory problems.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


distutils extension configuration problem

2009-05-26 Thread Ron Garret
I'm trying to build PyObjC on an Intel Mac running OS X 10.5.7.  The 
build is breaking because distutils seems to want to build extension 
modules as universal binaries, but some of the libraries it depends on 
are built for intel-only, i.e.:

[...@mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ python2.6 
setup.py build
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils
/dist.py:266: UserWarning: Unknown distribution option: 'options'
  warnings.warn(msg)
running build
running build_py
running build_ext
building 'ScreenSaver._inlines' extension
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g 
-bundle -undefined dynamic_lookup 
build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o -o 
build/lib.macosx-10.3-i386-2.6/ScreenSaver/_inlines.so -framework 
ScreenSaver
ld: in /Developer/SDKs/MacOSX10.4u.sdk/usr/local/lib/libTIFF.dylib, file 
is not of required architecture for architecture ppc
collect2: ld returned 1 exit status
lipo: can't open input file: 
/var/folders/nT/nTiypn-v2RatkU+BYncrKU+++TI/-Tmp-//ccMFYRkt.out (No such 
file or directory)
error: command 'gcc' failed with exit status 1

[...@mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file 
build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o 
build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o: Mach-O 
universal binary with 2 architectures
build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for 
architecture ppc): Mach-O object ppc
build/temp.macosx-10.3-i386-2.6/Modules/_ScreenSaver_inlines.o (for 
architecture i386):   Mach-O object i386

[...@mickey:~/Desktop/pyobjc-framework-ScreenSaver-2.2b2]$ file 
/usr/local/lib/libtiff.dylib 
/usr/local/lib/libtiff.dylib: Mach-O dynamically linked shared library 
i386

How do I get distutils to stop trying to build extensions as universal 
binaries?

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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Dave Angel

Sumitava Mukherjee wrote:

Hi all,
I need to randomly sample from a list where all choices have weights
attached to them. The probability of them being choosen is dependent
on the weights.
If say Sample list of choices are [A,B,C,D,E] and weights of the same
are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
want the likeliness of them being chosen be in the order : D>A>C>E>B

In short I mean if prob of a H is .9 and probability of T be 0.1 then
if I draw 10 samples, 9 should be H and 1 should be T.

I coudn't find a function in the module random that does so.
Please can someone guide me how the above could be implemented [either
through some function which exists and I don't know or pointers to
some code snippets which does so]?

  
Emile gave you a pretty elegant solution, assuming two things:  The 
choices can be represented by a single character each, and a roundoff 
error of one part in a thousand is acceptable.


Of course, you can represent 256 choices in a 2.x character, and you 
could switch to Unicode if that's not enough.  And if 1000 isn't enough, 
you could make it bigger, at the cost of needing a bigger table.


Here's my more-straightforward algorithm, not reduced to code.

Start with a list of probabilities.  Replace each item with the sum of 
all the items up to and including itself.  (If you do it in-place, you'd 
need to do it in reverse order, but if you use a copy, you could simply 
replace each item with a sum() of the appropriate slice of the copy.



Anyway, now you've got a list of cumulative probabilites, with the last 
item equalling 1.0 (pretty close).  You might need to fudge that to 
exactly 1.0, just in case.


I think I'd zip that list with the original list of items, so that you 
have a single list of tuples.


Now to generate a random sample, call  random.random() to get a value 
between 0 and 1. Search the list for the first item greater than or 
equal to your value, and return the other half of the tuple.



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


unpickling a stream

2009-05-26 Thread msolem
Hello,

I want to send a stream of pickled objects over a socket.  Is there a
standard way of ensuring that only complete objects are unpickled on
the receiving side.

client pseudo code:
  loop forever:
receive some bytes on the socket
if we have received a complete pickled object:  <== How is this
done?
  unpickle the object

This isn't for a project, just trying to learn some more about the
pickle module.

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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Mel
Sumitava Mukherjee wrote:

> Hi all,
> I need to randomly sample from a list where all choices have weights
> attached to them. The probability of them being choosen is dependent
> on the weights.
> If say Sample list of choices are [A,B,C,D,E] and weights of the same
> are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
> want the likeliness of them being chosen be in the order : D>A>C>E>B
> 
> In short I mean if prob of a H is .9 and probability of T be 0.1 then
> if I draw 10 samples, 9 should be H and 1 should be T.
> 
> I coudn't find a function in the module random that does so.
> Please can someone guide me how the above could be implemented [either
> through some function which exists and I don't know or pointers to
> some code snippets which does so]?

 I've usually used something like (untested):

def chooser (objects, weights):
total = 0.0
for obj, weight in zip (objects, weights):
total += weight
if weight < total * random.random():
chosen = obj
return chosen

Works fine if runtime is not a great concern.

Mel.

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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread George Sakkis
On May 26, 2:39 pm, Sumitava Mukherjee  wrote:
> Hi all,
> I need to randomly sample from a list where all choices have weights
> attached to them. The probability of them being choosen is dependent
> on the weights.
> If say Sample list of choices are [A,B,C,D,E] and weights of the same
> are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
> want the likeliness of them being chosen be in the order : D>A>C>E>B
>
> In short I mean if prob of a H is .9 and probability of T be 0.1 then
> if I draw 10 samples, 9 should be H and 1 should be T.
>
> I coudn't find a function in the module random that does so.
> Please can someone guide me how the above could be implemented [either
> through some function which exists and I don't know or pointers to
> some code snippets which does so]?

1. Normalize the weights so that they sum up to 1.
2. Form the cumulative sequence S = [0, w0, w0+w1, w0+w1+w2, ..., sum
(w)==1.0]
3. Call random.random() -> x
4. Find the bucket in S that x belongs to, i.e. the i so that s[i] <=
x < s[i+1] (you can do this fast using the bisect module).
5. Return choice[i]
6. Test.
7. Submit homework ;)

HTH,
George
-- 
http://mail.python.org/mailman/listinfo/python-list


Pickle of the instance of new style class fails when execute with exec statement

2009-05-26 Thread Борис Казаков
Hi, I'm trying to execute the following code:

d = {}
exec('import cPickle')  in d
desc = """
class A(object):
pass
"""
exec(desc) in d

exec('a = A()') in d
exec('cPickle.dump(a, open("tmp.txt","wb"))')in d

for some reason it fails with the following traceback:

Traceback (most recent call last):
  File "pickleTest.py", line 10, in 
exec('cPickle.dump(a, open("tmp.txt","wb"))')in d
  File "", line 1, in 
cPickle.PicklingError: Can't pickle : attribute lookup
__builtin__.A failed

pickle also dosen't work, changing protocol dosen't seem to help.

it works when i do:

exec('import __builtin__') in d
exec('__builtin__.A = A') in d

but it pollutes builtin namespace, which I don't like.

May be there is a workaround, how to do this correctly?
Thanks in advance,
Boris.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing string from python programs to external programs

2009-05-26 Thread Jeff McNeil
On May 26, 2:12 pm, lone_eagle  wrote:
> Hi all,
>
> On Linux, I do something like this
>
> $ program_to_execute < input_file
> ... get some output ...
>
> I have the content of the input_file as a string inside a python
> program and would like to pass this string to the external program
> from inside the python program and get back the programs output in a
> string/file. Can someone tell me how to achieve this. I have been
> through the documentation for Popen, but this one beats me.
>
> Cheers,
> Chaitanya

Sounds like subprocess is what you want.  Here's a quick ad-hoc
example. You can find more information on the module at
http://docs.python.org/library/subprocess.html.

[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> sub = subprocess.Popen('/bin/gzip', stdin=subprocess.PIPE, 
>>> stdout=subprocess.PIPE)
>>> g = sub.communicate('Please, sir, gzip me?')
>>> import gzip
>>> import StringIO
>>> gzip.GzipFile(fileobj=StringIO.StringIO(g[0])).read()
'Please, sir, gzip me?'
>>>

Thanks,

Jeff
mcjeff.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile python extensions under windows/cygwin

2009-05-26 Thread Joshua Kugler
Joana wrote:

> I mantain Python on Windows, all installed packages are under c:
> \Python25\Lib\site-packages. Now I have to build C libraries used by
> python extensions and I am using cygwin, but I don't know how to
> install the module in Windows directory.

I have used MingW to do this.  Might this help:

http://joshuakugler.com/archives/13-Building-Python-Eggs-with-C-Extensions-on-Windows.html

j

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Brian Blais

On May 26, 2009, at 8:07 , Lacrima wrote:


I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?


I have found that the appreciation of a text editor varies greatly  
across different people.  What one person swears by, feels clunky to  
another.  On the Mac, I like TextMate because I find it pretty clean  
and fast.  On Windows I've used Notepad++, Emacs, Crimson, and  
possibly a few others.  What I recommend is to try out some of the  
editors in:


http://wiki.python.org/moin/PythonEditors

and see how it works for you.  Depending on what you need, and how  
they "feel", you may find what you want with a free editor.




bb

--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



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


Re: What text editor is everyone using for Python

2009-05-26 Thread Brian Blais

On May 26, 2009, at 11:17 , Ken Seehart wrote:



Lacrima wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?



Jean-Michel Pichavant wrote:

Why buy an IDE when you just need a text editor ? I don't get it.
Anyway gvim (aka vim aka vi) and emacs are the most powerful  
editors for years. Both have Windows and Linux version and most  
important, they both are very effective at editing any file type  
(python, C, latex, love letters...)
Emacs is more accessible to the newby but requires time to master  
its complex features.
Gvim may be complex for the newby due to its command/insertion  
mode constant switch, but is as powerful as emacs can be. Being a  
gvim adept, I should stat that gvim is far better but it would  
only feed the neverending war.


Jean-Michel


I've heard notepad is pretty good.  http://www.notepad.org/




I'm sorry, but ed is the standard editor[1].   :)


bb



[1] http://en.wikipedia.org/wiki/Ed_(text_editor)




--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais



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


Re: Passing string from python programs to external programs

2009-05-26 Thread CTO
On May 26, 2:12 pm, lone_eagle  wrote:
> Hi all,
>
> On Linux, I do something like this
>
> $ program_to_execute < input_file
> ... get some output ...
>
> I have the content of the input_file as a string inside a python
> program and would like to pass this string to the external program
> from inside the python program and get back the programs output in a
> string/file. Can someone tell me how to achieve this. I have been
> through the documentation for Popen, but this one beats me.
>
> Cheers,
> Chaitanya

from subprocess import getstatusoutput

cmd = 'echo '
str = 'Hello World!'
status, output = getstatusoutput(cmd + repr(str))

Obviously, this is 3.x. I believe that in 2.x it was in
the commands module.

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


Re: [Python-Dev] PEP 384: Defining a Stable ABI

2009-05-26 Thread Martin v. Löwis
 Functions declared in the following header files are not part
 of the ABI:
 - cellobject.h
 - classobject.h
 - code.h
 - frameobject.h
 - funcobject.h
 - genobject.h
 - pyarena.h
 - pydebug.h
 - symtable.h
 - token.h
 - traceback.h
>>> I don't think that's feasable: you basically remove all introspection
>>> functions that way.
>>>
>>> This will need a more fine-grained approach.
>> What specifically is it that you want to do in a module that you
>> couldn't do anymore?
> 
> See my reply to Nick: some of the functions are needed even
> if you don't want to do introspection, such as Py_FatalError()

Ok. I don't know what Py_FatalError is doing in pydebug.h, so I
now propose to move it to pyerrors.h.

> or PyTraceBack_Print().

Ok; I have removed traceback.h from the list. By the other rules
of the PEP, the only function that becomes available then is
PyTraceBack_Print.

> BTW: Given the headline, I take it that the various type checking
> macros in these header will still be available, right ?

Which headers? The one on the list above? No; my idea would
be to completely hide them as-is.

All other type-checking macros will remain available, and
will remain being macros.

>>> Would creating a Python object in a full-API extension and
>>> free'ing it in a limited-API extension cause problems ?
>> No problem that I can see.
> 
> Can we be sure that the MSVCRT used by python35.dll stays compatible
> to the one used by say python32.dll ? What if the CRT memory
> management changes between MSVCRT versions ?

It doesn't matter. For Python "things", the extension module will
use the pymem.h functions, which get routed through pythonxy.dll
to the CRT that Python was build with.

If the extension uses regular malloc(), it should also invoke
regular free() on the pointer. There is no API where Python
calls malloc directly and the extension calls free, or vice
versa.

> How will this work in the light of having multiple copies of
> Python installed on a Windows machine ?

Interesting question. One solution could be to use SxS, which
would allow multiple concurrent installations of python3.dll,
although we would need to make sure it always binds to the
"right" one in each context.

Another solution could be to keep the various copies of python3.dll
in their respective PYTHONHOMEs, and leave it to python.exe or the
app to load the right one; any subsequent extension modules should
then pick up the one that was already loaded.

> They implementation section suggests that python3.dll would always
> redirect to the python3x.dll for which it was installed, ie. if
> I have Python 3.5 installed, but then need to run some app with
> Python 3.2, the installed python3.dll would then point back to the
> python32.dll.

That depends on where they get installed. If they all go into system32,
only the most recent one would be available, which is probably not
desirable.

> Now, if I start a Python 3.5 application which uses a limited
> API extension, this would try to load python32.dll into the
> Python 3.5 process. AFAIK, that's not possible due to the
> naming conflicts.

I don't see this problem. As long as we manage to install multiple
versions of python3.dll on the system somehow, different processes
could certainly load different such DLLs, and the same extension
module would always use the right one.

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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Arnaud Delobelle
Sumitava Mukherjee  writes:

> On May 26, 11:39 pm, Sumitava Mukherjee  wrote:
>> Hi all,
>> I need to randomly sample from a list where all choices have weights
>> attached to them. The probability of them being choosen is dependent
>> on the weights.
>> If say Sample list of choices are [A,B,C,D,E] and weights of the same
>> are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
>> want the likeliness of them being chosen be in the order : D>A>C>E>B

You mean A > D > C > E > B

>> In short I mean if prob of a H is .9 and probability of T be 0.1 then
>> if I draw 10 samples, 9 should be H and 1 should be T.
>>
>> I coudn't find a function in the module random that does so.
>> Please can someone guide me how the above could be implemented [either
>> through some function which exists and I don't know or pointers to
>> some code snippets which does so]?
>
> [Oh, I forgot to mention. I am looking for sampling without replacement.]

If you do sampling without replacement, you need to know the exact
number of each of A, B, C, D, E in the sample, not just their relative
frequency.

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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Emile van Sebille

On 5/26/2009 11:39 AM Sumitava Mukherjee said...

Hi all,
I need to randomly sample from a list where all choices have weights
attached to them. The probability of them being choosen is dependent
on the weights.
If say Sample list of choices are [A,B,C,D,E] and weights of the same
are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
want the likeliness of them being chosen be in the order : D>A>C>E>B

In short I mean if prob of a H is .9 and probability of T be 0.1 then
if I draw 10 samples, 9 should be H and 1 should be T.


I don't know if there's a function for this somewhere, but you can 
easily roll your own...


import random

choices = list('ABCDE')
weights = [0.895,0.567,0.765,0.890,0.60]

selections = list("".join([ choice*int(weight*1000) for choice,weight in 
zip(choices,weights) ]))


random.shuffle(selections)

for randomchoice in selections:
   dosomething(randomchoice)

Emile





I coudn't find a function in the module random that does so.
Please can someone guide me how the above could be implemented [either
through some function which exists and I don't know or pointers to
some code snippets which does so]?


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


Re: How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Sumitava Mukherjee
On May 26, 11:39 pm, Sumitava Mukherjee  wrote:
> Hi all,
> I need to randomly sample from a list where all choices have weights
> attached to them. The probability of them being choosen is dependent
> on the weights.
> If say Sample list of choices are [A,B,C,D,E] and weights of the same
> are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
> want the likeliness of them being chosen be in the order : D>A>C>E>B
>
> In short I mean if prob of a H is .9 and probability of T be 0.1 then
> if I draw 10 samples, 9 should be H and 1 should be T.
>
> I coudn't find a function in the module random that does so.
> Please can someone guide me how the above could be implemented [either
> through some function which exists and I don't know or pointers to
> some code snippets which does so]?

 [Oh, I forgot to mention. I am looking for sampling without replacement.]
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I sample randomly based on some probability(wightage)?

2009-05-26 Thread Sumitava Mukherjee
Hi all,
I need to randomly sample from a list where all choices have weights
attached to them. The probability of them being choosen is dependent
on the weights.
If say Sample list of choices are [A,B,C,D,E] and weights of the same
are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
want the likeliness of them being chosen be in the order : D>A>C>E>B

In short I mean if prob of a H is .9 and probability of T be 0.1 then
if I draw 10 samples, 9 should be H and 1 should be T.

I coudn't find a function in the module random that does so.
Please can someone guide me how the above could be implemented [either
through some function which exists and I don't know or pointers to
some code snippets which does so]?
-- 
http://mail.python.org/mailman/listinfo/python-list


Passing string from python programs to external programs

2009-05-26 Thread lone_eagle
Hi all,

On Linux, I do something like this

$ program_to_execute < input_file
... get some output ...

I have the content of the input_file as a string inside a python
program and would like to pass this string to the external program
from inside the python program and get back the programs output in a
string/file. Can someone tell me how to achieve this. I have been
through the documentation for Popen, but this one beats me.

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


multiprocessing / forking memory usage

2009-05-26 Thread Randall Smith
I'm trying to get a grasp on how memory usage is affected when forking 
as the multiprocessing module does.  I've got a program with a parent 
process using wx and other memory intensive modules. It spawns child 
processes (by forking) that should be very lean (no wx required, etc). 
Based on inspection using "ps v" and psutil, the memory usage (rss) is 
much higher than I would expect for the subprocess.


My understanding is that COW is used when forking (on Linux).  So maybe 
"ps v pid" is reflecting that.  If that's the case, is there a way to 
better determine the child's memory usage?  If it's not the case and I'm 
using modules I don't need, how can I reduce the memory usage to what 
the child actually uses instead of including everything the parent is using?


Randall

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


Re: Ted Dziuba

2009-05-26 Thread John DeRosa
On 2009-05-25 00:22:04 -0700, Lawrence D'Oliveiro 
 said:



:

If you've ever had to build C extensions to Python on Windows, you can
join me in a feeling of satisfaction that someone at Microsoft is going
to have to figure this out. Let's call it retribution for Internet
Explorer 6.


Brilliant. OT, I miss uncov.com. His wit is razor-sharp.

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


test message

2009-05-26 Thread Joel Goldstick
I'm wondering why I couldn't post here.  I read the email list, not from 
 the newsgroup

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


Re: [Python-Dev] PEP 384: Defining a Stable ABI

2009-05-26 Thread M.-A. Lemburg
Martin v. Löwis wrote:
>> Now, with the PEP, I have a feeling that the Python C-API
>> will in effect be limited to what's in the PEP's idea of
>> a usable ABI and open up the non-inluded public C-APIs
>> to the same rate of change as the private APIs.
> 
> That's certainly not the plan. Instead, the plan is to have
> a stable ABI. The policy on the API isn't affected, except
> for restricting changes to the API that would break the ABI.

Thanks for clarifying this.

>>> During the compilation of applications, the preprocessor macro
>>> Py_LIMITED_API must be defined. Doing so will hide all definitions
>>> that are not part of the ABI.
>> So extensions wanting to use the full Python C-API as documented
>> in the C-API docs will still be able to do this, right ?
> 
> Correct. They would link to the version-specific DLL on Windows.

Good.

>>> The structure of type objects is not available to applications;
>>> declaration of "static" type objects is not possible anymore
>>> (for applications using this ABI).
>> Hmm, that's going to create big problems for extensions that
>> want to expose a C-API for their types: Type checks are normally
>> done by pointer comparison using those static type objects.
> 
> I don't see the problem. During module initialization, you
> create the type object and store it in a global variable, and
> then both clients and the module compare against the stored
> pointer.

Ah, good point !

>>> Function-like macros (in particular, field access macros) remain
>>> available to applications, but get replaced by function calls
>>> (unless their definition only refers to features of the ABI, such
>>> as the various _Check macros)
>> Including Py_INCREF()/Py_DECREF() ?
> 
> Yes, although some people are requesting that these become functions.

I'd opt against that, simply because it creates a lot of overhead
due to the function call and issues with cache locality.

>>> Excluded Functions
>>> --
>>>
>>> Functions declared in the following header files are not part
>>> of the ABI:
>>> - cellobject.h
>>> - classobject.h
>>> - code.h
>>> - frameobject.h
>>> - funcobject.h
>>> - genobject.h
>>> - pyarena.h
>>> - pydebug.h
>>> - symtable.h
>>> - token.h
>>> - traceback.h
>> I don't think that's feasable: you basically remove all introspection
>> functions that way.
>>
>> This will need a more fine-grained approach.
> 
> What specifically is it that you want to do in a module that you
> couldn't do anymore?

See my reply to Nick: some of the functions are needed even
if you don't want to do introspection, such as Py_FatalError()
or PyTraceBack_Print().

BTW: Given the headline, I take it that the various type checking
macros in these header will still be available, right ?

>>> On Windows, applications shall link with python3.dll;
>> You mean: extensions that were compiled with Py_LIMITED_API, right ?
> 
> Correct, see "Terminology" in the PEP.

Good, thanks.

>>> an import
>>> library python3.lib will be available. This DLL will redirect all of
>>> its API functions through /export linker options to the full
>>> interpreter DLL, i.e. python3y.dll.
>> What if you mix extensions that use the full C-API with ones
>> that restrict themselves to the limited version ?
> 
> Some link against python3.dll, others against python32.dll (say).
> 
>> Would creating a Python object in a full-API extension and
>> free'ing it in a limited-API extension cause problems ?
> 
> No problem that I can see.

Can we be sure that the MSVCRT used by python35.dll stays compatible
to the one used by say python32.dll ? What if the CRT memory
management changes between MSVCRT versions ?

Another aspect to consider:

How will this work in the light of having multiple copies of
Python installed on a Windows machine ?

They implementation section suggests that python3.dll would always
redirect to the python3x.dll for which it was installed, ie. if
I have Python 3.5 installed, but then need to run some app with
Python 3.2, the installed python3.dll would then point back to the
python32.dll.

Now, if I start a Python 3.5 application which uses a limited
API extension, this would try to load python32.dll into the
Python 3.5 process. AFAIK, that's not possible due to the
naming conflicts.

>>> This PEP will be implemented in a branch, allowing users to check
>>> whether their modules conform to the ABI. To simplify this testing, an
>>> additional macro Py_LIMITED_API_WITH_TYPES will expose the existing
>>> type object layout, to let users postpone rewriting all types. When
>>> the this branch is merged into the 3.2 code base, this macro will
>>> be removed.
>> Now I'm confused again: this sounds a lot like you do want all extension
>> writers to only use the limited API.
> 
> I certainly want to support as many modules as reasonable with the PEP.
> Whether or not developers then chose to build version-independent
> binaries is certainly outside the scope of the PEP - it only specifies
> action items for Python, not 

Re: How to test python snippets in my documents?

2009-05-26 Thread Ned Deily
In article ,
 Matthew Wilson  wrote:
> I'm using a homemade script to verify some code samples in my
> documentation.  [...]
> The script checks all the files listed as arguments.  This is OK, but is
> there anything better?

Perhaps a test-discovery framework, like nose:

http://ivory.idyll.org/articles/nose-intro.html#running-doctests-in-nose

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

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


Re: large array in a single line

2009-05-26 Thread Arnaud Delobelle
karthik...@gmail.com writes:

> On May 26, 7:26 pm, Arnaud Delobelle  wrote:
>> karthik...@gmail.com writes:
>> > I would like to have a txt file of single line with
>> > [1 2 3 .100]
>>
>> > I try something like
>> > q=arange(100)
>> > fl=file('tmp.ext','w')
>> > fl.writelines(str(q))
>> > fl.close()
>>
>> > Unfortunately my output is
>>
>> > [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
>> > 23 24
>> >  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
>> > 48 49
>> >  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
>> > 73 74
>> >  75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
>> > 98 99]
>>
>> > ie there is automatic split in line after 76 characters. How do I
>> > avoid it? Thanks.
>>
>> You need to tell us more about the arange() function you use and what
>> object it returns.
>>
>> --
>> Arnaud
>
> arange(start, stop=None, step=1, typecode=None)
>
>  Just like range() except it returns an array whose type can be
> specified by the keyword argument typecode.

You didn't mention that it is a numpy function!  It returns a
numpy.ndarray object whose __str__() method automatically inserts
newlines to make the output easier to read I guess.

Don't use this, then. You can do for instance:

fl = open('tmp.ext', 'w')
fl.writelines(['[', ' '.join(range(1, 101)), ']'])
fl.close()

(untested)

-- 
Arnaud

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Tim Chase

Zamnedix wrote:

So what do you guys use, and why? Hopefully we can keep this civil.


Nano! Nano! Nano Revolution!!!


Thank you, Mork[1] :)

-tkc (who uses Vim for Python coding, and on rare occasions, 
Notepad or ed)


[1]
http://en.wikipedia.org/wiki/Mork_%26_Mindy





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


Re: large array in a single line

2009-05-26 Thread Robert Kern

On 2009-05-26 09:18, karthik...@gmail.com wrote:

I would like to have a txt file of single line with
[1 2 3 .100]

I try something like
q=arange(100)
fl=file('tmp.ext','w')
fl.writelines(str(q))
fl.close()

Unfortunately my output is

[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24
  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
  75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]

ie there is automatic split in line after 76 characters. How do I
avoid it? Thanks.


You will want to ask numpy questions on the numpy mailing list:

  http://www.scipy.org/Mailing_Lists

You can control the options for printing numpy arrays via the 
numpy.set_printoptions() function.



http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html#numpy.set_printoptions

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Network programming ?

2009-05-26 Thread Benjamin Kaplan
On Tue, May 26, 2009 at 4:00 AM, Dave Angel  wrote:

> thushiantha...@gmail.com wrote:
>
>> Hi everyone,
>>
>> I am planning to develop a chatting software in Python, for my college
>> project. I am using Windows Vista. Is it possible to do sockets
>> programming in Python ? Any books or websites ?  Also, i want to
>> develop a gui for that program. What are the gui tool kits available
>> for windows? I already knew about PyGtk and PyQT, but will they work
>> properly in Windows platform? Any suggestions?
>>
>> Thank you. Excuse my English.
>>
>>
>>
> You're asking two very distinct questions, and I hope others will chime in,
> especially with the sockets one.
>
> 1)  There is a module called socket, for low level BSD socket access, and
> it does support Windows (plus Mac OSX, BeOS, OS/2, and "all modern Unix"
> No experience with it, however.
>
> 2) There is tkInterf supplied with Python to do GUI development.  However,
> when I studied the choices I knew about, I picked wxPython.  I don't even
> remember the other choices, because it's hard to learn more than one.
>
> see:  http://www.python.org/
> and http://wiki.wxpython.org/
>
> Both totally free, and with very easy (msi) installers for Windows.
>
> Watch out for versions, though.  If you're goin to run wxPython, you want
> to get Python 2.5x or 2.6x, nothing later.  And many say that  wxPython for
>  2.5x is more stable,
> Then when you download wxPython, you need to get the matching version.
>

There was a problem with manifest files in the original Python 2.6 with
wxPython (Python switched to using Visual Studio 2008, wxPython was still
using an older version). I think they have most of the kinks worked out now.


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


Re: What text editor is everyone using for Python

2009-05-26 Thread Bar Shirtcliff
Ken Seehart writes:
| 
| Lacrima wrote:
| > I am new to python.
| > And now I am using trial version of Wing IDE.
| > But nobody mentioned it as a favourite editor.
| > So should I buy it when trial is expired or there are better choices?
| >   
| 

| I've heard notepad is pretty good.  http://www.notepad.org/
| 
| :-) Ken
| 

Seriously.  I actually know a programmer who does all of his work in
notepad: no macros, syntax-highlighting, or any other robust features,
plus that horrible font.

I use emacs.  No alternative presentation rivals, for me, the ability
to program your editor while you use it.  Never having to reach for
the mouse in emacs is a terrific (and optional) bonus.

I guess it depends on how you work.  If you're willing to invest a
fair amount of time in your editor and you like the idea of being able
to drastically modify your editor while you use it, you should
consider emacs.  Emacs has a good on-line help system, including a
friendly emacs lisp introduction.  If you're using a Mac, check out
Aquamacs Emacs.

I can't say a thing about other editors, except that when some shell
script perversely dumped me into vi a month ago, I felt as horrified
as if some actually living bugs had crawled out of my own reflection
on the computer screen and fallen, clicking and scraping, onto the
keyboard.  That's a personal reaction - totally irrelevant, of course.

Bar 

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


Re: large array in a single line

2009-05-26 Thread Dave Angel

karthik...@gmail.com wrote:

I would like to have a txt file of single line with
[1 2 3 .100]

I try something like
q=arange(100)
fl=file('tmp.ext','w')
fl.writelines(str(q))
fl.close()

Unfortunately my output is

[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]

ie there is automatic split in line after 76 characters. How do I
avoid it? Thanks.

  


I never heard of arange(), but perhaps you meant range() or xrange().  
If so, the first problem is that range(100) starts with 0 and ends just 
before 100, so you only get the values 0 to 99.  So if you need the 
final value to be 100, you need to pass it a 101.


Next problem is that you're using str() on a list.  All that does is try 
to give you some printable representation of the list.  You've observed 
it divides it into lines, but that's arbitrary.  If you want the output 
to look a certain way, build it that way.   Use write instead of 
writelines, and put your own \n at the end.


Create a for loop, iterate over the list q, writing each value with a 
trailing space, and follow the loop with one extra write, containing the 
closing brace, and the newline.


Don't forget the leading brace as well.


Sometimes debugging these things can be easier if you temporarily use 
sys.stdout instead of a file, while you're working on it.



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


Re: What text editor is everyone using for Python

2009-05-26 Thread Benjamin Kaplan
On Tue, May 26, 2009 at 8:07 AM, Lacrima  wrote:

> I am new to python.
> And now I am using trial version of Wing IDE.
> But nobody mentioned it as a favourite editor.
> So should I buy it when trial is expired or there are better choices?


We're mostly talking about text editors, not full-fledged IDEs. Those are
actually 3 different pieces of flame bait right there: favorite text editor,
favorite IDE, and text editors vs. IDEs.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Ken Seehart


Lacrima wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?
  


Jean-Michel Pichavant wrote:

Why buy an IDE when you just need a text editor ? I don't get it.
Anyway gvim (aka vim aka vi) and emacs are the most powerful editors 
for years. Both have Windows and Linux version and most important, 
they both are very effective at editing any file type (python, C, 
latex, love letters...)
Emacs is more accessible to the newby but requires time to master its 
complex features.
Gvim may be complex for the newby due to its command/insertion mode 
constant switch, but is as powerful as emacs can be. Being a gvim 
adept, I should stat that gvim is far better but it would only feed 
the neverending war.


Jean-Michel


I've heard notepad is pretty good.  http://www.notepad.org/

:-) Ken


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


Re: What text editor is everyone using for Python

2009-05-26 Thread Zamnedix
On May 25, 10:35 am, LittleGrasshopper  wrote:
> With so many choices, I was wondering what editor is the one you
> prefer when coding Python, and why. I normally use vi, and just got
> into Python, so I am looking for suitable syntax files for it, and
> extra utilities. I dabbled with emacs at some point, but couldn't get
> through the key bindings for commands. I've never tried emacs with vi
> keybindings (I forgot the name of it) but I've been tempted.
>
> So what do you guys use, and why? Hopefully we can keep this civil.

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


Re: replacement for execfile

2009-05-26 Thread Scott David Daniels

Alex Popescu wrote:

"Steven D'Aprano"  wrote in
news:pan.2007.07.29.03.39.34.703...@remove.this.cybersource.com.au: 

... you're expecting the users to write working Python code, but
you think "import module" is too hard for them?


That was just a cherry on the cake. The most important part is that 
through this mechanism the user will be able to configure the framework 
through normal Python code (very simple API: 3 functions), and not 
through .ini, .xml or other variants.


I think Steven's point is that you can tell the to define a module with,
for example a setup function.  You then import their module and run
their setup function.  They then have a straightforward environment,
and can, for example do straightforward unit tests on their code if
anything even slightly tricky might be wanted as support code.  I agree
with Steven; much nicer to ask them to define a particular module and go
names inside that module.


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing math functions

2009-05-26 Thread Robert Kern

On 2009-05-24 07:42, Esmail wrote:

Robert Kern wrote:



We have several bounded optimization routines in scipy.

http://docs.scipy.org/doc/scipy/reference/optimize.html


Hi Robert,

Thanks for the lead .. I briefly looked at the documentation, but
before I dig into this more deeply 2 quick questions:

1. Will is also allow me to maximize a function (I only saw minimum)?


Already answered.


2. Will it give me the global minima/maxima?


No, they are local optimizers.


I only ask because I got all excited to see that R has an optimize
function but unfortunately it can not deal with multi-modal functions.
I am trying to come up with some complex test cases for a genetic
algorithm I'm working with, both for functions using f(x) and f(x,y) over a
variety of intervals so I would like to have a way to verify results for
more challenging functions.


You may want to consider using artificial functions with known optima. Here is a 
paper from the ACM Transactions on Mathematical Software doing such:


  http://portal.acm.org/citation.cfm?id=962444
  http://wwwinfo.deis.unical.it/~yaro/GKLS.html
  http://www.netlib.org/toms/829

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: large array in a single line

2009-05-26 Thread Arnaud Delobelle
karthik...@gmail.com writes:

> I would like to have a txt file of single line with
> [1 2 3 .100]
>
> I try something like
> q=arange(100)
> fl=file('tmp.ext','w')
> fl.writelines(str(q))
> fl.close()
>
> Unfortunately my output is
>
> [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
> 23 24
>  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
> 48 49
>  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> 73 74
>  75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
> 98 99]
>
> ie there is automatic split in line after 76 characters. How do I
> avoid it? Thanks.

You need to tell us more about the arange() function you use and what
object it returns.

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


Re: How to test python snippets in my documents?

2009-05-26 Thread Lie Ryan

Matthew Wilson wrote:

I'm using a homemade script to verify some code samples in my
documentation.  Here it is:

#! /usr/bin/env python2.6

# vim: set expandtab ts=4 sw=4 filetype=python:

import doctest, os, sys

def main(s):
"Run doctest.testfile(s, None)"

return doctest.testfile(s, None)

if __name__ == "__main__":
for x in sys.argv[1:]:
print "testing code excerpts in %s..." % x
print main(x)


The script checks all the files listed as arguments.  This is OK, but is
there anything better?



maybe glob.glob('*.py')?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread David Smith
Lacrima wrote:
> I am new to python.
> And now I am using trial version of Wing IDE.
> But nobody mentioned it as a favourite editor.
> So should I buy it when trial is expired or there are better choices?


I use Wing IDE and like it.  It very nicely enforces consistent space
indentations and other Python basics that might fall through the cracks
when writing.  I'm not too hot on the auto-suggest, but I haven't seen
any other IDE do better.

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


Re: which database is suitable for small applications

2009-05-26 Thread Kushal Kumaran
On Tue, May 26, 2009 at 2:03 PM, Kalyan Chakravarthy
 wrote:
> Hi All,
>   can any one suggest me which database I can use for my small
> application(to store user names ,passwords, very few other data.. )
> I am using Python, Google Apps and guide me how to connect to database, I am
> very new to these technologies
>

Going by your previous mail, I assume you meant Google App Engine when
you said Google Apps.  Given that, searching for google app engine
database gives 
http://code.google.com/appengine/docs/python/gettingstarted/usingdatastore.html
as the first result.

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


Re: Network programming ?

2009-05-26 Thread thushianthan15
Thank you, for all your support.

I will try wxPython with the sockets module.

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


Re: What is the difference between init and enter?

2009-05-26 Thread Gary Herron

John wrote:
I'm okay with init, but it seems to me that enter is redundant since 
it appears that anything you want to execute in enter can be done in 
init.


The proper response to a question like this has to be
   http://www.catb.org/~esr/faqs/smart-questions.html
as anything else is complete guesswork.



Gary Herron

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


scripting and uploading in Python

2009-05-26 Thread Mark Tarver
I've recently purchased a site on a Linux server which runs Python.

Generally I'd like to bring myself up to speed on scripting in
Python.   Any good reads - dead tree or otherwise?

One thing I need to learn is to be able to give folks the power to
upload files onto their own disk space using passwords.

thanks

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


Re: [Python-Dev] PEP 384: Defining a Stable ABI

2009-05-26 Thread Martin v. Löwis
> Now, with the PEP, I have a feeling that the Python C-API
> will in effect be limited to what's in the PEP's idea of
> a usable ABI and open up the non-inluded public C-APIs
> to the same rate of change as the private APIs.

That's certainly not the plan. Instead, the plan is to have
a stable ABI. The policy on the API isn't affected, except
for restricting changes to the API that would break the ABI.

>> During the compilation of applications, the preprocessor macro
>> Py_LIMITED_API must be defined. Doing so will hide all definitions
>> that are not part of the ABI.
> 
> So extensions wanting to use the full Python C-API as documented
> in the C-API docs will still be able to do this, right ?

Correct. They would link to the version-specific DLL on Windows.

>> The structure of type objects is not available to applications;
>> declaration of "static" type objects is not possible anymore
>> (for applications using this ABI).
> 
> Hmm, that's going to create big problems for extensions that
> want to expose a C-API for their types: Type checks are normally
> done by pointer comparison using those static type objects.

I don't see the problem. During module initialization, you
create the type object and store it in a global variable, and
then both clients and the module compare against the stored
pointer.

>> Function-like macros (in particular, field access macros) remain
>> available to applications, but get replaced by function calls
>> (unless their definition only refers to features of the ABI, such
>> as the various _Check macros)
> 
> Including Py_INCREF()/Py_DECREF() ?

Yes, although some people are requesting that these become functions.

>> Excluded Functions
>> --
>>
>> Functions declared in the following header files are not part
>> of the ABI:
>> - cellobject.h
>> - classobject.h
>> - code.h
>> - frameobject.h
>> - funcobject.h
>> - genobject.h
>> - pyarena.h
>> - pydebug.h
>> - symtable.h
>> - token.h
>> - traceback.h
> 
> I don't think that's feasable: you basically remove all introspection
> functions that way.
> 
> This will need a more fine-grained approach.

What specifically is it that you want to do in a module that you
couldn't do anymore?

>> On Windows, applications shall link with python3.dll;
> 
> You mean: extensions that were compiled with Py_LIMITED_API, right ?

Correct, see "Terminology" in the PEP.

> 
>> an import
>> library python3.lib will be available. This DLL will redirect all of
>> its API functions through /export linker options to the full
>> interpreter DLL, i.e. python3y.dll.
> 
> What if you mix extensions that use the full C-API with ones
> that restrict themselves to the limited version ?

Some link against python3.dll, others against python32.dll (say).

> Would creating a Python object in a full-API extension and
> free'ing it in a limited-API extension cause problems ?

No problem that I can see.

>> This PEP will be implemented in a branch, allowing users to check
>> whether their modules conform to the ABI. To simplify this testing, an
>> additional macro Py_LIMITED_API_WITH_TYPES will expose the existing
>> type object layout, to let users postpone rewriting all types. When
>> the this branch is merged into the 3.2 code base, this macro will
>> be removed.
> 
> Now I'm confused again: this sounds a lot like you do want all extension
> writers to only use the limited API.

I certainly want to support as many modules as reasonable with the PEP.
Whether or not developers then chose to build version-independent
binaries is certainly outside the scope of the PEP - it only specifies
action items for Python, not for application authors.

>>> Something I haven't seen explicitly mentioned as yet (in the PEP or the
 python-dev list discussion) are the memory management APIs and the FILE*
 APIs which can cause the MSVCRT versioning issues on Windows.

 Those would either need to be excluded from the stable ABI or else
 changed to use opaque pointers.
>> Good point. As a separate issue, I would actually like to deprecate,
>> then remove these APIs. I had originally hoped that this would happen
>> for 3.0 already, alas, nobody worked on it.
>>
>> In any case, I have removed them from the ABI now.
> 
> How do you expect Python extensions to allocate memory and objects
> in a platform independent way without those APIs ?

I have only removed functions from the ABI that have FILE* in their
signatures.

> And as an aside: Which API families are you referring to ? PyMem_Malloc,
> PyObject_Malloc, or PyObject_New ?

Neither. PyRun_AnyFileFlags and friends.

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


How to test python snippets in my documents?

2009-05-26 Thread Matthew Wilson
I'm using a homemade script to verify some code samples in my
documentation.  Here it is:

#! /usr/bin/env python2.6

# vim: set expandtab ts=4 sw=4 filetype=python:

import doctest, os, sys

def main(s):
"Run doctest.testfile(s, None)"

return doctest.testfile(s, None)

if __name__ == "__main__":
for x in sys.argv[1:]:
print "testing code excerpts in %s..." % x
print main(x)


The script checks all the files listed as arguments.  This is OK, but is
there anything better?

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


Re: large array in a single line

2009-05-26 Thread Ken Seehart

Arnaud Delobelle wrote:

karthik...@gmail.com writes:

  

I would like to have a txt file of single line with
[1 2 3 .100]

I try something like
q=arange(100)
fl=file('tmp.ext','w')
fl.writelines(str(q))
fl.close()

Unfortunately my output is

[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]

ie there is automatic split in line after 76 characters. How do I
avoid it? Thanks.



You need to tell us more about the arange() function you use and what
object it returns.
  


That would be *numpy.arange

*Since numpy has it's own idea about formatting, you would have to roll 
your own.


How about:

   q=arange(100)
   *s = '[' + ' '.join([`x` for x in q]) + ']'*
   fl=file('tmp.ext','w')
   fl.*write*(s)
   fl.close()
 


See: http://docs.python.org/tutorial/datastructures.html#list-comprehensions

Incidentally, it's a funny thing that* writelines *coincidentally does 
what you expect it to do when given a string.  I suspect that you need 
to read the documentation on* writelines*:


file.writelines(/sequence/)
   Write a sequence of strings to the file. The sequence can be any
   iterable object producing strings, typically a list of strings.
   There is no return value. (The name is intended to match
   readlines(); writelines() does not add line separators.)

So you are asking it to effectively concatenate the characters in your 
string, (which gives you back your original string), and write the 
result.  Simply using* write *instead would be more efficient in this case.


Ken

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


Re: large array in a single line

2009-05-26 Thread karthik167
On May 26, 7:26 pm, Arnaud Delobelle  wrote:
> karthik...@gmail.com writes:
> > I would like to have a txt file of single line with
> > [1 2 3 .100]
>
> > I try something like
> > q=arange(100)
> > fl=file('tmp.ext','w')
> > fl.writelines(str(q))
> > fl.close()
>
> > Unfortunately my output is
>
> > [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
> > 23 24
> >  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
> > 48 49
> >  50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> > 73 74
> >  75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
> > 98 99]
>
> > ie there is automatic split in line after 76 characters. How do I
> > avoid it? Thanks.
>
> You need to tell us more about the arange() function you use and what
> object it returns.
>
> --
> Arnaud

arange(start, stop=None, step=1, typecode=None)

 Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Benjamin Kaplan
On Tue, May 26, 2009 at 11:17 AM, Ken Seehart  wrote:

>
> Lacrima wrote:
>
>> I am new to python.
>> And now I am using trial version of Wing IDE.
>> But nobody mentioned it as a favourite editor.
>> So should I buy it when trial is expired or there are better choices?
>>
>>
>
> Jean-Michel Pichavant wrote:
>
>> Why buy an IDE when you just need a text editor ? I don't get it.
>> Anyway gvim (aka vim aka vi) and emacs are the most powerful editors for
>> years. Both have Windows and Linux version and most important, they both are
>> very effective at editing any file type (python, C, latex, love letters...)
>> Emacs is more accessible to the newby but requires time to master its
>> complex features.
>> Gvim may be complex for the newby due to its command/insertion mode
>> constant switch, but is as powerful as emacs can be. Being a gvim adept, I
>> should stat that gvim is far better but it would only feed the neverending
>> war.
>>
>> Jean-Michel
>>
>>  I've heard notepad is pretty good.  http://www.notepad.org/
>

But it's not available on any *real* OS. XP

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


large array in a single line

2009-05-26 Thread karthik167
I would like to have a txt file of single line with
[1 2 3 .100]

I try something like
q=arange(100)
fl=file('tmp.ext','w')
fl.writelines(str(q))
fl.close()

Unfortunately my output is

[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]

ie there is automatic split in line after 76 characters. How do I
avoid it? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to create a list of functions depending on a parameter?

2009-05-26 Thread Scott David Daniels

enzo michelangeli wrote:

Let's suppose I want to create a list of n functions of a single
argument, returning the sum between argument and index in the list, so
that e.g.:

f[0](10) will return 10
f[3](12) will return 15

...and so on. I had naively though of coding:

 f = [lambda x: x+j for j in range(n)]


OK, first, almost a joke (unless you really need what you say):
f = [j.__add__ for j in range(n)]

And now the one various others are missing:

def add(x, y):
'''replace with the function you actually want'''
return x + y

f = [functools.partial(add, n) for n in range(0)]

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Arnaud Delobelle
Lawrence D'Oliveiro  writes:

> In message , Hendrik van 
> Rooyen wrote:
>
>> "Lawrence D'Oliveiro"  wrote:
>>> 
>>> Why [do you want syntax highlighting]?
>> 
>> It makes your screen look more busy as you type - for instance, if you
>> type a " or a ' then it treats the rest of the file from that point on as
>> belonging to the same string you are about to start typing, and colours it
>> all using the colour you have selected for displaying string literals.
>> This is basically to make you seasick and to force you to type the closing
>> quote immediately and then to back arrow to inside the string again to
>> finish typing the string, thereby making sure that firstly you type more
>> keystrokes, which will look good on your productivity summary, and
>> secondly to save the Python parser the hassle of dealing with a string
>> that has no end quote.
>
> Yeah, that's about what I figured. I think I first came across it 15 years 
> ago in Metrowerks CodeWarrior. I tried it for a while, but it didn't really 
> help with any of my program bugs, so I turned it off.

It's a bit like the colour-coding of electrical cables - distracting
more than anything else!  And don't start me on traffic lights...  They
nearly give me an epileptic fit each time.

That's why I use ed.  Ed is the standard text editor [1].  Ed is open
source [2].

[1] http://www.gnu.org/fun/jokes/ed.msg
[2] http://www.gnu.org/fun/jokes/ed

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Mel
LittleGrasshopper wrote:

> With so many choices, I was wondering what editor is the one you
> prefer when coding Python, and why. I normally use vi, and just got
> into Python, so I am looking for suitable syntax files for it, and
> extra utilities. I dabbled with emacs at some point, but couldn't get
> through the key bindings for commands. I've never tried emacs with vi
> keybindings (I forgot the name of it) but I've been tempted.
> 
> So what do you guys use, and why? Hopefully we can keep this civil.
 SciTE
I like one big uncomplicated window, tabbed file panes, syntax coloring and 
help with indentation.  There's nothing to it I hate.  It would be nice if 
customization were easier.

Mel.


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


Re: which database is suitable for small applications

2009-05-26 Thread Mike Driscoll
On May 26, 8:16 am, J Kenneth King  wrote:
> Jean-Michel Pichavant  writes:
> > Kalyan Chakravarthy wrote:
> >> Hi All,
> >>           can any one suggest me which database I can use for my
> >> small application(to store user names ,passwords, very few other
> >> data.. )
> >> I am using Python, Google Apps and guide me how to connect to
> >> database, I am very new to these technologies
>
> >> Please help me
>
> >> Thanks in advance
>
> >> --
> >> Regards
> >> Kalyan
>
> > If you are really new to these technologies and don't want to spend
> > some time on it, just serialize on the disk your data structure
> > containing your names, password and so on
> > (http://docs.python.org/library/pickle.html).
> > Depending on your application you may not be that concerned with
> > security/reliability issues.
>
> > Of course if you want to learn more about it, go on. I personally use
> > postgreSQL with the pgdb python module. But this is the only one I
> > ever used so I'll let someone else more familiar with all the database
> > types respond to you.
>
> > Jean-Michel
>
> sqlite is also a pretty lite database. Sits in a single file and the
> libraries ship with Python (> 2.6 I think? or maybe 2.5?).
>

Sqlite starting shipping with Python 2.5.

I use SqlAlchemy to connect to Microsoft SQL 2000 right now, but I
used to use the mssql and adodb modules. The latter two worked for
what I needed, although I was always running to escaping issues with
them. SqlAlchemy is nice because it does all that for you and you can
switch database back-ends with little to no change in your code.

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


Re: Regarding sort()

2009-05-26 Thread Scott David Daniels

Jaime Fernandez del Rio wrote:

... the reasons are starting to pile to fare 2.6 goodbye and move on to 3.0...

If you wait just a bit (TM)*, you'd be better served to move on to
3.1.  I think 3.0 is for learning, both for Python developers and
users, and has less "fit and polish" than previous Python releases.
Between 2.x and 3.0, there were huge changes, and some substantial
restructuring.  The move to Unicode strings was not without its
bumps and bruises, and efficiency was (quite properly) by no means
the top priority.  As a result, "normal" file I/O on 3.0 is slowed,
and getting that fixed was not a priority (as correctness was plenty
of work).

I'd view 3.0 as the first real-world view of Python 3000, and 3.1 as
getting the surprise burs and sharp edges of 3.0 cleaned up a bit.


* 3.1 is already in beta, according to PEP 375, the first release
  candidate is coming 30-May, with final release on 27-June:
  http://python.org/dev/peps/pep-0375

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Ken Seehart

Lacrima wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?
  

It's my favorite.  Buy it.  I'm not aware of any better choices.

If you can afford the Pro version buy that, especially if you are 
planning any large projects.  But take a peek at the feature list before 
making that decision: http://www.wingware.com/wingide/features .  Some 
of my favorite Pro features are test suite support, advanced debugging, 
and code folding.  The debugger is way more powerful in the Pro version.


Of course, favorites are ultimately determined by religious preference.

Ken

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Roy Smith
In article ,
 "Hendrik van Rooyen"  wrote:

> [syntax coloring] makes your screen look more busy as you type - for 
> instance, if you
> type a " or a ' then it treats the rest of the file from that point on as 
> belonging to the same string you are about to start typing, and colours it
> all using the colour you have selected for displaying string literals.
> This is basically to make you seasick and to force you to type the closing
> quote immediately 

Good syntax coloring implementations have some hysteresis built in, to 
prevent transient things (like strings you haven't closed yet) from 
changing the entire file.  If you stop typing for a while, it then does a 
full update.  This avoids the problem above.

That being said, syntax coloring is like any other tool.  It's worth 
trying, but if you find it hinders you more than it helps, turn it off.  
Different strokes for different folks.

My pet peeve is syntax-aware editors which get things wrong.  For example, 
the version of emacs I'm using now doesn't parse this properly:

'''A triple-quoted string.  Some editors won't get this right'''

The solution is to change the outer quotes to double-quotes, but it annoys 
me when I have to change my code to appease a tool.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Jean-Michel Pichavant

Why buy an IDE when you just need a text editor ? I don't get it.
Anyway gvim (aka vim aka vi) and emacs are the most powerful editors for 
years. Both have Windows and Linux version and most important, they both 
are very effective at editing any file type (python, C, latex, love 
letters...)
Emacs is more accessible to the newby but requires time to master its 
complex features.
Gvim may be complex for the newby due to its command/insertion mode 
constant switch, but is as powerful as emacs can be. Being a gvim adept, 
I should stat that gvim is far better but it would only feed the 
neverending war.


Jean-Michel


Lacrima wrote:

I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?
  


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


Re: What is the difference between init and enter?

2009-05-26 Thread Lie Ryan

Diez B. Roggisch wrote:

John wrote:


I'm okay with init, but it seems to me that enter is redundant since it
appears that anything you want to execute in enter can be done in init.


About what are you talking? 


Diez


Do you mean __init__ and __enter__?

They are used for two completely different purpose. __init__ is used to 
initialize an object when they've just been created. __enter__ is called 
when an object enters a Context Manager (i.e. with statement)


Example, when opening a file:

# this calls file.__init__
f = open('foo.bar')

# some codes...

# this calls file.__enter__
with f:
pass

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


Re: which database is suitable for small applications

2009-05-26 Thread J Kenneth King
Jean-Michel Pichavant  writes:

> Kalyan Chakravarthy wrote:
>> Hi All,
>>   can any one suggest me which database I can use for my
>> small application(to store user names ,passwords, very few other
>> data.. )
>> I am using Python, Google Apps and guide me how to connect to
>> database, I am very new to these technologies
>>
>> Please help me
>>
>> Thanks in advance
>>
>> -- 
>> Regards
>> Kalyan
>>
> If you are really new to these technologies and don't want to spend
> some time on it, just serialize on the disk your data structure
> containing your names, password and so on
> (http://docs.python.org/library/pickle.html).
> Depending on your application you may not be that concerned with
> security/reliability issues.
>
> Of course if you want to learn more about it, go on. I personally use
> postgreSQL with the pgdb python module. But this is the only one I
> ever used so I'll let someone else more familiar with all the database
> types respond to you.
>
> Jean-Michel

sqlite is also a pretty lite database. Sits in a single file and the
libraries ship with Python (> 2.6 I think? or maybe 2.5?).

Serialization is always a neat option. With a hash table DB like
berkeley or some such you can get a pretty speedy (albeit simple)
persistence layer.

Really depends on what your app needs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the difference between init and enter?

2009-05-26 Thread Ken Seehart

Diez B. Roggisch wrote:

John wrote:

  

I'm okay with init, but it seems to me that enter is redundant since it
appears that anything you want to execute in enter can be done in init.



About what are you talking? 


Diez
  

Presumably, the 'with' statement.  http://www.python.org/dev/peps/pep-0343/

   *__enter__*(self)

   Enter the runtime context related to this object. The *with*
    statement will bind this method's
   return value to the target(s) specified in the *as*
    clause of the statement, if any.


Unlike __init__,  __enter__ can return a value, which is assigned to the 
variable (or tuple) following the 'as' keyword:


   with EXPR as VAR:
   BLOCK

Also, the object used in a with statement can be constructed prior to 
the with statement.  The __init__ method is called when the object is 
initialized, but the __enter__ method is called when the context is 
entered (i.e. when the 'with' statement is invoked).


Ken

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


Re: What text editor is everyone using for Python

2009-05-26 Thread J Kenneth King
Lacrima  writes:

> I am new to python.
> And now I am using trial version of Wing IDE.
> But nobody mentioned it as a favourite editor.
> So should I buy it when trial is expired or there are better choices?

That is a slightly better question.

Try some of the free alternatives.  I do happen to use emacs.  It took
me quite a lot of adjusting to get used to it after being a vim user
for almost ten years.  Doesn't cost anything to give one a shot and
see if it works for you.  The choice of editor is a personal one
(hence the reluctance to answer your original question).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which database is suitable for small applications

2009-05-26 Thread Tim Chase

  can any one suggest me which database I can use for my small
application(to store user names ,passwords, very few other data.. )
I am using Python, Google Apps and guide me how to connect to database, I am
very new to these technologies


Well, depending on the complexity you need, you can use either 
the standard  "anydbm" module for simple, persistent key-value 
string-to-string mappings; or you can use the "sqlite3" module 
for a more full-fledged SQL experience with a local data-store. 
If you need to step up to a shared database, you can investigate 
the various MySQL, PostgreSQL, etc. bindings that can be added to 
Python.


You can read about both the "anydbm" and "sqlite3" modules (along 
with example code) in the standard library reference docs.


-tkc



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


Re: DB-API execute params, am I missing something?

2009-05-26 Thread Diez B. Roggisch
Gabriel Rossetti wrote:

> Hello everyone, I am trying to use dbapi with mysql and I get this error:
> 
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in getUnitParams
>   File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 151,
> in execute
> query = query % db.literal(args)
> TypeError: int argument required
> 
> with this code :
> 
> import MySQLdb
> 
> def getParams(curs):
> curs.execute("select * from param where id=%d", 1001)
> return curs.fetchall()
> 
> cp = MySQLdb.connect(host="localhost",
>  port=3306,
>  user="root",
>  passwd="123",
>  db="test")
> 
> curs = cp.cursor()
> result = getParams(curs)
> 
> I checked MySQLdb.paramstyle and it uses "format". I also tried passing
> (1001,) instead of just 1001 as the param but this changes nothing. What
> am I doing wrong?

AFAIK you need to use %s, regardless of what type you pass.

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


Building Python with icc on 64-bit Linux

2009-05-26 Thread Konrad Hinsen
I am trying to install Python 2.6.2 on a 64-bit Linux machine (RedHat  
Enterprise) using the Intel compiler (version 11). Even without  
optimizations (-O0), I get a compilation error in the ctypes module


icc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -O0 -I. -I/home/shr/ 
khinsen/tm\
p/Python-2.6.2/./Include -Ibuild/temp.linux-x86_64-2.6/libffi/include  
-Ibuild/t\
emp.linux-x86_64-2.6/libffi -I/home/shr/khinsen/tmp/Python-2.6.2/ 
Modules/_ctype\
s/libffi/src -I. -IInclude -I./Include -I/usr/local/include -I/home/ 
shr/khinsen\
/tmp/Python-2.6.2/Include -I/home/shr/khinsen/tmp/Python-2.6.2 -c / 
home/shr/khi\
nsen/tmp/Python-2.6.2/Modules/_ctypes/libffi/src/x86/ffi64.c -o build/ 
temp.linu\
x-x86_64-2.6/home/shr/khinsen/tmp/Python-2.6.2/Modules/_ctypes/libffi/ 
src/x86/f\

fi64.o
/home/shr/khinsen/tmp/Python-2.6.2/Modules/_ctypes/libffi/src/x86/ 
ffi64.c(43): \

error: identifier "__int128_t" is undefined
__int128_t sse[MAX_SSE_REGS];
^
compilation aborted for /home/shr/khinsen/tmp/Python-2.6.2/Modules/ 
_ctypes/libf\

fi/src/x86/ffi64.c (code 2)


and failed test:

test test_cmath failed -- Traceback (most recent call last):
  File "/home/shr/khinsen/tmp/Python-2.6.2/Lib/test/test_cmath.py",  
line 366, i\

n test_specific_values
self.fail(error_message)
AssertionError: acos: acos(complex(0.0, 0.0))
Expected: complex(1.5707963267948966, -0.0)
Received: complex(1.5707963267948966, 0.0)
Received value insufficiently close to expected value.


Adding optimization yields even more failed tests. My configuration  
options are:


configure --prefix=$HOME CC=icc CXX=icc OPT=-O0

Did anyone encounter these problems before? Any solutions?

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


Re: email scanning for X-Spam-Score

2009-05-26 Thread skip
Helmut>mailmsg = email.message_from_string(msg)
Helmut>SPAM_CORE = mailmsg['X-Spam-Score']

Maybe lower case?

SPAM_CORE = mailmsg['x-spam-score']

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
America's vaunted "free press" notwithstanding, story ideas that expose
the unseemly side of actual or potential advertisers tend to fall by the
wayside.  Not quite sure why.  -- Jim Thornton
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What text editor is everyone using for Python

2009-05-26 Thread Lacrima
I am new to python.
And now I am using trial version of Wing IDE.
But nobody mentioned it as a favourite editor.
So should I buy it when trial is expired or there are better choices?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the difference between init and enter?

2009-05-26 Thread Diez B. Roggisch
John wrote:

> I'm okay with init, but it seems to me that enter is redundant since it
> appears that anything you want to execute in enter can be done in init.

About what are you talking? 

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


DB-API execute params, am I missing something?

2009-05-26 Thread Gabriel Rossetti

Hello everyone, I am trying to use dbapi with mysql and I get this error:

Traceback (most recent call last):
 File "", line 1, in 
 File "", line 2, in getUnitParams
 File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 151, 
in execute

   query = query % db.literal(args)
TypeError: int argument required

with this code :

import MySQLdb

def getParams(curs):
   curs.execute("select * from param where id=%d", 1001)
   return curs.fetchall()

cp = MySQLdb.connect(host="localhost",
port=3306,
user="root",
passwd="123",
db="test")

curs = cp.cursor()
result = getParams(curs)

I checked MySQLdb.paramstyle and it uses "format". I also tried passing 
(1001,) instead of just 1001 as the param but this changes nothing. What 
am I doing wrong?


Thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list


What is the difference between init and enter?

2009-05-26 Thread John
I'm okay with init, but it seems to me that enter is redundant since it 
appears that anything you want to execute in enter can be done in init.

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


Re: What text editor is everyone using for Python

2009-05-26 Thread Lawrence D'Oliveiro
In message , Hendrik van 
Rooyen wrote:

> "Lawrence D'Oliveiro"  wrote:
>> 
>> Why [do you want syntax highlighting]?
> 
> It makes your screen look more busy as you type - for instance, if you
> type a " or a ' then it treats the rest of the file from that point on as
> belonging to the same string you are about to start typing, and colours it
> all using the colour you have selected for displaying string literals.
> This is basically to make you seasick and to force you to type the closing
> quote immediately and then to back arrow to inside the string again to
> finish typing the string, thereby making sure that firstly you type more
> keystrokes, which will look good on your productivity summary, and
> secondly to save the Python parser the hassle of dealing with a string
> that has no end quote.

Yeah, that's about what I figured. I think I first came across it 15 years 
ago in Metrowerks CodeWarrior. I tried it for a while, but it didn't really 
help with any of my program bugs, so I turned it off.


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


Re: How to create a list of functions depending on a parameter?

2009-05-26 Thread Diez B. Roggisch
Arnaud Delobelle wrote:

> "Diez B. Roggisch"  writes:
> 
>> You need to capture n into the closure of the lambda:
>>
>> f = [lambda x, n=n: x+j for j in xrange(n)]
> 
> You mean  [lambda x, j=j: x+j for j in xrange(n)]


Ah, sorry, parentheses-problem.

Diez


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


Re: How to create a list of functions depending on a parameter?

2009-05-26 Thread Diez B. Roggisch
Paul Rudin wrote:

> "Diez B. Roggisch"  writes:
> 
>> enzo michelangeli schrieb:
>>> Let's suppose I want to create a list of n functions of a single
>>> argument, returning the sum between argument and index in the list, so
>>> that e.g.:
>>>
>>> f[0](10) will return 10
>>> f[3](12) will return 15
>>>
>>> ...and so on. I had naively though of coding:
>>>
>>>  f = [lambda x: x+j for j in range(n)]
>>>
>>> Unfortunately, each function in the list f[]() behaves as a closure,
>>> and f[k](p) does NOT return p+k but p+j (for whatever value j has at
>>> the moment: typically n, the last value assumed by j in the list
>>> comprehension loop).
>>>
>>> Is there a way of achieving my goal? (Of course, n is not a constant
>>> known in advance, so I can't manually unroll the loop.)
>>
>> You need to capture n into the closure of the lambda:
>>
>> f = [lambda x, n=n: x+j for j in xrange(n)]
>>
> 
> But be careful using such a technique with mutable arguments...

What makes "this technique" more susceptible to mutable argument issues than
any other function or method-definition?

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


Re: which database is suitable for small applications

2009-05-26 Thread Jean-Michel Pichavant

Kalyan Chakravarthy wrote:

Hi All,
  can any one suggest me which database I can use for my small 
application(to store user names ,passwords, very few other data.. )
I am using Python, Google Apps and guide me how to connect to 
database, I am very new to these technologies


Please help me

Thanks in advance

--
Regards
Kalyan

If you are really new to these technologies and don't want to spend some 
time on it, just serialize on the disk your data structure containing 
your names, password and so on (http://docs.python.org/library/pickle.html).
Depending on your application you may not be that concerned with 
security/reliability issues.


Of course if you want to learn more about it, go on. I personally use 
postgreSQL with the pgdb python module. But this is the only one I ever 
used so I'll let someone else more familiar with all the database types 
respond to you.


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


Re: Are Python-based web frameworks reliable enough?

2009-05-26 Thread Bruno Desthuilliers

Gilles Ganault a écrit :

Hello

Until now, the modest web apps I wrote were all in PHP because it's
available on just about any hosted server.

I now have a couple of ideas for applications where I would deploy my
own servers, so that I'd rather write them in Python because I find
the language more pleasant to write with.

I read that the traction for the mod_python module isn't as strong as
mod_php, so I guess I should consider the alternative, which is
writing a long-running process with some framework like TurboGears or
Django.

To make an informed choice, I'd like your feedback on this:

1. Is mod_python a bad choice today? If yes, are there other PHP-like
modules available, ie. the Python code is hosted in pages that are
loaded every time a user calls them?


I indeed wouldn't use mod_python for web app development, unless I need 
really strong integration with apache and don't care for portability (=> 
 deploying on other web servers).


And while we're at it, the server page model (PHP etc) is just braindead 
for anything more complicated than a simple personal home page. FWIW, 
even PHP coders tend to go away from it and turn to more "structured" 
frameworks like Symfony or CakePHP - which look much more like Django, 
TG, Pylons or (for CakePHP) Ruby On Rails.



2. If you think I should consider long-running processes, are the
frameworks reliable enough so that I shouldn't fear crashes every so
often?


My experience is that they are usually much more reliable than most PHP 
code around.



3. What about performance as compared to equivalent PHP/MySQL apps?


The right question here would be "what about performances as compared to 
equivalent PHP apps of equivalent quality written using similar 
frameworks, deployed on equivalent web servers and getting equivalent 
loads".


Ok, to make a long story short: I never had any performance issues so 
far with app written in Django, and never heard of anyone reporting such 
issues. I whish I could say the same about Zope/Plone...

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


Re: Network programming ?

2009-05-26 Thread CTO
On May 25, 11:05 pm, thushiantha...@gmail.com wrote:
> Hi everyone,
>
> I am planning to develop a chatting software in Python, for my college
> project. I am using Windows Vista. Is it possible to do sockets
> programming in Python ? Any books or websites ?  Also, i want to
> develop a gui for that program. What are the gui tool kits available
> for windows? I already knew about PyGtk and PyQT, but will they work
> properly in Windows platform? Any suggestions?
>
> Thank you. Excuse my English.

There's a book called Foundations of Python Network Programming that
is
pretty much as good a book as you could ever ask for on the subject. I
strongly recommend it, and I think you'll find many of the examples
relevant.

As far as PyGTK and PyQT, my understanding is that they will work, but
require some effort. You may want to look at PyGUI, which I haven't
used
but have consistently heard good things about- they seem to have good
windows support.

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


Re: A list with periodic boundary conditions

2009-05-26 Thread youh...@googlemail.com

Rodhri,

thank you very much for your reply. I've tried to extend what you
suggested; I think it can be made to work, but you're right -- it gets
horrid rapidly. I'm at the start of what promises to be a large
project, and I want to make sure that I get my data structures right,
but my impression right now is that the memory efficiency of views is
negated by the computational complexity of their implementation. So I
think I will stick to copies and be done with it.

For the record, part of the reason I wanted a view was that my class
will be inherited from numpy.ndarray, where, by default, slices return
views.

Thanks again,

-AM

On 22 May, 00:20, "Rhodri James"  wrote:
> On Thu, 21 May 2009 13:08:39 +0100,  wrote:
> > Hi,
>
> > I'm trying to create a new class of list that has periodic boundary
> > conditions.
>
> > Here's what I have so far:
>
> > class wrappedList(list):
> >     def __getitem__(self, p):
> >         return list.__getitem__(self, p%len(self))
> >     def __setitem__(self, p, v):
> >         list.__setitem__(self, p%len(self), v)
>
> > a=wrappedList(range(10))
> > a[1]
> > 1
> > a[11]
> > 1
>
> > But I would also like to make slices. For instance I would like
> > a[8:11]
> > [8, 9, 0]
>
> > I can do it by copying, but I want to return a view to the original
> > data, and I have no idea where to start. It seems that the slice needs
> > to retain some knowledge of the list from which it derived. i.e. it
> > needs to know that it is a slice. Any ideas on how I can extend this
> > to allow views?
>
> Reading the docs, this looks like a very messy area of Python 2.x in
> that for a builtin like `list` you have to provide a __getslice__ method
> despite it being deprecated and only dealing with simple slices.  Good
> luck with that.  In Python 3, you just have to deal with the fact that
> your __getitem__ and __setitem__ `p` arguments can be slice objects
> instead of integers.
>
> If you're set on making your slices views on the original (which means
> that changes to the slice will change the original, unlike normal lists!)
> then you need to extend your class to remember what it's viewing, and
> what the start, stop and step of the slice were.  When it's a view, it
> passes (massaged) requests up to its parent.  There's a cute (but likely
> inefficient) way of doing this that uses the fact that your view is still
> a list under the hood, and stashes the parental indices in it.  This will
> also make len() work correctly, for a bonus :-)  It gets quite horrid
> quite fast, but here's a very incomplete untested skeleton:
>
> class wrappedList(list):
>    def __init__(self, parent=None, *args):
>      list.__init__(self, *args)
>      self.parent = parent
>
>    def __getitem__(self, p):
>      if self.parent is None:
>        self.primary_getitem(p)
>      else:
>        self.view_getitem(p)
>
>    def view_getitem(self, p):
>      return self.parent[list.__getitem__(self, p%len(self))]
>
> ...and similarly for __setitem__, where primary_getitem() is your
> previous __getitem__ method.  All four need to be modified to cope
> with slices, of course, and to create new wrappedList objects.
> Something like this:
>
>    if isinstance(p, slice):
>      if p.start is None:
>        start = 0
>      else:
>        start = p.start
>      if p.step is None:
>        step = 1
>      else:
>        step = p.step
>      indices = range(start, p.stop, step)
>      return wrappedList(indices, parent=self)
>
> This will go horribly, horribly wrong if you delete anything from
> your original list, but I can't off-hand think of a view method
> that won't.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

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


  1   2   >