Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Hendrik van Rooyen
On Thursday, 8 October 2009 18:41:31 Dr. Phillip M. Feldman wrote:
> I currently have a function that uses a list internally but then returns
> the list items as separate return
> values as follows:
>
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on).  Is there a cleaner way to accomplish the same thing?

Why do you not change the list into a tuple and return the tuple, and let 
automatic unpacking handle it?

As I see it, the problem is not in the return, but in the call - how do you 
know now, which of the following to write:

answer = thing(params)
answer0,answer1 = thing(params)
answer0,answer1,answer2 = thing(params)
answer0,answer1,answer2,answer3 = thing(params)

and so on...

probably best to write:

answers = thing(params)

for answer in answers:
do something with answer

- Hendrik

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


web sound recording with python

2009-10-08 Thread kernus
I need a web-based sound recording application and upload the sound
data to a web server (python cgi?).

the project is web voice search, so the web cgi would be a voice
search server.

any idea about the whole solution(web page and the python cgi)? thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Persistent Distributed Objects

2009-10-08 Thread John Haggerty
I am interested in seeing how it would be possible in python to have
persistent objects (basically be able to save objects midway through a
computation, etc) and do so across multiple computers.

Something that would allow for memory, disk space, processing power, etc to
be distributed across the nodes not just for number crunching.

So for example a warehouse program started up on 3 machines one for adding
orders, one for searching for orders, one for organizing the warehouse and
them running on a different machine with a single interface.

I've seen evidence about this being done wrt what looks like insanely
complex stuff on this list but I'm wondering if there is something to do
this with any number of nodes and just farm out random classes/objects to
them?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Simon Forman
On Thu, Oct 8, 2009 at 7:14 PM, Dr. Phillip M. Feldman
 wrote:
>
> I'm amazed that this works.  I had not realized that
>
> x,y= [3,4]
>
> is equivalent to
>
> x= 3; y= 4
>
> Python is rather clever.
>
> Thanks!
>

Python is very clever:

>>> (a, b), c = (1, 2), 3
>>> a, b, c
(1, 2, 3)

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Alan G Isaac

Dr. Phillip M. Feldman writes:

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?



The suggestions to return result
or if needed tuple(result) are good,
if a sequence is expected.

But perhaps better if each element has separate meaning:
return a defaultdict;
document the keys.
http://docs.python.org/library/collections.html#collections.defaultdict

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Robert Kern

Dr. Phillip M. Feldman wrote:

I'm amazed that this works.  I had not realized that

x,y= [3,4]

is equivalent to

x= 3; y= 4

Python is rather clever.

Thanks!



To elaborate on Paul's answer, returning the list will also unpack it if 
you have it set up that way.  E.g.


def func(alist):
return alist

some_list = [1, 2]
this, that = func(alist)

At least, in 2.5.4 this works.  :-)


In just about all Python versions for all sequence types, in fact.

Mind you, if you don't have the correct number of return names to match 
the unpacking you'll get the normal errors from that.


Yes. This is why people are suggesting that you be consistent about what you 
return. This is quite different from Matlab where the interpreter knows how many 
return values the caller is expecting in order to overload functions, but I 
think it makes for much more understandable code.


--
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: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Phillip M. Feldman
This is an interesting alternative.  If one wants to generate everything 
and return it at one shot, the list approach is better, but there are 
situations where generating things incrementally is preferrable, e.g., 
because the caller doesn't know a priori how many things he wants.  I 
will try this out.


Thanks!

Jack Norton wrote:

Dr. Phillip M. Feldman wrote:
I currently have a function that uses a list internally but then 
returns the

list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?
  

How about using yield and then iterate over the answer:

def some_fun():
\tfor result in some_loopable_stuff:
\t\t yield result

Then call it thusly:

for i in some_fun()
  result = i

-Jack (PS, sorry to the OP, you will get two of these -- I forgot to 
CC the list)




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


Re: datetime.datetime. or datetime. ?

2009-10-08 Thread Carl Banks
On Oct 8, 3:11 pm, niklasr  wrote:
> On Oct 8, 5:25 pm, "Diez B. Roggisch"  wrote:
>
>
>
>
>
> > NiklasRTZ schrieb:
>
> > > Hello, my basic question is which recommendation is after slight
> > > restructuring datetime.datetime to datetime
> > > Both works but only one should be chosen probably adjust my package to
> > > comply to dependencies.
> > > Spec integrated code where datetime.datetime.now() refactored to
> > > datetime.now()
> > > set rather
> > > from datetime import datetime, timedelta
> > > than
> > > import datetime
> > > or no matter and completely flexible (then why gae error that
> > > datetime.datetime wasn't datetime?)
> > > Naturally better not to customize external dependencies but seemingly
> > > impossible to use both for a little xmpp project.
> > > Thanks with best regards
>
> > Some remarks:
>
> >   - whitespace is significant. In python. And in posting here.
>
> >   - please show us the exact traceback you get, and a minimal example
> > that produces it.
>
> >   - how to import is mostly a matter of taste, as long as you refrain
> > from using "from datetime import *"e
>
> > Diez
>
> type object 'datetime.datetime' has no attribute 'datetime' Traceback
> (most recent call last):
> is flexible, both ways worked just that self complying towards more
> professional projects naturally feels right. Above error log seemingly
> caused by import datetime instead of from datetime import datetime.
> Then changed import and cut the first datetime occurance which looks
> good but breaks next sync with other. The project is the crowdguru
> xmpp chat test reachable via gae app "classifiedsmarket@
> {gmail,appspot}" currently importing
> from datetime import datetime, timedelta
> instead of
> import datetime
> Many thanks for the help and all further recommendation
> code disponible montao.googlecode.com- Hide quoted text -

When you do this:

  import datetime

you have to do this

  d = datetime.datetime()

And when you do this:

  from datetime import datetime

you have to do this:

  d = datetime()

You evidently did this:

  from datetime import datetime

then this:

  d = datetime.datetime()

which is not allowed.

If you want to self-comply, I recommend always doing it the first way.


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


Re: Sentiment analysis using Python

2009-10-08 Thread alex23
On Oct 9, 10:26 am, Henrik Lied  wrote:
> An experiment I'm currently involved with requires some form of texual
> analysis to figure out the "mood" of sentences (ergo, if the sentence
> in any way seem negative or positive).

I vaguely recall seeing a presentation on exactly this at an open
source con a few years back:

http://osdc2006.cgpublisher.com/proposals/73/index_html

The paper is available here:

http://maurice.vodien.com/unrefereed/OSDC06-MontyLingua.pdf

The "emotional estimation" aspect revolved mostly around Open Mind
Common Sense:

http://openmind.media.mit.edu/

Unfortunately, there are no code samples in the presentation, but you
may be able to approach the author, Maurice Ling.

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3.1 shell and Arrow Keys ?

2009-10-08 Thread Peter Billam
On 2009-10-08, casevh  wrote:
> On Oct 8, 2:47 pm, Peter Billam  wrote:
>> Greetings.  I've upgraded 3.0->3.1 and now my arrow-keys don't
>> work at the shell command-line, I just get:
>>   >>> ^[[A
>> etc. Is there some environment-variable or option I have to set ?
>> I'm using xterm on debian lenny, and compiled python3.1.1, as far
>> as I remember, just with sh configure, make, make install ...
>
> You probably need to install the readline-devel package. I
> don't use debian so I'm not sure of exact the package name.

Yes! it's
  aptitude install libreadline-dev
and that fixes the problem :-)

Thanks,  regards,  Peter

-- 
Peter Billam   www.pjb.com.auwww.pjb.com.au/comp/contact.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime.datetime. or datetime. ?

2009-10-08 Thread Gabriel Genellina

En Thu, 08 Oct 2009 19:11:04 -0300, niklasr  escribió:

On Oct 8, 5:25 pm, "Diez B. Roggisch"  wrote:

NiklasRTZ schrieb:



> Hello, my basic question is which recommendation is after slight
> restructuring datetime.datetime to datetime



  - how to import is mostly a matter of taste, as long as you refrain
from using "from datetime import *"e


type object 'datetime.datetime' has no attribute 'datetime' Traceback
(most recent call last):
is flexible, both ways worked just that self complying towards more
professional projects naturally feels right. Above error log seemingly
caused by import datetime instead of from datetime import datetime.


The datetime module doesn't contain anything useful apart from the five  
classes: date, time, datetime, timedelta and tzinfo. So using "from  
datetime import ..." is fine.



Then changed import and cut the first datetime occurance which looks
good but breaks next sync with other.


Just make sure to replace *all* occurrences of  "datetime.datetime" to  
"datetime", etc. Should be easy to do.

I don't know what you mean "breaks next sync with other".

--
Gabriel Genellina

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


Re: Sentiment analysis using Python

2009-10-08 Thread Paul Rubin
Henrik Lied  writes:
> Do any of you have experience with something equivalent, and perhaps
> some pointers on where I should go forward?

en.wikipedia.org/wiki/Latent_semantic_analysis  perhaps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Sentiment analysis using Python

2009-10-08 Thread Henrik Lied
Hi there,

An experiment I'm currently involved with requires some form of texual
analysis to figure out the "mood" of sentences (ergo, if the sentence
in any way seem negative or positive).

Do any of you have experience with something equivalent, and perhaps
some pointers on where I should go forward?

I've had some experience with Naive Bayes in the past, but I assume
the training would be colossal (I've got texts in the thousands to
examine).


Any tips appreciated!
-- Henrik L.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python3.1 shell and Arrow Keys ?

2009-10-08 Thread casevh
On Oct 8, 2:47 pm, Peter Billam  wrote:
> Greetings.  I've upgraded 3.0->3.1 and now my arrow-keys don't work
> at the shell command-line, I just get:
>   >>> ^[[A
> etc. Is there some environment-variable or option I have to set ?
> I'm using xterm on debian lenny, and compiled python3.1.1, as far
> as I remember, just with sh configure, make, make install ...
>
> Regards,  Peter
>
> --
> Peter Billam      www.pjb.com.au   www.pjb.com.au/comp/contact.html

You probably need to install the readline-devel package. I don't use
debian so I'm not sure of exact the package name.

HTH,

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


Re: datetime.datetime. or datetime. ?

2009-10-08 Thread Diez B. Roggisch

niklasr schrieb:

On Oct 8, 5:25 pm, "Diez B. Roggisch"  wrote:

NiklasRTZ schrieb:


Hello, my basic question is which recommendation is after slight
restructuring datetime.datetime to datetime
Both works but only one should be chosen probably adjust my package to
comply to dependencies.
Spec integrated code where datetime.datetime.now() refactored to
datetime.now()
set rather
from datetime import datetime, timedelta
than
import datetime
or no matter and completely flexible (then why gae error that
datetime.datetime wasn't datetime?)
Naturally better not to customize external dependencies but seemingly
impossible to use both for a little xmpp project.
Thanks with best regards

Some remarks:

  - whitespace is significant. In python. And in posting here.

  - please show us the exact traceback you get, and a minimal example
that produces it.

  - how to import is mostly a matter of taste, as long as you refrain
from using "from datetime import *"e

Diez


type object 'datetime.datetime' has no attribute 'datetime' Traceback
(most recent call last):
is flexible, both ways worked just that self complying towards more
professional projects naturally feels right. Above error log seemingly
caused by import datetime instead of from datetime import datetime.
Then changed import and cut the first datetime occurance which looks
good but breaks next sync with other. The project is the crowdguru
xmpp chat test reachable via gae app "classifiedsmarket@
{gmail,appspot}" currently importing
from datetime import datetime, timedelta
instead of
import datetime
Many thanks for the help and all further recommendation
code disponible montao.googlecode.com


I'm sorry, but this gibberish is beyond what I'm willing to decipher. 
Good luck with somebody else doing so & helping you.


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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Dr. Phillip M. Feldman

I'm amazed that this works.  I had not realized that

x,y= [3,4]

is equivalent to

x= 3; y= 4

Python is rather clever.

Thanks!



To elaborate on Paul's answer, returning the list will also unpack it if 
you have it set up that way.  E.g.

def func(alist):
return alist

some_list = [1, 2]
this, that = func(alist)

At least, in 2.5.4 this works.  :-)

Mind you, if you don't have the correct number of return names to match 
the unpacking you'll get the normal errors from that.

Hope this helps!

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



-- 
View this message in context: 
http://www.nabble.com/Is-there-a-better-way-to-code-variable-number-of-return-arguments--tp25803294p25813206.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: datetime.datetime. or datetime. ?

2009-10-08 Thread niklasr
On Oct 8, 5:25 pm, "Diez B. Roggisch"  wrote:
> NiklasRTZ schrieb:
>
> > Hello, my basic question is which recommendation is after slight
> > restructuring datetime.datetime to datetime
> > Both works but only one should be chosen probably adjust my package to
> > comply to dependencies.
> > Spec integrated code where datetime.datetime.now() refactored to
> > datetime.now()
> > set rather
> > from datetime import datetime, timedelta
> > than
> > import datetime
> > or no matter and completely flexible (then why gae error that
> > datetime.datetime wasn't datetime?)
> > Naturally better not to customize external dependencies but seemingly
> > impossible to use both for a little xmpp project.
> > Thanks with best regards
>
> Some remarks:
>
>   - whitespace is significant. In python. And in posting here.
>
>   - please show us the exact traceback you get, and a minimal example
> that produces it.
>
>   - how to import is mostly a matter of taste, as long as you refrain
> from using "from datetime import *"e
>
> Diez

type object 'datetime.datetime' has no attribute 'datetime' Traceback
(most recent call last):
is flexible, both ways worked just that self complying towards more
professional projects naturally feels right. Above error log seemingly
caused by import datetime instead of from datetime import datetime.
Then changed import and cut the first datetime occurance which looks
good but breaks next sync with other. The project is the crowdguru
xmpp chat test reachable via gae app "classifiedsmarket@
{gmail,appspot}" currently importing
from datetime import datetime, timedelta
instead of
import datetime
Many thanks for the help and all further recommendation
code disponible montao.googlecode.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading hex to int from a binary string

2009-10-08 Thread Luc
On Oct 8, 11:13 pm, "Diez B. Roggisch"  wrote:
> Luc schrieb:
>
> > Hi all,
>
> > I read data from a binary stream, so I get hex values as characters
> > (in a string) with escaped x, like "\x05\x88", instead of 0x05.
>
> > I am looking for a clean way to add these two values and turn them
> > into an integer, knowing that calling int() with base 16 throws an
> > invalid literal exception.
>
> > Any help appreciated, thanks.
>
> Consider this (in the python interpreter):
>
>  >>> chr(255)
> '\xff'
>  >>> chr(255) == r"\xff"
> False
>  >>> int(r"ff", 16)
> 255
>
> In other words: no, you *don't* get hex values. You get bytes from the
> stream "as is", with python resorting to printing these out (in the
> interpreter!!!) as "\xXX". Python does that so that binary data will
> always have a "pretty" output when being inspected on the REPL.
>
> But they are bytes, and to convert them to an integer, you call "ord" on
> them.
>
> So assuming your string is read bytewise into two variables a & b, this
> is your desired code:
>
>  >>> a = "\xff"
>  >>> b = "\xa0"
>  >>> ord(a) + ord(b)
> 415
>
> HTH, Diez

Sorry I was not clear enough. When I said "add", I meant concatenate
because I want to read 0x0588 as one value and ord() does not allow
that.

However you pointed me in the right direction and I found that int
(binascii.hexlify(a + b, 16)) does the job.

Thanks.

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


python3.1 shell and Arrow Keys ?

2009-10-08 Thread Peter Billam
Greetings.  I've upgraded 3.0->3.1 and now my arrow-keys don't work
at the shell command-line, I just get:
  >>> ^[[A
etc. Is there some environment-variable or option I have to set ?
I'm using xterm on debian lenny, and compiled python3.1.1, as far
as I remember, just with sh configure, make, make install ...

Regards,  Peter

-- 
Peter Billam   www.pjb.com.auwww.pjb.com.au/comp/contact.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-08 Thread John Yeung
On Oct 6, 4:10 pm, Stef Mientki  wrote:
>
> thanks guys,
> mx works a bit better  

Another popular Python date library is dateutil:

  http://labix.org/python-dateutil

It gives a certain amount of credit to mxDateTime (praising it but not
being very clear how they are related; there is some mention of "using
the specification" of mxDateTime).

I would say mxDateTime and dateutil are the two heavyweights in this
arena.  As you would expect, they have a lot of overlapping
functionality and which one is used is often just a matter of taste,
or whichever one you happened to find first.

One thing that dateutil provides that mxDateTime doesn't is support
for "lay person" month operations.  That is, as far as I can tell,
mxDateTime tries not to dirty itself with the messy business of month
arithmetic, whereas dateutil rolls up its sleeves and takes an honest
stab at it.  If you are writing a calendar/appointment application, or
other end-user-facing program, I would expect dateutil to be a little
more helpful.

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


Re: datetime.datetime. or datetime. ?

2009-10-08 Thread Diez B. Roggisch

NiklasRTZ schrieb:

Hello, my basic question is which recommendation is after slight
restructuring datetime.datetime to datetime
Both works but only one should be chosen probably adjust my package to
comply to dependencies.
Spec integrated code where datetime.datetime.now() refactored to
datetime.now()
set rather
from datetime import datetime, timedelta
than
import datetime
or no matter and completely flexible (then why gae error that
datetime.datetime wasn't datetime?)
Naturally better not to customize external dependencies but seemingly
impossible to use both for a little xmpp project.
Thanks with best regards



Some remarks:

 - whitespace is significant. In python. And in posting here.

 - please show us the exact traceback you get, and a minimal example 
that produces it.


 - how to import is mostly a matter of taste, as long as you refrain 
from using "from datetime import *"e


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


datetime.datetime. or datetime. ?

2009-10-08 Thread NiklasRTZ
Hello, my basic question is which recommendation is after slight
restructuring datetime.datetime to datetime
Both works but only one should be chosen probably adjust my package to
comply to dependencies.
Spec integrated code where datetime.datetime.now() refactored to
datetime.now()
set rather
from datetime import datetime, timedelta
than
import datetime
or no matter and completely flexible (then why gae error that
datetime.datetime wasn't datetime?)
Naturally better not to customize external dependencies but seemingly
impossible to use both for a little xmpp project.
Thanks with best regards
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading hex to int from a binary string

2009-10-08 Thread Diez B. Roggisch

Luc schrieb:

Hi all,

I read data from a binary stream, so I get hex values as characters
(in a string) with escaped x, like "\x05\x88", instead of 0x05.

I am looking for a clean way to add these two values and turn them
into an integer, knowing that calling int() with base 16 throws an
invalid literal exception.

Any help appreciated, thanks.


Consider this (in the python interpreter):

>>> chr(255)
'\xff'
>>> chr(255) == r"\xff"
False
>>> int(r"ff", 16)
255

In other words: no, you *don't* get hex values. You get bytes from the 
stream "as is", with python resorting to printing these out (in the 
interpreter!!!) as "\xXX". Python does that so that binary data will 
always have a "pretty" output when being inspected on the REPL.


But they are bytes, and to convert them to an integer, you call "ord" on 
them.


So assuming your string is read bytewise into two variables a & b, this 
is your desired code:


>>> a = "\xff"
>>> b = "\xa0"
>>> ord(a) + ord(b)
415


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


Re: trouble with regex?

2009-10-08 Thread Paul McGuire
On Oct 8, 11:42 am, MRAB  wrote:
> inhahe wrote:
> > Can someone tell me why this doesn't work?
>
> > colorre = re.compile ('('
> >                         '^'
> >                        '|'
> >                         '(?:'
> >                            '\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
> >                            '(?:'
> >                               ',(?:10|11|12|13|14|15|0\\d|\\d)'
> >                            ')?'
> >                         ')'
> >                       ')(.*?)')
>
> > I'm trying to extract mirc color codes.
>

You might find this site interesting (http://utilitymill.com/utility/
Regex_For_Range) to generate RE's for numeric ranges.

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


Re: Multiprocessing.Array bug / shared numpy array

2009-10-08 Thread Robert Kern

On 2009-10-08 15:14 PM, Felix wrote:


I am trying to create a shared, read-only numpy.ndarray between
several processes. After some googling the basic idea is:

sarr = mp.Array('i',1000)
ndarr = scipy.frombuffer(sarr._obj,dtype='int32')

Since it will be read only (after being filled once in a single
process) I don't think I need any locking mechanism. However is this
really true given garbage collection, reference counts and other
implicit things going on?

Or is there a recommended better way to do this?


I recommend using memory-mapped arrays for such a purpose.

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

  http://www.scipy.org/Mailing_Lists

--
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: mktime, how to handle dates before 01-01-1970 ?

2009-10-08 Thread John Yeung
On Oct 6, 5:11 pm, Christian Heimes  wrote:
> Ben Finney wrote:
> > If you're committed to changing the epoch anyway, I would recommend
> > using http://en.wikipedia.org/wiki/Astronomical_year_numbering>
> > (epoch at 4004 BCE) since it is widely used to unify dates referring to
> > human history.
>
> I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long
> before or after the unix epoch. The conversion from JDN as float to a
> datetime object is trivial.

I think the choice of epoch is not a big deal, once you pick one far
enough back.  Ben Finney's suggestion to use 4004 BCE is not
appreciably different (computationally) from JDN.  (Though I will say
that the Wikipedia link he provided doesn't mention 4004 BCE, and if
anything suggests using 1 CE as the epoch.)

If there is any difficulty, it would be determining whether historical
records used (for example) the Julian calendar or Gregorian.  This
doesn't seem to be a factor for the OP's use case, so my
recommendation would be to just pick whatever's convenient (either
because some library or program uses it, or because it makes intuitive
sense to the programmer).

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


Re: Unofficial Python GIS SIG

2009-10-08 Thread Aahz
In article <07bd0443-5e60-4661-b03d-1db1b5de6...@k4g2000yqb.googlegroups.com>,
seang   wrote:
>On Oct 1, 9:49=A0pm, a...@pythoncraft.com (Aahz) wrote:
>> 
>> Any particular reason you didn't create a list @python.org?
>
>Only that I am not entirely sure this will take off and don't want to
>leave python.org with a defunct list, and I'm unfamiliar with what's
>involved with starting a list on python.org. A Google group seemed low
>risk. There's fairly good sign-up so far. Am I alienating anybody by
>not going with python.org?

Dunno, but I don't use mailing lists on google.com.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --re...@lion.austin.ibm.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread w.g.sned...@gmail.com
On Oct 8, 2:12 pm, Dave Angel  wrote:
> bsneddon wrote:
> > I saw an issue  on winXP  box not connected to internet yesterday,
> > where i was running
> > a script in the interactive window on PythonWin .   I would modify the
> > script save and
> > import and was still running the old version.  I did that several
> > times with same result.
> > I even renamed the function and it showed up but ran the old script.
> > Very strange.
> > 
>
> Caching (not cashing) doesn't come into play here.  Objects are kept as
> long as there is a reference to them somewhere.  So renamed functions
> can still exist under their old name, since nobody has reused the name
> for something newer.
>
> I'm not familiar with PythonWin.  But if it's like the standard python
> interpreter, where you use import at the command line to load a module,
> then I can comment on it.
>
> Doing a second import on the same module will not look at the disk file
> at all.  To get it to re-read the source code, you need reload().  And
> reload() doesn't really do everything you'd expect.  In some cases it
> cannot (for example, references to external DLL's).  So there are
> frequently remnants of the earlier version of things lying around.
>
> If this is really an interpreter environment, I'd exit the environment
> and start it again.   If it's more like a GUI (like Komodo, which I
> use), then the gui will kill the old interpreter and start another one
> when you say "exit" and "run".   Then you have nothing left of the old
> version of the module, and can start from scratch.
>
> As Simon said, you should read about reload(), and its caveats:
>    http://docs.python.org/library/functions.html#reload
>
> DaveA

Thanks I have looked at reload now.  It seem pythonWin tries to use
reload
when doing an import.  I think I need to do a little more reading on
PythonWin.

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


Re: del an imported Class at EOF... why?

2009-10-08 Thread Terry Reedy

Terry Reedy wrote:

Hans Mulder wrote:


Errrhm, no.  He is not deleting the PyQt4 module from sys.modules;
he's only deleting the name QtGui from his own namespace.  Next
time Python comes across

from PyQt4 import QtGui

, it finds that the module PyQt4 already exists in sys.modules, so
Python does not have to load the module again.  All it has to do is
bind name QtGui in the importing module to the class with the same
name in the PyQt4 module.  That does not take many cycles.


I recently discovered that when IDLE restarts (as when one runs a file 
from an edit window), it clears the global namespace but does not clear 
sys.modules. Hence re-running a script that does time-consuming imports 
is much faster, as only the global name binding is done after the first 
run.


Whoops, on rechecking, above does not seem to be true. The faster rerun 
time I was seeing was due to some other cause. Sorry for the noise.



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


extract oracle-BLOBs to the file system (9.2.0.7): some docs not readable

2009-10-08 Thread Mark Dellon
Dear colleges,

I read BLOBs from oracle database and write these in a loop to a the file 
system. 
Some documents (e.g.PDF) are not correct and I can't open these.

Database size of these blobs is different to size on the file system.

Which code I should use for readig blob from oracle database?
Need I to use chunks?
Where is the problem please?

MY CODE:

sys.dbc = cx_Oracle.connect("user/passw...@db")

sys.csr.execute('SELECT blob FROM BLOB_TABLE')
aSQLData = sys.csr.fetchone()
aLob = aSQLData[0]
aLobData = aLob.read() #this is type str 

f = open ("c:\\tmp\\test.pdf","wb" )
f.write(aLobData)
f.close()


Thank you very much for every idea.

Best regards

Mark
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiprocessing.Array bug / shared numpy array

2009-10-08 Thread Felix
Hi,

The documentation for the Multiprocessing.Array says:

multiprocessing.Array(typecode_or_type, size_or_initializer, *,
lock=True)¶

...
If lock is False then access to the returned object will not be
automatically protected by a lock, so it will not necessarily be
“process-safe”.
...

However:
In [48]: mp.Array('i',1,lock=False)
---
AssertionErrorTraceback (most recent call
last)

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
multiprocessing/__init__.pyc in Array(typecode_or_type,
size_or_initializer, **kwds)
252 '''
253 from multiprocessing.sharedctypes import Array
--> 254 return Array(typecode_or_type, size_or_initializer,
**kwds)
255
256 #


/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
multiprocessing/sharedctypes.pyc in Array(typecode_or_type,
size_or_initializer, **kwds)
 85 if lock is None:
 86 lock = RLock()
---> 87 assert hasattr(lock, 'acquire')
 88 return synchronized(obj, lock)
 89

AssertionError:

---
I.e. it looks like lock=false is not actually supported. Or am I
reading this wrong? If not, I can submit a bug report.


I am trying to create a shared, read-only numpy.ndarray between
several processes. After some googling the basic idea is:

sarr = mp.Array('i',1000)
ndarr = scipy.frombuffer(sarr._obj,dtype='int32')

Since it will be read only (after being filled once in a single
process) I don't think I need any locking mechanism. However is this
really true given garbage collection, reference counts and other
implicit things going on?

Or is there a recommended better way to do this?

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


Re: del an imported Class at EOF... why?

2009-10-08 Thread Terry Reedy

Simon Forman wrote:

On Thu, Oct 8, 2009 at 1:42 AM, Terry Reedy  wrote:

Hans Mulder wrote:


Errrhm, no.  He is not deleting the PyQt4 module from sys.modules;
he's only deleting the name QtGui from his own namespace.  Next
time Python comes across

   from PyQt4 import QtGui

, it finds that the module PyQt4 already exists in sys.modules, so
Python does not have to load the module again.  All it has to do is
bind name QtGui in the importing module to the class with the same
name in the PyQt4 module.  That does not take many cycles.

I recently discovered that when IDLE restarts (as when one runs a file from
an edit window), it clears the global namespace but does not clear
sys.modules. Hence re-running a script that does time-consuming imports is
much faster, as only the global name binding is done after the first run.


Is that with or without '-n'?


The Windows start menu IDLE entry, which I gather is without -n, though 
the property sheet does not actually give the command-line equivalent.


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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Jack Norton

Dr. Phillip M. Feldman wrote:

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?
  

How about using yield and then iterate over the answer:

def some_fun():
\tfor result in some_loopable_stuff:
\t\t yield result

Then call it thusly:

for i in some_fun()
  result = i

-Jack (PS, sorry to the OP, you will get two of these -- I forgot to CC 
the list)

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


Re: windows side-by-side configuration woes on windows HPC

2009-10-08 Thread M.-A. Lemburg
Nick Touran wrote:
> Copying my local copy of Python 2.6 to a Windows HPC 2008 system is giving
> dll side-by-side configuration errors for some third-party packages
> (matplotlib, pyMSSQL, in particular). I understand that there is a tradition
> of Python supporting XCOPY deployment, and would really like to be able to
> just copy my C:\python26 folder to the network drive and have it run on the
> server.
> 
> I got around a related issue (http://bugs.python.org/issue4566) just by
> upgrading to 2.6.3 and was able to import socket and mpi4py and everything,
> except matplotlib and pyMSSQL, that is.
> 
> I also understand that if I were to install the MS Visual Studio 2008
> redistribution package on the server that everything would be fine because
> the modules just can't find the proper C run-time DLL. The problem with that
> is two-fold: I don't have admin rights on the machine and there are over
> 1000 machines on the cluster and I don't think the admin is going to install
> that on all of them.
> 
> So is there any way to set an environmental variable or something to get
> these packages to know where to find the proper msvcr90.dll, akin to setting
> LD_LIBRARY_PATH in Linux? Is there another solution?

I assume this is related to this new problem:

http://bugs.python.org/issue4120

Manifests were meant to solve some of the DLL mess... apparently they
cause even more grief.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Oct 08 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-08 Thread Stef Mientki

Stephen Hansen wrote:


Personally, while /users/ may write a date in a lazy way like 
"01-01-53", I'd never store that and would avoid having them enter 
them directly. At the UI level I'd validate and normalize it to a 
standard format before storing it.



yes I agree, but the data is coming from all kind of programs,
some more than 10 years old.
E.g. instead of users entering someone's birthday into a control, I'd 
use a calendar control, and store it with (in wx terms) 
date.FormatISODate(). Or use date.toString(ISODate) in QT terms (ish).

I don't know your age,
but with my age it takes hours to look up my birthday on a windows 
calender control ;-)


cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is pythonic version of scanf() or sscanf() planned?

2009-10-08 Thread Terry Reedy

ryniek90 wrote:

On 6 Paź, 06:37, Dennis Lee Bieber  wrote:

On Sun, 4 Oct 2009 15:48:16 -0700 (PDT), TerryP 
declaimed the following in gmane.comp.python.general:


In the last 4 years, I have never missed functions like .*scanf() or
atoi().
It's probably a greeaaat thing that Python provides nether as built
ins (per se).

Uhm... Isn't the second one spelled "int()" 
--
Wulfraed Dennis Lee Bieber   KD6MOG
wlfr...@ix.netcom.com  HTTP://wlfraed.home.netcom.com/




Ok thanks all for answers. Not counting .split() methods and regexps,
there's nothing interesting.
But I remember that lambda function also was unwelcome in Python, but
finally it is and is doing well. So maybe someone, someday decide to
put in Python an alternative, really great implementation of scanf() ?


scanf does three things: parses string fields out of text, optionally 
converts strings to numbers, and puts the results into pointed-to boxes. 
Since Python does not have pointer types, a python function cannot very 
well do the last, but has to return the tuple of objects. However, if a 
format string has named rather than positional fields, a Python function 
could either return a dict or set sttributes on an object. That could be 
useful.


If I were doing this, I would look into using the new str.format() 
strings rather than %-formatted strings.



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


Re: Multiprocessing.Queue deadlock

2009-10-08 Thread Felix Schlesinger
On Oct 8, 3:21 am, Dennis Lee Bieber  wrote:
> On Wed, 7 Oct 2009 10:24:08 -0700 (PDT), Felix Schlesinger
> > A bunch of workers push an unknown number of results into a queue. The
> > main process needs to collect all those results.
>
> > What is the right way to implement that with multiprocessing? I tried
> > joining the workers and then reading everything available, but
> > obviously (see above) that does not seem to work.
>
>         The cleanest solution that I can think of is to have the processes
> return a special token which identifies WHICH process is terminating, so
> you can join just that one, and go back and continue looking for data
> from the others.

I implemented the lazy version of this, namely waiting until all
workers signal that they are done (reading results until I encounter
the right number of 'done' tokens'. And only after that joining all
workers.). I think this is stable, but I am not an expert on the
issue.
Putting 'done' is always the last call to queue.put a worker makes.
Does that guarantee that it will not block after 'done' is read by the
main process?

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


Re: A new Internet-search website written in Python

2009-10-08 Thread Aahz
In article <7xocor1pii@ruckus.brouhaha.com>,
Paul Rubin   wrote:
>"hrg...@gmail.com"  writes:
>>
>> The purpose of this email is to inform the Python-list mailing-list
>> subscribers of an Internet-search website that is run by software
>> written in Python.
>
>Is the software downloadable?  If not, why should anyone here care
>what language it is written in?

Same reason we care what language YouTube is written in.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --re...@lion.austin.ibm.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sftp login without password

2009-10-08 Thread David
Il Tue, 06 Oct 2009 12:26:34 -0800, Joshua Kugler ha scritto:

> David wrote:
>> transport.connect(username = username, pkey = mykey)
>> 
>> I get a "AuthenticationException: Authentication failed." exception.
>> 
>> 
>> My ~/.ssh/id_rsa is correct because if, at console, I type
>> 
>> bags...@bagvapp:~$ sftp bags...@192.168.92.129
>> Connecting to 192.168.92.129...
>> sftp>
>> 
>> I get a successful login. How can I get an sftp login without using a
>> password in python?
>> I am using Ubuntu 9.04, python 2.6.2 and paramiko 1.7.5
> 
> What is the contents of 'mykey'?  Is it a file object? A string containing
> the contents of ~/.ssh/id_rsa? The Paramiko docs indicate mykey should be a
> subclass of PKey, probably RSAKey.
> 
> So, you'd need to do:
> 
> mykey = RSAKey.from_private_key_file('/path/to/private/key/id_rsa')
> transport.connect(username = username, pkey = mykey)

That's exactly what I did (as clearly explained in the tutorial) but doesn't
work.

> 
> Beyond that, I"m not sure.  Of course, I've never used Paramiko before.

Can you suggest an alternative way to connect to an sftp server without
using a passoword in python? 

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


Re: load_dynamic(_name_, path)

2009-10-08 Thread MRAB

jim-on-linux wrote:

Python help,

In win32api line 10 is written:
 mod = imp.load_dynamic(__name__, path)

traceback;
ImportError: DLL load failed:  The specified module 
could not be found.


import imp is available,
Where does 
load_dynamic(__name__, path) 
come from?



The traceback is saying that it couldn't find the DLL you're trying to
load. Is the path you're giving correct? Does it point to a DLL?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Neural networks in python

2009-10-08 Thread ruchir
On Oct 8, 1:21 pm, Raymond Hettinger  wrote:
> On Oct 7, 10:53 pm, ruchir  wrote:
>
> > I want to design and train a neural network in python. Can anyone
> > guide me, from where can I get some useful material/eBook/libraries
> > etc. for the same. I have no prior experience in neural netwoks and
> > want to implement it urgently.
> > Thanks in advance :)
>
> Take a look athttp://code.activestate.com/recipes/496908/
>
> Raymond

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


Re: Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread Dave Angel

bsneddon wrote:

I saw an issue  on winXP  box not connected to internet yesterday,
where i was running
a script in the interactive window on PythonWin .   I would modify the
script save and
import and was still running the old version.  I did that several
times with same result.
I even renamed the function and it showed up but ran the old script.
Very strange.

  

Caching (not cashing) doesn't come into play here.  Objects are kept as 
long as there is a reference to them somewhere.  So renamed functions 
can still exist under their old name, since nobody has reused the name 
for something newer.


I'm not familiar with PythonWin.  But if it's like the standard python 
interpreter, where you use import at the command line to load a module, 
then I can comment on it.


Doing a second import on the same module will not look at the disk file 
at all.  To get it to re-read the source code, you need reload().  And 
reload() doesn't really do everything you'd expect.  In some cases it 
cannot (for example, references to external DLL's).  So there are 
frequently remnants of the earlier version of things lying around.


If this is really an interpreter environment, I'd exit the environment 
and start it again.   If it's more like a GUI (like Komodo, which I 
use), then the gui will kill the old interpreter and start another one 
when you say "exit" and "run".   Then you have nothing left of the old 
version of the module, and can start from scratch.


As Simon said, you should read about reload(), and its caveats:
  http://docs.python.org/library/functions.html#reload



DaveA

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


Re: Problem Displaying Pics

2009-10-08 Thread Victor Subervi
I have come to the conclusion that this has absolutely nothing to do with
the code. The problem is eNom. I have had so many problems with this
provider specifically concerning their python interpreter that I actually
filed a complaint against them with the BBB, which they still didn't
resolve. Now that I'm back in the states and making money, I've bought space
on another server that I'm building. Let me spend my time building that, and
I believe all these silly problems will go away. I will start a new thread
if I'm wrong. Thank you all for your help!
V

On Thu, Oct 8, 2009 at 11:43 AM, Gabriel Genellina
wrote:

> En Thu, 08 Oct 2009 12:30:16 -0300, Victor Subervi <
> victorsube...@gmail.com> escribió:
>
>  http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1
>>
>> On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury > >wrote:
>>
>>  On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <
>>> victorsube...@gmail.com> wrote:
>>>
>>>  print 'Content-Type: image/jpeg'
>>>
 print 'Content-Encoding: base64'
 print
 print content.encode('base64')

>>>
> Are you sure this is your actual code?
>
> py> import urllib
> py> data = urllib.urlopen("
> http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1";).read()
> py> data[:30]
> 'Content-Encoding: base64\n\n\n/9j'
> py> data[-30:]
> 'XdjTJvaaF5fvfMVgbUM+gatZXFzb\n\n'
>
> 1) The Content-Encoding line is taken as part of the response entity (the
> picture data), but should be part of the header. I bet you have a blank line
> after Content-Type.
> 2) Note the \n\n at the end
>
> py> data = data[27:-2]
> py> decoded = data.decode("base64")
> py> open("test.jpg","wb").write(decoded)
>
> I tried to open test.jpg, but it's corrupt.
>
> py> len(decoded)
> 65535
> py> decoded[:30]
> '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1
> \xadExif\x00\x00'
>
> Very suspicious file size... Looks like a jpeg image that was truncated at
> that size. See whether it is already corrupt in the database and repair it
> (you're using a data type large enough to hold the image, aren't you?)
>
> After fixing the database, you can omit the unnecesary base64 encoding;
> anyway I'd add a Content-Length header to avoid that spurious \n at the end.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best vi / emacs python features

2009-10-08 Thread TerryP
> But in actual practice you use a space cadets editor like Vim.
>
>                                         Ross Ridge

Actually by space cadets editor, I meant needing one of these:
http://en.wikipedia.org/wiki/Space_cadet_keyboard

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Ethan Furman

Paul Rubin wrote:

Ethan Furman  writes:


some_list = [1, 2]
this, that = func(alist)

At least, in 2.5.4 this works.  :-)



But that fails if there are fewer than two elements in the list.  It's
better to just make the logic either expect a list, or if it's
implementing something like an optional value, code it up explicitly.
You may even want to return two lists, the second one possibly empty.


It also fails if there are more than two elements in the list, as the 
rest of my post went on to say.  I myself would generally not use such a 
structure, but that doesn't mean the OP doesn't have a good use case for 
it.  Don't forget, his original question indicated that there could be 
more than two return elements also.


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


load_dynamic(_name_, path)

2009-10-08 Thread jim-on-linux
Python help,

In win32api line 10 is written:
 mod = imp.load_dynamic(__name__, path)

traceback;
ImportError: DLL load failed:  The specified module 
could not be found.

import imp is available,
Where does 
load_dynamic(__name__, path) 
come from?

jim-on-linux
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Paul Rubin
Ethan Furman  writes:
> some_list = [1, 2]
> this, that = func(alist)
> 
> At least, in 2.5.4 this works.  :-)

But that fails if there are fewer than two elements in the list.  It's
better to just make the logic either expect a list, or if it's
implementing something like an optional value, code it up explicitly.
You may even want to return two lists, the second one possibly empty.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is pythonic version of scanf() or sscanf() planned?

2009-10-08 Thread Simon Brunning
2009/10/8 ryniek90 :
> Ok thanks all for answers. Not counting .split() methods and regexps,
> there's nothing interesting.
> But I remember that lambda function also was unwelcome in Python, but
> finally it is and is doing well. So maybe someone, someday decide to
> put in Python an alternative, really great implementation of scanf() ?

Write one, post it on Google Code, the Python cookbook or somewhere,
and if the world beats a path to your door then we'll talk.

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


Re: How to run python script in emacs

2009-10-08 Thread Chris

> if you want, i can suggest you some lines for the init file .emacs,
> in order to keep the text indented with 4 spaces, no tab at all (very
> important).

I would be interest in the .emacs changes for python mode.


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


Re: Tkinter -- the best way to make a realtime loop

2009-10-08 Thread J Wolfe
Thank you both for your replies.  I had something similar to this:

def incr():
  var.set(1 + var.get())
  root.after(1000, incr)

except I had an extra set of parenthesis...
def incr():
  var.set(1 + var.get())
  root.after(1000, incr())

on the function which was screwing it up. Also needed to have a
root.update() to refresh the GUI.

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


Re: threading module, call thread.interrupt_main()

2009-10-08 Thread Gabriel Genellina
En Thu, 08 Oct 2009 00:33:04 -0300, §äŽmŠÛ€vªº...@€ù€Ñ  
 escribió:



Sorry to ask, but i don't know how to solve it.


No need to apologize!

I try to call thread.interrupt_main() function in my child thread's run  
method

which is inherit threading.Thread class.

But it didn't work, does anyone know why?


Are you join()ing your child thread? In this case the main thread won't  
acknowledge the exception until the join() call returns -- probably too  
late. A sleep() call isn't interruptible either.


I think it's already reported at http://bugs.python.org but I can't locate  
the issue right now.


--
Gabriel Genellina

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


Re: threading module, call thread.interrupt_main()

2009-10-08 Thread Gabriel Genellina
En Thu, 08 Oct 2009 00:33:04 -0300, §äŽmŠÛ€vªº...@€ù€Ñ  
 escribió:



Sorry to ask, but i don't know how to solve it.


No need to apologize!

I try to call thread.interrupt_main() function in my child thread's run  
method

which is inherit threading.Thread class.

But it didn't work, does anyone know why?


Are you join()ing your child thread? In this case the main thread won't  
acknowledge the exception until the join() call returns -- probably too  
late. A sleep() call isn't interruptible either.


I think it's already reported at http://bugs.python.org but I can't locate  
the issue right now.


--
Gabriel Genellina

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Ethan Furman

Dr. Phillip M. Feldman wrote:

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?


To elaborate on Paul's answer, returning the list will also unpack it if 
you have it set up that way.  E.g.


def func(alist):
   return alist

some_list = [1, 2]
this, that = func(alist)

At least, in 2.5.4 this works.  :-)

Mind you, if you don't have the correct number of return names to match 
the unpacking you'll get the normal errors from that.


Hope this helps!

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


windows side-by-side configuration woes on windows HPC

2009-10-08 Thread Nick Touran
Copying my local copy of Python 2.6 to a Windows HPC 2008 system is giving
dll side-by-side configuration errors for some third-party packages
(matplotlib, pyMSSQL, in particular). I understand that there is a tradition
of Python supporting XCOPY deployment, and would really like to be able to
just copy my C:\python26 folder to the network drive and have it run on the
server.

I got around a related issue (http://bugs.python.org/issue4566) just by
upgrading to 2.6.3 and was able to import socket and mpi4py and everything,
except matplotlib and pyMSSQL, that is.

I also understand that if I were to install the MS Visual Studio 2008
redistribution package on the server that everything would be fine because
the modules just can't find the proper C run-time DLL. The problem with that
is two-fold: I don't have admin rights on the machine and there are over
1000 machines on the cluster and I don't think the admin is going to install
that on all of them.

So is there any way to set an environmental variable or something to get
these packages to know where to find the proper msvcr90.dll, akin to setting
LD_LIBRARY_PATH in Linux? Is there another solution?

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Simon Forman
On Thu, Oct 8, 2009 at 12:41 PM, Dr. Phillip M. Feldman
 wrote:
>
> I currently have a function that uses a list internally but then returns the
> list items as separate return
> values as follows:
>
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on).  Is there a cleaner way to accomplish the same thing?

It kind of depends on how the caller of your function handles the return values.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Jean-Michel Pichavant

Dr. Phillip M. Feldman wrote:

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?
  


return tuple(result)

But you down want to do that, cause the caller will have a hell of a job 
getting your result. You may want to simply return the list itself.


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


Re: best vi / emacs python features

2009-10-08 Thread Ross Ridge
TerryP   wrote:
>ed -- I can quickly edit files without having to wait on an ncurses
>app to start up. Although I rarely have access to GNU versions of ed,
>they use readline which is a big perk when you make a typo.

I used to fallback on ed when network connections got really slow and
I could log in using Telnet line-mode, but it's been a long time since
the I could tell the difference between the start up time of any editor.
They all, ed, nvi or GNU emacs, start up instantaneously for me.

>nvi -- smaller and faster then vim, works great over slow ssh links or
>when editing huge files. I like nvi over the original vi, because most
>of the limitations of the old-school vi are removed; unlimited undo is
>the best feature added.

I like nvi because by default it's quirk for quirk compatible with the
original vi, including single-level undo.  (Well at least until they
screwed things up with the new file/input encoding scheme.)

>EDIT.COM -- much faster then notepad over remote connections, and it
>understands both DOS and UNIX end of lines; meaning I can skip
>converting formats, the only downside is it's still a 16-bit program.

I use MS-DOS Editor from time to time, but mainly because it means I
don't have to change window focus.

>I am a freak: I do not use nor want syntax highlighting. I don't want
>my editor to understand mail, irc, or the www either, I want it to
>edit text efficiently so I can go on with the rest of my life as soon
>as possible. Given the choice of using a space cadets editor like
>emacs or something primitive one like ed, I would choose *ed* just to
>speed things up and save on wrist strain.

But in actual practice you use a space cadets editor like Vim.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  rri...@csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Christian Heimes
Dr. Phillip M. Feldman schrieb:
> I currently have a function that uses a list internally but then returns the
> list items as separate return
> values as follows:
> 
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
> 
> (and so on).  Is there a cleaner way to accomplish the same thing?

You can simply "return result". If you want to make sure that you return
a copy of the internal list, do "return list(result)" or "return
tuple(result)".

Christian

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


Re: Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread Simon Forman
On Thu, Oct 8, 2009 at 9:47 AM, bsneddon  wrote:
> I saw an issue  on winXP  box not connected to internet yesterday,
> where i was running
> a script in the interactive window on PythonWin .   I would modify the
> script save and
> import and was still running the old version.  I did that several
> times with same result.
> I even renamed the function and it showed up but ran the old script.
> Very strange.
>
> I tried reproducing this morning on a machine that is connected to
> internet was unable to
> but did get the behavior below that I do not understand.
>
> created module named spam with this code.
> def ello():
>    print "Your father smells of elderberrys"
>
> Here is expert for interactive window to explain the issue: question
> is below.
>
> PythonWin 2.6 (r26:66721, Oct  2 2008, 11:35:03)
> I
>
>
> renamed ello to insult and re-imported.
>
 dir(spam)
> [clip.. 'ello', 'insult']
>
> ello still exist in namespace an runs ... not so strange
 spam.ello()
> Your father smells of elderberrys
>
 del(spam)
> delete spam and it no longer runs as expected.
>
> modify insult to this:
> def insult():
>    print "Your father smells of elderberrys/n and your mother was a
> kiniggit"
>
> Q.
> on re-importing spam ello is back and continues to run.   I did note
> expect this to be the
> case.  Can someone explain what is happening?
>
 dir(spam)
> [clip..., 'ello', 'insult']
 spam.ello()
> Your father smells of elderberrys
 spam.insult()
> Your father smells of elderberrys/n and your mother was a kiniggit

>
>
> Thanks for your help.
>
> Bill Sneddon

The reload() function might be what you need:
http://docs.python.org/library/functions.html#reload

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


Re: Is there a better way to code variable number of return arguments?

2009-10-08 Thread Paul Rubin
"Dr. Phillip M. Feldman"  writes:
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
> 
> (and so on).  Is there a cleaner way to accomplish the same thing?

That is poor style.  Just return the result as a list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem Displaying Pics

2009-10-08 Thread Gabriel Genellina
En Thu, 08 Oct 2009 12:30:16 -0300, Victor Subervi  
 escribió:



http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1

On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury  
wrote:



On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <
victorsube...@gmail.com> wrote:

 print 'Content-Type: image/jpeg'

print 'Content-Encoding: base64'
print
print content.encode('base64')


Are you sure this is your actual code?

py> import urllib
py> data =  
urllib.urlopen("http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1";).read()

py> data[:30]
'Content-Encoding: base64\n\n\n/9j'
py> data[-30:]
'XdjTJvaaF5fvfMVgbUM+gatZXFzb\n\n'

1) The Content-Encoding line is taken as part of the response entity (the  
picture data), but should be part of the header. I bet you have a blank  
line after Content-Type.

2) Note the \n\n at the end

py> data = data[27:-2]
py> decoded = data.decode("base64")
py> open("test.jpg","wb").write(decoded)

I tried to open test.jpg, but it's corrupt.

py> len(decoded)
65535
py> decoded[:30]
'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1  
\xadExif\x00\x00'


Very suspicious file size... Looks like a jpeg image that was truncated at  
that size. See whether it is already corrupt in the database and repair it  
(you're using a data type large enough to hold the image, aren't you?)


After fixing the database, you can omit the unnecesary base64 encoding;  
anyway I'd add a Content-Length header to avoid that spurious \n at the  
end.


--
Gabriel Genellina

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


Re: trouble with regex?

2009-10-08 Thread MRAB

inhahe wrote:

Can someone tell me why this doesn't work?

colorre = re.compile ('('
'^'
   '|'
'(?:'
   '\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
   '(?:'
  ',(?:10|11|12|13|14|15|0\\d|\\d)'
   ')?'
')'
  ')(.*?)')

I'm trying to extract mirc color codes.

this works:

colorre = re.compile ('\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
  '(?:'
 ',(?:10|11|12|13|14|15|0\\d|\\d)'
  ')?'
  )

but I wanted to modify it so that it returns me groups of (color code, 
text after the code), except for the first text at the beginning of the 
string before any color code, for which it should return ('', text). 
that's what the first paste above is trying to do, but it doesn't work. 
here are some results:


 >>> colorre.findall('a\x0b1,1')
[('', ''), ('\x0b1,1', '')]
 >>> colorre.findall('a\x0b1,1b')
[('', ''), ('\x0b1,1', '')]
 >>> colorre.findall('ab')
[('', '')]
 >>> colorre.findall('\x0b1,1')
[('', '')]
 >>> colorre.findall('\x0b1,1a')
[('', '')]
 >>>

i can easily work with the string that does work and just use group 
starting and ending positions, but i'm curious as to why i can't get it 
working teh way i want :/



The problem with the regex is that .*? is a lazy repeat: it'll try to
match as few characters as possible, which is why the second group is
always ''. Try a greedy repeat instead, but matching only
non-backspaces:

colorre = re.compile('('
   '^'
  '|'
   '(?:'
  '\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
  '(?:'
 ',(?:10|11|12|13|14|15|0\\d|\\d)'
  ')?'
   ')'
 ')([^\x0b]*)')
--
http://mail.python.org/mailman/listinfo/python-list


Is there a better way to code variable number of return arguments?

2009-10-08 Thread Dr. Phillip M. Feldman

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on).  Is there a cleaner way to accomplish the same thing?
-- 
View this message in context: 
http://www.nabble.com/Is-there-a-better-way-to-code-variable-number-of-return-arguments--tp25803294p25803294.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: threading module, call thread.interrupt_main()

2009-10-08 Thread Simon Forman
2009/10/7 找尋自己的一片天 :
> Sorry to ask, but i don't know how to solve it.
>
> I try to call thread.interrupt_main() function in my child thread's run method
> which is inherit threading.Thread class.
>
> But it didn't work, does anyone know why?
>
> Thanks a lot!!
>

"it didn't work" is not enough information.

What is your code (smallest version that shows the problem)?

And what is the traceback?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: del an imported Class at EOF... why?

2009-10-08 Thread Simon Forman
On Thu, Oct 8, 2009 at 1:42 AM, Terry Reedy  wrote:
> Hans Mulder wrote:
>
>> Errrhm, no.  He is not deleting the PyQt4 module from sys.modules;
>> he's only deleting the name QtGui from his own namespace.  Next
>> time Python comes across
>>
>>    from PyQt4 import QtGui
>>
>> , it finds that the module PyQt4 already exists in sys.modules, so
>> Python does not have to load the module again.  All it has to do is
>> bind name QtGui in the importing module to the class with the same
>> name in the PyQt4 module.  That does not take many cycles.
>
> I recently discovered that when IDLE restarts (as when one runs a file from
> an edit window), it clears the global namespace but does not clear
> sys.modules. Hence re-running a script that does time-consuming imports is
> much faster, as only the global name binding is done after the first run.

Is that with or without '-n'?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is pythonic version of scanf() or sscanf() planned?

2009-10-08 Thread Ben Sizer
On Oct 3, 11:06 pm, ryniek90  wrote:
> Hi
>
> I know that in python, we can do the same with regexps or *.split()*,
> but thats longer and less practical method than *scanf()*. I also found
> that (http://code.activestate.com/recipes/502213/), but the code
> doesn't looks so simple for beginners. So, whether it is or has been
> planned the core Python implementation of *scanf()* ? (prefered as a
> batteries included method)

Perhaps struct.unpack is close to what you need? Admittedly that
doesn't read from a file, but that might not be a problem in most
cases.

--
Ben Sizer


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


trouble with regex?

2009-10-08 Thread inhahe
Can someone tell me why this doesn't work?
colorre = re.compile ('('
'^'
   '|'
'(?:'
   '\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
   '(?:'
  ',(?:10|11|12|13|14|15|0\\d|\\d)'
   ')?'
')'
  ')(.*?)')

I'm trying to extract mirc color codes.

this works:

colorre = re.compile ('\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
  '(?:'
 ',(?:10|11|12|13|14|15|0\\d|\\d)'
  ')?'
  )

but I wanted to modify it so that it returns me groups of (color code, text
after the code), except for the first text at the beginning of the string
before any color code, for which it should return ('', text). that's what
the first paste above is trying to do, but it doesn't work. here are some
results:

>>> colorre.findall('a\x0b1,1')
[('', ''), ('\x0b1,1', '')]
>>> colorre.findall('a\x0b1,1b')
[('', ''), ('\x0b1,1', '')]
>>> colorre.findall('ab')
[('', '')]
>>> colorre.findall('\x0b1,1')
[('', '')]
>>> colorre.findall('\x0b1,1a')
[('', '')]
>>>

i can easily work with the string that does work and just use group starting
and ending positions, but i'm curious as to why i can't get it working teh
way i want :/
-- 
http://mail.python.org/mailman/listinfo/python-list


transparent splash screen

2009-10-08 Thread NighterNet
I been looking for simple way to create a transparent splash screen.
Using gif,png,jpg just by loading the file into it. Using version
3.1.1 Any help would be nice.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Testoob 1.15 released

2009-10-08 Thread oripel
Testoob is the advanced Python test runner and testing framework that
spices up any existing unittest test suite.

Home: http://code.google.com/p/testoob

Version 1.15 (Oct. 2009) adds better Python 2.6, IronPython, and
Jython support, as well as test coverage improvements, better color
support, and some new options and bugfixes. *nix and Windows are fully
supported.

Installation options:
 * 'easy_install -U testoob'
 * One of the packages at http://code.google.com/p/testoob/downloads/list

This version wouldn't have been possible without the help of Ronnie
van 't Westeinde.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best vi / emacs python features

2009-10-08 Thread Falcolas
On Oct 8, 7:23 am, Jean-Michel Pichavant 
wrote:
> Chris Jones wrote:
> > On Wed, Oct 07, 2009 at 07:06:08PM EDT, TerryP wrote:
>
> > [..]
>
> >> I am a freak: I do not use nor want syntax highlighting. I don't want
> >> my editor to understand mail, irc, or the www either, I want it to
> >> edit text efficiently so I can go on with the rest of my life as soon
> >> as possible. Given the choice of using a space cadets editor like
> >> emacs or something primitive one like ed, I would choose *ed* just to
> >> speed things up and save on wrist strain. Before I read a tutorial
> >> about vi, I used XEmacs very happily---vi just lines up better with
> >> how my brain works.
>
> >> --
>
> >> It is also general consensus that I am nuts ;)
>
> > I don't think so.
>
> > Always felt that syntax highlighting for instance is way overrated.  Haven't
> > tried "ed" yet, but since I have already stripped down my everything to what
> > I thought was minimal, now that you mention it, this may be where I'm bound.
>
> > I do have a question:
>
> > You mentioned Vim's clientserver mode.
>
> > What's it good for?
>
> > Thanks,
>
> > CJ
>
> Strange how things can differ from one person to another. Syntax
> highlighting is the feature I'm missing the most when I'm using pure vi.
> Looks like some are getting annoyed by it, I think it provides useful
> and meaningful informations through colors.
>
> JM

I have found that syntax hilighting is useful, as long as it isn't
overwhelming. Zenburn is a great highlighting scheme which is fairly
easy on the eyes to use (no startling colors anywhere), yet the
differences are enough for me to quickly pick out syntax elements.

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


Nested Menus

2009-10-08 Thread Victor Subervi
Hi;
I have the following code:
  sql = 'create table if not exists categories (ID int(3) unsigned primary
key, Category varchar(40), Parent varchar(40))'
  cursor.execute(sql)
  cursor.execute('select Category, Parent from categories;')
  data = cursor.fetchall()
  parents = []
  Parents = []
  for dat in data:
if dat[1] not in parents:
  parents.append(dat[1])
Categories.append(dat[0])
Parents.append(dat[1])
  Parents.sort()
  families = []
  for parent in Parents:
children = []
for dat in data:
  if dat[0] == parent:
children.append(dat[1])
families.append([parent, children])

Now, what I want to do is to capture all nested categories, such that if x
is the parent of y who is the parent of z, etc., I can print out the entire
family tree. I'm at a loss as to how to do it! Please advise.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Ulrich Eckhardt wrote:
> No, as this one doesn't give me a handle to the thread. I also find this
> barely readable, for sure it doesn't beat the readability of the proposed
> function.

Roll your own convenient function, though. :) At work we have this short
function in our tool box:

def daemonthread(target, name=None, autostart=True, args=(), kwargs=None):
"""Start a thread as daemonic thread
"""
thread = Thread(target=target, name=name, args=args, kwargs=kwargs)
thread.setDaemon(True)
if autostart:
thread.start()
return thread

Christian

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


Re: best vi / emacs python features

2009-10-08 Thread edexter
On Oct 7, 10:07 am, OdarR  wrote:
> hello,
>
> * this is not a troll *
>
> which kind of help you have with your favorite editor ?
>
> personnally, I find emacs very nice, in the current state of my
> knowledge, when I need to reindent the code.
> you know how this is critical in python...:-)
>
> I don't use other python-mode features for the moment, maybe you have
> some advices.
> I used with success an Xemacs on Solaris, as well as a Aquamacs on
> Mac.
>
> For the vi/vim guys, explain us the best features this editor give you
> in your py files !
>
> thanks,
>
> Olivier

I like alot of the features of both on gvim they show white space
symbols but I find both emacs and gvim a pain to extend
and I need to find a key word and then  hilight columns so because of
the complexity it has become rich edit vs scintilla..
I wrote my own syntax highlighter for rich edit 2 for csound but not
with all the complexity I am planning later..  jedit looked
very intresting but I haven't figured out the output window yet they
do have python embeded well jython anyway (like gvim does)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Hendrik van Rooyen wrote:
> What does the Threading module buy me, other than a formal OO approach?

* the interpreter won't know about your thread when you bypass the
threading module and use the thread module directly. The thread isn't in
the list of active threads and the interpreter is unable to wait for the
thread to exit when Python shuts down. All threads created by the thread
module behave like daemonic threads.

* exception reporting doesn't work with thread.start_new_thread

* profiling and tracing doesn't work with thread.start_new_thread

* introspection of active thread doesn't work because threads started by
thread.start_new_thread are invisible for the rest of the interpreter

* you have to roll your own system to join a thread

* probably more stuff

In Python 3.0 the thread module has been renamed to _thread in order to
reflect the nature of the C extension.

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


Re: Problem Displaying Pics

2009-10-08 Thread Victor Subervi
http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1
TIA,
V

On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury wrote:

> On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <
> victorsube...@gmail.com> wrote:
>
>  print 'Content-Type: image/jpeg'
>> print 'Content-Encoding: base64'
>> print
>> print content.encode('base64')
>>
>> I did change it to text/plain, but I don't know how I'm supposed to
>> manually
>> decode it. Yes, it printed out a bunch of crap to the screen. I've gotten
>> that far before, and once I read "Adobe" something, so yes, it's an image.
>> TIA,
>> V
>>
>>
> Hopefully the 'crap' you're getting is the base64-encoded representation of
> your binary image -- you should be able to use Python to decode that, and
> then use any image viewer to verify that the JPEG is sound.
>
> Can you remind us of the URL where that code (with the text/plain content
> type) is running?
>
>
>
>  On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury > >wrote:
>>
>>  On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi <
>>> victorsube...@gmail.com> wrote:
>>>
>>>  I did that. In fact, just to make things easier, I wrote out exactly
>>> what
>>>
 is
 supposed to be rendered, as below:

 #!/usr/local/bin/python
 import cgitb; cgitb.enable()
 import MySQLdb
 import cgi
 import sys,os
 sys.path.append(os.getcwd())
 from login import login
 user, passwd, db, host = login()
 form = cgi.FieldStorage()
 db = MySQLdb.connect(host, user, passwd, db)
 cursor= db.cursor()
 sql = "select pic1 from products where id='1';"
 cursor.execute(sql)
 content = cursor.fetchall()[0][0].tostring()
 cursor.close()
 print '''Content-Type: image/jpeg'''# Only print one line

 Content-Encoding: base64
 '''
 print
 print content.encode('base64')


  Just to reiterate what Gabriel and Carsten have pointed out, I'd
>>> suggest
>>> changing the last few lines of the script, as the comments below
>>> indicate:
>>>
>>> print '''Content-Type: image/jpeg''' # One header line
>>> print '''Content-Encoding: base64''' # Another header line. Note *no*
>>> blank
>>> line between them
>>> print# Blank line signals the end of the
>>> headers
>>> print content.encode(base64) # Base64-encoded content comes
>>> *after*
>>> the blank line
>>>
>>> If you include extra blank lines after the headers, the browser will
>>> misunderstand where the binary image data begins, and so will see a
>>> malformed JPEG.
>>>
>>> If this doesn't work, I suggest changing the content-type header to
>>> text/plain and trying to manually decode and check the image data to
>>> ensure
>>> it's valid.
>>>
>>>
>>>
>>>  On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina <
 gagsl-...@yahoo.com.ar
 >wrote:

  En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi

>  escribió:
>
> > print '''Content-Type: image/jpeg
> >
> > '''
> > print
> > print content
>
> On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina  p...@yahoo.com.ar>wrote:
>
> > That's still wrong. The output should be:
> >
> > - a line containing Content-Type: image/jpeg
> > - a blank line (no more!)
>   ^
> > - the actual image data
>
> --
> Gabriel Genellina
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
>>>
>>> --
>>> Rami Chowdhury
>>> "Never attribute to malice that which can be attributed to stupidity" --
>>> Hanlon's Razor
>>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>>>
>>>
>
>
> --
> Rami Chowdhury
> "Never attribute to malice that which can be attributed to stupidity" --
> Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Hendrik van Rooyen
On Thursday, 8 October 2009 13:24:14 Christian Heimes wrote:
> Laszlo Nagy wrote:
> > But really thread.start_new_thread is better:
> >
> > import thread.start_new_thread as thr
> >
> > thr(my_function,arg1,arg2)
>
> Please don't use the thread module directly, especially the
> start_new_thread function. It a low level function that bypasses the
> threading framework. The is no good reason to use this function in favor
> of threading.Thread().

I have seen this advice a couple of times now, and I do not understand it.

>From my perspective (which is admittedly jaundiced) Threading just adds a 
bunch of superfluous stuff like a run method and other weird things that I 
cannot see a need for.

The simplicity of this kind of code:

def this_is_a_thread(arg1,arg2):
do_some_initialisation(arg1,arg2)
while some_condition:
do_some_stuff()

which then gets started with thread.start_new_thread, does it for me.

What does the Threading module buy me, other than a formal OO approach?

- Hendrik



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


Re: Is pythonic version of scanf() or sscanf() planned?

2009-10-08 Thread ryniek90
On 6 Paź, 06:37, Dennis Lee Bieber  wrote:
> On Sun, 4 Oct 2009 15:48:16 -0700 (PDT), TerryP 
> declaimed the following in gmane.comp.python.general:
>
> > In the last 4 years, I have never missed functions like .*scanf() or
> > atoi().
>
> > It's probably a greeaaat thing that Python provides nether as built
> > ins (per se).
>
>         Uhm... Isn't the second one spelled "int()" 
> --
>         Wulfraed         Dennis Lee Bieber               KD6MOG
>         wlfr...@ix.netcom.com      HTTP://wlfraed.home.netcom.com/



Ok thanks all for answers. Not counting .split() methods and regexps,
there's nothing interesting.
But I remember that lambda function also was unwelcome in Python, but
finally it is and is doing well. So maybe someone, someday decide to
put in Python an alternative, really great implementation of scanf() ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python + webservice

2009-10-08 Thread Fred Chevitarese
Hello again!!

Now i'm reading the documentation... If i got doubts, i ask here!

Thanks ;)

On Oct 8, 10:50 am, Fred  Chevitarese  wrote:
> First of all, thanks for these replies...
> Someone has an example of python + suds generating a XML and consuming
> a webservice or, in suds documentation has one?
>
> Thanks again ;)
>
> On Oct 8, 8:32 am, Jakob Kristensen  wrote:
>
>
>
> > Ralf Schoenian wrote:
> > > > Has anyone made something like this and can share with me a bit of
> > > > experience?
>
> > > Did you try sudshttps://fedorahosted.org/suds?I'vegot good results
> > > with this library.
>
> > > Ralf
>
> > After working with both ZSI and Suds, i must say i've had by far the
> > best experiences with Suds. It's very light-weight compared to ZSI
> > (which by no means is light-weighted).

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


Re: Python + webservice

2009-10-08 Thread Fred Chevitarese
First of all, thanks for these replies...
Someone has an example of python + suds generating a XML and consuming
a webservice or, in suds documentation has one?

Thanks again ;)



On Oct 8, 8:32 am, Jakob Kristensen  wrote:
> Ralf Schoenian wrote:
> > > Has anyone made something like this and can share with me a bit of
> > > experience?
>
> > Did you try sudshttps://fedorahosted.org/suds?I've got good results
> > with this library.
>
> > Ralf
>
> After working with both ZSI and Suds, i must say i've had by far the
> best experiences with Suds. It's very light-weight compared to ZSI
> (which by no means is light-weighted).

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


Cashing in PythonWin name space?... seems unexpected to me

2009-10-08 Thread bsneddon
I saw an issue  on winXP  box not connected to internet yesterday,
where i was running
a script in the interactive window on PythonWin .   I would modify the
script save and
import and was still running the old version.  I did that several
times with same result.
I even renamed the function and it showed up but ran the old script.
Very strange.

I tried reproducing this morning on a machine that is connected to
internet was unable to
but did get the behavior below that I do not understand.

created module named spam with this code.
def ello():
print "Your father smells of elderberrys"

Here is expert for interactive window to explain the issue: question
is below.

PythonWin 2.6 (r26:66721, Oct  2 2008, 11:35:03)
I


renamed ello to insult and re-imported.

>>> dir(spam)
[clip.. 'ello', 'insult']

ello still exist in namespace an runs ... not so strange
>>> spam.ello()
Your father smells of elderberrys

>>> del(spam)
delete spam and it no longer runs as expected.

modify insult to this:
def insult():
print "Your father smells of elderberrys/n and your mother was a
kiniggit"

Q.
on re-importing spam ello is back and continues to run.   I did note
expect this to be the
case.  Can someone explain what is happening?

>>> dir(spam)
[clip..., 'ello', 'insult']
>>> spam.ello()
Your father smells of elderberrys
>>> spam.insult()
Your father smells of elderberrys/n and your mother was a kiniggit
>>>


Thanks for your help.

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


Re: cpython compilation parameter

2009-10-08 Thread Diez B. Roggisch
cEd wrote:

> Hello,
> 
> I'm wondering how to compile python to get good performance.
> Because when I compare this ugly code which find prime number:
> 
> # prime_number.py
> start=3
> for is_first in range(start):
>  found = 0
>  is_first+=1
>  for i in range (2, is_first):
>   if not (is_first%(i)):
>found = 1
>break
>  if not found:
>   print is_first
> 
> 
>  between :
>  - the python distributed with my ubuntu
> #time python prime_number.py > /dev/null
> real0m12.237s
> user0m12.129s
> sys0m0.024s
> 
>  - and the one compiled by my self
> time my_python_compiled prime_number.py > /dev/null
> real0m42.193s
> user0m41.891s
> sys0m0.044s
> 
> so which option should I give or which flag ???

I doubt that there is such a flag. There must be a different reason for
this. Can you give us the python versions for each, and architecture (32/64
bit)?

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


cpython compilation parameter

2009-10-08 Thread cEd
Hello,

I'm wondering how to compile python to get good performance.
Because when I compare this ugly code which find prime number:

# prime_number.py
start=3
for is_first in range(start):
 found = 0
 is_first+=1
 for i in range (2, is_first):
  if not (is_first%(i)):
   found = 1
   break
 if not found:
  print is_first


 between :
 - the python distributed with my ubuntu
#time python prime_number.py > /dev/null
real0m12.237s
user0m12.129s
sys0m0.024s

 - and the one compiled by my self
time my_python_compiled prime_number.py > /dev/null
real0m42.193s
user0m41.891s
sys0m0.044s

so which option should I give or which flag ???

regards

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


Re: When ‘super’ is not a good id ea

2009-10-08 Thread Jean-Michel Pichavant

alex23 wrote:

Jean-Michel Pichavant  wrote:
  

alex23 wrote:


To me, the explicit reference to the base class violates DRY. It also
means you need to manually change all such references should the base
class ever change, something that using super() avoids.
  

I found the correct answer
(http://www.artima.com/weblogs/viewpost.jsp?thread=236275)



I'm not entirely sure how an opinion + explanation of the underlying
mechanics is more or less "correct" than a development principle...
  
The correctness applies to my answer, not the super mechanism. The super 
mechanism is correct and properly documented since python 2.6, so anyone 
is free to use it.
I'm just trying to give arguments in favor of using the explicit base 
class name instead of super.


And in my opinion, explicit names are (slightly) better because there's 
no underlying explanation required when using the base class name 
instead of super.


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


Re: best vi / emacs python features

2009-10-08 Thread Jean-Michel Pichavant

Chris Jones wrote:

On Wed, Oct 07, 2009 at 07:06:08PM EDT, TerryP wrote:

[..]

  

I am a freak: I do not use nor want syntax highlighting. I don't want
my editor to understand mail, irc, or the www either, I want it to
edit text efficiently so I can go on with the rest of my life as soon
as possible. Given the choice of using a space cadets editor like
emacs or something primitive one like ed, I would choose *ed* just to
speed things up and save on wrist strain. Before I read a tutorial
about vi, I used XEmacs very happily---vi just lines up better with
how my brain works.

--

It is also general consensus that I am nuts ;)



I don't think so. 


Always felt that syntax highlighting for instance is way overrated.  Haven't
tried "ed" yet, but since I have already stripped down my everything to what
I thought was minimal, now that you mention it, this may be where I'm bound.

I do have a question: 

You mentioned Vim's clientserver mode. 


What's it good for?

Thanks,

CJ
  
Strange how things can differ from one person to another. Syntax 
highlighting is the feature I'm missing the most when I'm using pure vi. 
Looks like some are getting annoyed by it, I think it provides useful 
and meaningful informations through colors.


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


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Ulrich Eckhardt
Laszlo Nagy wrote:
> Ulrich Eckhardt írta:
>> Hi!
>>
>> I'm looking at the 'threading' module and see that other than the
>> 'thread' module it doesn't have a simple function to start a new thread.
>> Instead, you first have to instantiate a threading object and then start
>> the new thread on it:
>>
>>   t = threading.Thread(target=my_function)
>>   t.start()
>>
>> What I'm wondering is if following function wouldn't be a good addition
>> to the threading module:
>>
>>   def start_new_thread(target, ..):
>>   t = Thread(target, ..)
>>   t.start()
>>   return t
> What is wrong with thread.start_new_thread ?

The 'thread' module is more or less deprecated.

> At least it supports function arguments. Your suggested addition would
> only useful if you want to start argument-less functions in separate
> threads, from multiple places in a module.

To quote from my own posting:
 | Note: I left out the additional parameters for brevity, but they
 | should of course be forwarded, but the 'target' parameter is not
 | optional as it is with Thread's constructor.

No, this is supposed to support function arguments, too.

> You can use this one-liner:
> 
> import threading.Thread as thr
> 
> thr(target=my_function).start()

No, as this one doesn't give me a handle to the thread. I also find this
barely readable, for sure it doesn't beat the readability of the proposed
function.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Ulrich Eckhardt
sturlamolden wrote:
> On 8 Okt, 09:17, Ulrich Eckhardt  wrote:
> 
>> I'm looking at the 'threading' module and see that other than the
>> 'thread' module it doesn't have a simple function to start a new thread.
>> Instead, you first have to instantiate a threading object and then start
>> the new thread on it:
>>
>> t = threading.Thread(target=my_function)
>> t.start()
> 
> One usually want to subclass threading.Thread instead of specifying a
> target function.

No. You also don't derive from a file class in order to read a file. The
point is that the Thread instance is not a thread but it is an object that
can be used to access a thread, similar to a File instance which file which
is not the file but just an object to access one.

I personally find it much cleaner this way. Also, why should any code care
in which thread it is executed? Why should I have to derive a class from
some other only because I want to run one of its functions in a separate
thread?

I don't want to start a discussion which principle is better, that would
only end in endless discussions, but I'd like to point out that the
principle of deriving from a thread class is not universally accepted. ;)

Cheers!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Python + webservice

2009-10-08 Thread Jakob Kristensen
Ralf Schoenian wrote:
> > Has anyone made something like this and can share with me a bit of
> > experience?
>
> Did you try sudshttps://fedorahosted.org/suds? I've got good results
> with this library.
>
> Ralf

After working with both ZSI and Suds, i must say i've had by far the
best experiences with Suds. It's very light-weight compared to ZSI
(which by no means is light-weighted).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Christian Heimes
Laszlo Nagy wrote:
> But really thread.start_new_thread is better:
> 
> import thread.start_new_thread as thr
> 
> thr(my_function,arg1,arg2)

Please don't use the thread module directly, especially the
start_new_thread function. It a low level function that bypasses the
threading framework. The is no good reason to use this function in favor
of threading.Thread().

Christian

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


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread sturlamolden
On 8 Okt, 09:17, Ulrich Eckhardt  wrote:

> I'm looking at the 'threading' module and see that other than the 'thread'
> module it doesn't have a simple function to start a new thread. Instead,
> you first have to instantiate a threading object and then start the new
> thread on it:
>
>   t = threading.Thread(target=my_function)
>   t.start()

One usually want to subclass threading.Thread instead of specifying a
target function.

class mythread(threading.Thread):

def run():
# whatever
pass

t = mythread()
t.start()

Also, you may want to set the daemon flag before starting the thread,
which is why the thread is created in a suspended state.















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


Re: No threading.start_new_thread(), useful addition?

2009-10-08 Thread Laszlo Nagy

Ulrich Eckhardt írta:

Hi!

I'm looking at the 'threading' module and see that other than the 'thread'
module it doesn't have a simple function to start a new thread. Instead,
you first have to instantiate a threading object and then start the new
thread on it:

  t = threading.Thread(target=my_function)
  t.start()

What I'm wondering is if following function wouldn't be a good addition to
the threading module:

  def start_new_thread(target, ..):
  t = Thread(target, ..)
  t.start()
  return t
What is wrong with thread.start_new_thread ? At least it supports 
function arguments. Your suggested addition would only useful if you 
want to start argument-less functions in separate threads, from multiple 
places in a module. This is quite special, not general enough to make 
the suggested change. You can use this one-liner:


import threading.Thread as thr

thr(target=my_function).start()


But really thread.start_new_thread is better:

import thread.start_new_thread as thr

thr(my_function,arg1,arg2)

Best,

  Laci


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


Re: data matrix python

2009-10-08 Thread lallous

Hello

Try re-asking your question in a more general way so that users w/o 
background information (about those classes and modules you're using) can 
help you with your problem.


--
Elias
 wrote in message 
news:mailman.968.1254922056.2807.python-l...@python.org...

Good morning all!

I am trying to build a data matrix, but I am not able either to write  to 
file with a proper structure nor to get the data from the matrix.


I want to sort some music by similarity content, and I just have the 
indexes of the playlist like this:


dm = numpy.array(songs)

[0 4 2 1 3]
[1 2 0 4 3]
[2 1 0 4 3]
[3 2 1 0 4]
[4 0 1 2 3]

Now, I want to keep the same format but with the names of the songs, 
something like this:


Sort_dm.append(songlist(dm))

['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n'
 '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n'
 '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n'
 '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3'
 '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']

But there is no way either I can access to the data... because there  are 
strings, or save them in matrix format! I could not find anything  in the 
documentation about this! any hint would be very welcome! thank  you for 
your time!


Best regards,
Bea Mora



This message was sent using IMP, the Internet Messaging Program. 


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


Re: .pyc from stdin?

2009-10-08 Thread lallous

Hello Shay,

"Shay Telfer"  wrote in message 
news:mailman.1021.1254988413.2807.python-l...@python.org...

Hi...

It seems that python will accept a .py file piped from stdin, but not a 
.pyc file (and there don't seem to be any flags to allow this). Am I 
missing something?


Eg

cat blah.py | python

works, but

cat blah.pyc | python



Try for example: python -c "import blah"


doesn't. (If you're wondering why anyone would do this it's because I'm 
actually intending to use curl rather than cat :)




The former works because the Python interpreter understands python syntax, 
and when you (in the latter case) provide the interpreter a pyc file it 
surely won't work because it does not understand those compiled bytes just 
like that


--
Elias 


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


Re: .pyc from stdin?

2009-10-08 Thread lallous

Hello Shay,

"Shay Telfer"  wrote in message 
news:mailman.1021.1254988413.2807.python-l...@python.org...

Hi...

It seems that python will accept a .py file piped from stdin, but not a 
.pyc file (and there don't seem to be any flags to allow this). Am I 
missing something?


Eg

cat blah.py | python

works, but

cat blah.pyc | python



Try for example: python -c "import blah"


doesn't. (If you're wondering why anyone would do this it's because I'm 
actually intending to use curl rather than cat :)




The former works because the Python interpreter understands python syntax, 
and when you (in the latter case) provide the interpreter a pyc file it 
surely won't work because it does not understand those compiled bytes just 
like that


--
Elias 


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


Re: .pyc from stdin?

2009-10-08 Thread lallous

Hello Shay,

"Shay Telfer"  wrote in message 
news:mailman.1021.1254988413.2807.python-l...@python.org...

Hi...

It seems that python will accept a .py file piped from stdin, but not a 
.pyc file (and there don't seem to be any flags to allow this). Am I 
missing something?


Eg

cat blah.py | python

works, but

cat blah.pyc | python



Try for example: python -c "import blah"


doesn't. (If you're wondering why anyone would do this it's because I'm 
actually intending to use curl rather than cat :)




The former works because the Python interpreter understands python syntax, 
and when you (in the latter case) provide the interpreter a pyc file it 
surely won't work because it does not understand those compiled bytes just 
like that


--
Elias 


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


Re: WMI remote call in python script to create process on remote windows computer

2009-10-08 Thread Tim Golden

Processor-Dev1l wrote:

On Oct 8, 10:22 am, Tim Golden  wrote:

David Jackson wrote:

ok, cut and pasted, but changed the username/password to protect the innocent.
this is from interactive prompt.
let me know if i am still not doing the slashes correctly please.
i doubt authentication is the issue.; i can get pid information using
WQL queries.
objCreateProc.Create expects 4 strings (not objects?), right?

Invoking a method isn't as easy as that, I'm afraid. At
the risk of being boring, can I ask again why you aren't
using the wmi module, which solves these problems for
you?

In short you want to do something like this:
(simplified for testing purposes to use the local machine)


import win32com.client

wmi = win32com.client.GetObject ("winmgmts:")
win32_process = wmi.Get ("Win32_Process")
in_parameters = win32_process.Methods_ ("Create").InParameters
in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
result = win32_process.ExecMethod_ ("Create", in_parameters)



TJG


Good point, I would like just to add this:
wmi = win32com.client.GetObject ("winmgmts:username:passw...@host\
\root\\cimv2")
and it is perfect :)


I wasn't aware of that form of moniker construction
(ie with the username / password embedded) and on
an XP-to-2k3 link it doesn't seem to work. Is it a
Vista / 2k8 extension? Obviously, above, I was relying
on the fact that the default default namespace (as opposed
to the DEFAULT namespace ;) ) is root\cimv2.

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


Re: WMI remote call in python script to create process on remote windows computer

2009-10-08 Thread Processor-Dev1l
On Oct 8, 10:22 am, Tim Golden  wrote:
> David Jackson wrote:
> > ok, cut and pasted, but changed the username/password to protect the 
> > innocent.
> > this is from interactive prompt.
> > let me know if i am still not doing the slashes correctly please.
> > i doubt authentication is the issue.; i can get pid information using
> > WQL queries.
> > objCreateProc.Create expects 4 strings (not objects?), right?
>
> Invoking a method isn't as easy as that, I'm afraid. At
> the risk of being boring, can I ask again why you aren't
> using the wmi module, which solves these problems for
> you?
>
> In short you want to do something like this:
> (simplified for testing purposes to use the local machine)
>
> 
> import win32com.client
>
> wmi = win32com.client.GetObject ("winmgmts:")
> win32_process = wmi.Get ("Win32_Process")
> in_parameters = win32_process.Methods_ ("Create").InParameters
> in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
> result = win32_process.ExecMethod_ ("Create", in_parameters)
>
> 
>
> TJG

Good point, I would like just to add this:
wmi = win32com.client.GetObject ("winmgmts:username:passw...@host\
\root\\cimv2")
and it is perfect :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multi-arrays python

2009-10-08 Thread Chris Rebert
On Wed, Oct 7, 2009 at 10:21 AM,   wrote:
> Hi again!
>
> After testing the whole day, I have got my goals from the last email, but as
> always, another issues came up! and now that Ive been able to save a list of
> list (or multi-arrays) as below :
>
> ['100.mp3\n' '10008.mp3\n' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n']
> ['10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
> ['10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n' '10006.mp3\n']
> ['10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3\n']
> ['10008.mp3\n' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n']
>
> I am not able to manipulate it again! I read it with:
> Myfile.read() and all what I get is a str type data, what make my aim very
> difficult to reach!  What I want, is just to read one line(one specific
> line, so  I wouldnt have to read the whole file) and to get the numbers of
> the songs from that line. Maybe I should save the information in another
> way... But I just get those lines as lists, and write them in a file. Is
> there a better way? I am very receptive to suggestions! Thanks again for
> your help!

Have you considered using the `json` module
(http://docs.python.org/library/json.html) to serialize and
deserialize the lists to/from a file in JSON format?
The `pickle` module is another option:
http://docs.python.org/library/pickle.html

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Neural networks in python

2009-10-08 Thread Raymond Hettinger
On Oct 7, 10:53 pm, ruchir  wrote:
> I want to design and train a neural network in python. Can anyone
> guide me, from where can I get some useful material/eBook/libraries
> etc. for the same. I have no prior experience in neural netwoks and
> want to implement it urgently.
> Thanks in advance :)

Take a look at http://code.activestate.com/recipes/496908/


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


Re: WMI remote call in python script to create process on remote windows computer

2009-10-08 Thread Tim Golden

David Jackson wrote:

ok, cut and pasted, but changed the username/password to protect the innocent.
this is from interactive prompt.
let me know if i am still not doing the slashes correctly please.
i doubt authentication is the issue.; i can get pid information using
WQL queries.
objCreateProc.Create expects 4 strings (not objects?), right?


Invoking a method isn't as easy as that, I'm afraid. At
the risk of being boring, can I ask again why you aren't
using the wmi module, which solves these problems for
you? 


In short you want to do something like this:
(simplified for testing purposes to use the local machine)


import win32com.client

wmi = win32com.client.GetObject ("winmgmts:")
win32_process = wmi.Get ("Win32_Process")
in_parameters = win32_process.Methods_ ("Create").InParameters
in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
result = win32_process.ExecMethod_ ("Create", in_parameters)





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


Re: Enormous Input and Output Test

2009-10-08 Thread n00m
N00m The Instigator... hahaha :-)
I always wish I was a producer, an entertainer,
an impressario, or even a souteneur (kidding).

Life is complex: it has both real and imaginary parts.
Some producer (Mr. Gomelsky) nicknamed Eric Clapton as
"Slow Hand", many years ago.
Gomel is my native town and apparently russian name
"Gomelsky" means "smb/smth belonging to Gomel".

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


  1   2   >