Re: Keeping two lists aligned after processing

2008-05-11 Thread Terry Reedy

"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
news:[EMAIL PROTECTED]
| philly_bob <[EMAIL PROTECTED]> writes:
| > algs=['AlgA', 'AlgB', 'AlgC', 'AlgD', 'AlgE']
| > accs=[]
| > for alg in algs:
| >thisacc=getattr(alg.accuracy)()
|> # picked this technique on comp.lang.python last month

I don't believe that you actually ran this.
What you should have picked up for the above was something like
globals()[alg].accuracy().  What you probably saw was something
like getattr(ob_with_call_attr, 'callable_name')().
But a list of alg objects instead of names, as Paul suggested,
is almost always better.

| >accs.append(thisacc)

| I think what you mean is (untested):
|
| algs = [AlgA, AlgB, AlgC, AlgD, AlgE]
| accs = sorted(((alg.accuracy(), alg.name()) for alg in algs), 
reverse=True)

Use alg.__name__ instead of alg.name().

| for i,(alg_acc, alg_name) in enumerate(accs):
|print '%2d %5s %0.2f'% (i, alg_name, alg_acc)
|
| This assumes a method alg.name() which tells you the name of the 
algorithm.

See above.  In 3.0, function names are also .__name__ instead of 
.func_name,
so one can mix callables in a list and get their definitions names 
uniformly.

| I don't understand how you're converting the string 'AlgA'
| to an algorithm object in your example above.

He was trying to convert name to method with the buggy getattr call.

tjr




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


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Gary Herron

bc90021 wrote:

...and the exact error message was?

Here is a tip: if you want people to help you, then you have to help
them to help you.  Personally, I wouldn't respond to anymore of your
questions because you seem incapable of posting the information that was
requested.



So far, the people who have answered this post have gone on the 
assumption that I'm stupid.  I'm not.  I took perfectly working code, 
cut it from one class, and put it in another.  It stopped working in the 
second class.  I've spent days on this and trust me, given what I've 
experienced of the Python community so far, if I didn't have to ask, I 
wouldn't.


(I really must say that so far the help I am getting in the Python 
community is a big let down.  Whether it's on IRC or here, everyone has 
an arrogance that I don't find anywhere else in the open source 
community, and it seriously makes me question the choice of language that 
I've made.)
  


Sorry, the arrogance is yours. 


   Expecting us to help with only partial information.

   Expecting us to help when your posts of the error message changes 
from one post to the next.


   Expecting us to help when you refuse to post the traceback.

   Expecting us to believe that it has anything to do with threads.  
(No one believes that for a moment.)



While acknowledging that any piece of code may have bugs, Python's 
threading included, the problem here looks to be some simple mistake in 
the computation of the name of the file to be opened.   Then I look at 
the convoluted quoting surrounding your computation of the file name, 
and my confidence in that as an explanation sky-rockets.  Then someone 
in another post has found an extra set of quotes embedded in your 
filename you compute, and it's clear that we are on the right track.




The error message was at the top of the thread (am I incapable of posting 
it, or are you incapable of following a thread?), but here it is again:


IOError: [Errno 2] no such file u'tempfileName'

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


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


Re: Python GUIs and custom controls

2008-05-11 Thread Joe P. Cool
On 9 Mai, 10:14, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> If you can work with the license (GPL), I suggest Qt4

Thanks for your helpful hints, guys.

--
Joe P. Cool
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiple Python versions, but on Windows (how to handle registry updates)

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 01:17:22 -0300, Banibrata Dutta <[EMAIL PROTECTED]> 
escribió:

> I realized that my query was not making much sense, or a bit convoluted. A
> simler form of the question:
>
> For packages which do contain .dlls & .pyd's (not pure Python) their latest
> version may be compatible with -- say Python 2.5, whereas I need the version
> compatible for Python2.2. Is this a completely manual exercise ?

You don't have to try - binaries for different Python versions *are* *not* 
compatible (up to the second digit: 2.4 and 2.5 are not compatible, but 2.5.1 
and 2.5.2 are). So any extension using a .pyd/.dll will have to be recompiled, 
at least.
Even pure Python code written for 2.5 may use features not available in 2.2.

Packages built using setuptools (eggs) may contain explicit dependency 
information but I don't know for sure.

-- 
Gabriel Genellina

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


Re: Simple question

2008-05-11 Thread Bjoern Schliessmann
Gandalf wrote:
> On May 10, 2:36 pm, Bjoern Schliessmann > It depends on your web server configuration. To get your web
>> server execute Python code, there are several alternatives like
>>
>> * CGI
>> * FastCGI
>> * mod_python
>
> my server is my computer 

I didn't mean which server hardware you use, but which web server
application. You need a web server application to use your "WWW
directory" in such a way.

> and all i did way to install python on it.

Nah, you probably have at least an operating system beneath Python.

Regards,


Björn

-- 
BOFH excuse #264:

Your modem doesn't speak English.

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


Re: what does int means for python ?

2008-05-11 Thread castironpi
On May 11, 5:05 am, alefajnie <[EMAIL PROTECTED]> wrote:
> > try arr[2][3] instead.
>
> > basically your version is trying to index an array with a tuple argument 
> > (2,3).
>
> > --irmen
>
> oh, you're right.
>
> btw, is any simple way to create multi-dimension array ?
> any built-in function ?

it is not clear that two-dim arrays are faster than hashes in all
implementations of Python, or in every general language, or if they're
the right symbol for your program.

>>> a= { }
>>> a[ 0, 1 ]= True
>>> a[ 4, 0 ]= True
>>> a[ 0, 1 ]
True

however, this one:

>>> a[ 2, 1 ]

results in a KeyError.  do you want a particular thing, or are you on
the clock?

if you want to define 'blanks', that takes time too.  is it initally
empty?
--
http://mail.python.org/mailman/listinfo/python-list


Re: diffing and uniqing directories

2008-05-11 Thread castironpi
On May 11, 2:44 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> On Sat, 26 Apr 2008 23:44:17 +0530, Rustom Mody wrote:
> > Over years Ive collected tgz's of my directories. I would like to diff
> > and uniq them
>
> > Now I guess it would be quite simple to write a script that does a walk
> > or find through a pair of directory trees, makes a SHA1 of each file and
> > then sorts out the files whose SHA1s are the same/different. What is
> > more difficult for me to do is to write a visual/gui tool to help me do
> > this.
>
> > I would guess that someone in the python world must have already done it
> > [The alternative is to use some of the tools that come with version
> > control systems like git. But if I knew more about that option I would
> > not be stuck with tgzs in the first place ;-)]
>
> > So if there is such software known please let me know.
>
> > PS Also with the spam flood that has hit the python list I dont know if
> > this mail is being read at all or Ive fallen off the list!
>
> It doesn't have a GUI, but here's a python program I wrote for dividing
> large collections of files up into identical groups:
>
> http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html- Hide quoted 
> text -
>
> - Show quoted text -

I want to question terminology!

Question 'identical' groups over related!

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


Re: Some error messages in Python are ugly

2008-05-11 Thread Matthieu Brucher
Please, really please, stop asking question and go read some books about/get
some courses on Linux shell and then finally Python.
Before you do that, the only thing will have is upset people telling you to
_think_ (clearly that's something you are n,ot used to do, but you will have
to start at some point) before sending a mail.

Matthieu

2008/5/11 <[EMAIL PROTECTED]>:

> This really looks ugly for an error message:
>
> [1]+  Stopped python
>
>
> Please explain to me the role of the '+' sign. And why is there such a
> gap between 'Stopped' and 'python'?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list

IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
Hello,

I am testing Python 3.0a5's handling of unicode strings. Since SPE is
not yet for Python 3.0, I have begun to write in IDLE 3.0a5.

I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
can:

#!/usr/bin/python
# -*- coding: utf-8 -*-

def načtiSlovník(zdroj='slovník.txt'):
soubor = open(zdroj, mode='r', encoding='utf_8')
řádky = soubor.readlines()
for řádek in řádky:
print(řádek, end='')

načtiSlovník()
# End of source code

I have set up Default Source Encoding to UTF-8 in IDLE's general
configuration. Still, when I open that source code and try to run it,
IDLE complains about "invalid character in identifier" and highlights
"zdroj" red in the first line (sic!).

However, when I run the source code from command line (by "python
"), it gets executed well and does what it shall do.

I should probably add, that I have installed py3k:62932M, May 9 2008,
16:23:11 [MSC v.1500 32 bit (Intel)] on win32. I use Windows XP SP 3.

Is this a known bug if IDLE 3.0a5 which will be fixed in the final
release?

Greetings,

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


Re: Mathematics in Python are not correct

2008-05-11 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>I am stunned that this simple misunderstanding of mine ended in a
>mathematical clash of a sort. :)  You guys really blew me away wih
>your mathematical knowledge. And also the 0**0 is a thing I've never
>thought about trying, until now that is. If the mathematical rule is
>that EVERYTHING raised to the power of 0 is 1, then we should accept
>that, even in the case of 0**0. This is just the way it is.

Sure, but it's ALSO the mathematical rule that 0 raised to any power is 0.
Thus, there are multiple solutions to this problem, meaning that there is
NO solution to the problem.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to call a file

2008-05-11 Thread Yves Dorfsman

Gary Herron wrote:

First of all, some terminology: You are not *calling* a file, you are 
*opening* it or reading.


Wouldn't it be more correct to say that, in python, you either create a file 
object, or call a method for that object, once the object has been created ?




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


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Martin v. Löwis
> Is this a known bug if IDLE 3.0a5 which will be fixed in the final
> release?

No, it's now a known bug (at least I don't know it). Whether or not it
gets fixed might depend on whether or not it gets reported to
bugs.python.org.

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


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
> I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
> can:

Oh I see the posts in this newsgroup do not yet support Unicode. Most
of the special characters in my source code have been messed up. But
anyway, those who know Czech can handle it. The error is replicable
even with the messed-up characters.

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


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
> No, it's now a known bug (at least I don't know it). Whether or not it
> gets fixed might depend on whether or not it gets reported to
> bugs.python.org.

Ok, I'll repost it there.

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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
John Salerno <[EMAIL PROTECTED]> writes:

> num = 33
> 
> for x in xrange(10):
> print num += 1

Which is better done by 'num += 10'.

Can you come up with an example that isn't trivially replaced with
clearer code? That might make it clearer what your concern is.

> The [above] example [...] is simply doing something 10 times, and
> what it's doing has nothing to do with 'x' or xrange. So it seems
> like an abuse of the for loop.

In such cases, the name 'dummy' is conventionally bound to the items
from the iterator, for clarity of purpose::

for dummy in range(10):
# do stuff that makes no reference to 'dummy'

Also note that 'range' will return an iterator (not a list) in Python
3.0, and 'xrange' is removed since it's then obsolete
http://www.python.org/dev/peps/pep-3100/#built-in-namespace>.

-- 
 \  “Isn’t it enough to see that a garden is beautiful without |
  `\  having to believe that there are fairies at the bottom of it |
_o__) too?” —Douglas Adams |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Yves Dorfsman

John Salerno wrote:


To me, the first example is a pure use of the for loop. You are 
iterating through an object and *using* the items you are stepping through.


The second example, however, is simply doing something 10 times, and 
what it's doing has nothing to do with 'x' or xrange. So it seems like 
an abuse of the for loop.


Well, I would say this:
myl = ['a', 'b', 'c', 'd']
for i in xrange(len(myl)):
  print myl[i]

As you would see in other languages, is an abuse in python. But in you need 
to iterate 5 times over something. Do you have a cleaner / python'er 
alternative ?


Do you find the following cleaner:

x = 0
while x <= 4:
  print x
  x += 1



Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread hdante
On May 11, 7:27 pm, Sven Siegmund <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/python

 Notice that this line is probably not what you want, unless you
overwrote the default python 2 installation. The line should be:

 #!/usr/bin/env python3.0

 (this is irrelevant to the bug, however)

> IDLE complains about "invalid character in identifier" and highlights
> "zdroj" red in the first line (sic!).

 It worked here (Python 3.0a5 (r30a5:62856, May 11 2008, 19:52:04)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2). I started IDLE 3.0a5,
clicked the open menu, loaded the file, then run->run module. I've
copied and pasted your code and created the "slovník.txt" file. I'm
using tk 8.4.16.

 Would you mind reinstalling and notice any warning message during
compilation ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle problem

2008-05-11 Thread krustymonkey
On May 8, 7:29 pm, [EMAIL PROTECTED] wrote:
> On May 8, 4:35 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
>
>
> > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>
> > > On Thu, 08 May 2008 08:55:35 -0700, krustymonkey wrote:
>
> > >> The thing is, I'm not using slots by choice.  I'm using the standard
> > >> lib "socket" class, which apparently uses slots.
>
> > > `socket` objects can't be pickled.  Not just because of the
> > > `__slot__`\s but because a substantial part of their state lives in
> > > the operating system's space.
>
> > Of course, if it makes sense to pickle sockets in the application, one
> > is can do so by defining __getstate__ and __setstate__:
>
> > class Connection(object):
> > def __init__(self, host, port):
> > self.host = host
> > self.port = port
> > self.init_sock()
>
> > def init_sock(self):
> > self.sock = socket.socket()
> > self.sock.connect((host, port))
> > ... init communication ...
>
> > def __getstate__(self):
> > # pickle self as a (host, port) pair
> > return self.host, self.port
>
> > def __setstate__(self, state):
> > # reinstate self by setting host and port and
> > # recreating the socket
> > self.host, self.port = state
> > self.init_sock()
>
> I, local, am mystified that you'd want to pickle a socket.  It's a
> live connection, which flies on a pocket dollar.  You don't want it on
> disk, do you?
>
> If you're running a net buoy through a cluster somewhere, do you want
> to drop a server and reconnect?  Is Amazon's EC2 up and running?
>
> Certainly no one was talking on the internet.  Were you?
>
> I don't think you hit anything but banks surfing the web, and the
> American dollar is notoriously stuffy.  Pump a wi-fi to a diner,
> though, and you're just talking more.  Where's Usenet?

The idea is a pre-fork socket server.  What I want to do is fork off
some child processes from the parent and use IPC to send the
connection object (via socket.accept()) over a pipe to one of the
preexisting child processes and have said child handle the
transaction.  Think Apache, if you want an example of what I'm trying
to do here.  This alleviates the process startup cost that occurs when
you fork.  If the socket object can't be serialized, is there another
way to go about handling this in python?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python, are you ill?

2008-05-11 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>If you are in the interactive prompt of the Python interpreter and you
>do this
>
>print """Testing\"""   or   print '''Testing\'''
>
>you get three dots [...] as if Python expects a code block.

...which it does.

>If you
>press Enter, you get three dots again, and again, and again... You
>can't get out of the code block with pressing the Enter key; you have
>to press Ctrl+Z (if you're in Linux) in order to get out of that code
>block, 

No, you don't.  You can also enter """ or ''' to properly close the quote.

>If you do
>
>print "Testing\"   or   print 'Testing\'
>
>you get an error, but not of you use the triple quotes. Is that a bug
>in the interpreter perhaps?

As a general rule, when you are just beginning to learn some product, it is
safe to assume that anything you see as a bug in the product is almost
certainly a flaw in your understanding of the product.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


python without while and other "explosive" statements

2008-05-11 Thread ivo talvet
Hello,

Is it possible to have a python which not handle the execution of
"while", "for", and other loop statements ? I would like to allow
remote execution of python on a public irc channel, so i'm looking for
techniques which would do so people won't be able to crash my computer
(while 1: os.fork(1)), or at least won't won't freeze my python in a
infinite loop, make it unresponsive. Is there a compiling option (or
better, something i can get with apt-get cos i think compiling myself
and handle all the metastuff myself is somehow dirty) for have a
"secure python" (you can guess what i mean by "secure" in my case) or
must i touch myself the source disable some code lines ? If last
solution, which modifications in which files should i do ? (sorry for
my bad english)

Thanks.

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


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Gary Herron

bc90021 wrote:
You are a perfect example of exactly what I was talking about, and why 
the Python community is such a poor one.


I though you were treated quite fairly all things considered.   (You 
started the personal attacks, the whining about the group, the 
accusations of arrogance, and the refusal to believe we all *knew* the 
error was in your file name calculation and not in Python threads.)


This group is widely acknowledged as one of the more friendly groups 
around,  and in fact we keep it that way by coming down rather hard on 
those who abuse either the members of the group or the purpose of the 
group.  And you've done both and been reprimanded for it.   Now, either 
go away, or change your attitude and join the group. (You would be 
welcome if the attitude changed.)  Either way, this group will be it's 
usual friendly self.



Gary Herron





Gary Herron wrote:

bc90021 wrote:

...and the exact error message was?

Here is a tip: if you want people to help you, then you have to help
them to help you.  Personally, I wouldn't respond to anymore of your
questions because you seem incapable of posting the information 
that was

requested.



So far, the people who have answered this post have gone on the 
assumption that I'm stupid.  I'm not.  I took perfectly working 
code, cut it from one class, and put it in another.  It stopped 
working in the second class.  I've spent days on this and trust me, 
given what I've experienced of the Python community so far, if I 
didn't have to ask, I wouldn't.


(I really must say that so far the help I am getting in the Python 
community is a big let down.  Whether it's on IRC or here, everyone 
has an arrogance that I don't find anywhere else in the open source 
community, and it seriously makes me question the choice of language 
that I've made.)
  


Sorry, the arrogance is yours.
   Expecting us to help with only partial information.

   Expecting us to help when your posts of the error message changes 
from one post to the next.


   Expecting us to help when you refuse to post the traceback.

   Expecting us to believe that it has anything to do with threads.  
(No one believes that for a moment.)



While acknowledging that any piece of code may have bugs, Python's 
threading included, the problem here looks to be some simple mistake 
in the computation of the name of the file to be opened.   Then I 
look at the convoluted quoting surrounding your computation of the 
file name, and my confidence in that as an explanation sky-rockets.  
Then someone in another post has found an extra set of quotes 
embedded in your filename you compute, and it's clear that we are on 
the right track.




The error message was at the top of the thread (am I incapable of 
posting it, or are you incapable of following a thread?), but here 
it is again:


IOError: [Errno 2] no such file u'tempfileName'

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








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


Re: python without while and other "explosive" statements

2008-05-11 Thread Grant Edwards
On 2008-05-11, ivo talvet <[EMAIL PROTECTED]> wrote:

> Is it possible to have a python which not handle the execution of
> "while", "for", and other loop statements ? I would like to allow
> remote execution of python on a public irc channel, so i'm looking for
> techniques which would do so people won't be able to crash my computer
> (while 1: os.fork(1)), or at least won't won't freeze my python in a
> infinite loop, make it unresponsive.

The easiest thing to to is to limit the amount of files,
disk-space, file descriptors, inodes, memory, cpu, and
processes that the users are allowed.  If bash is your shell,
the builtin "ulimit" provides most of those features.  The file
system quota features provide the rest.

> Is there a compiling option (or better, something i can get
> with apt-get cos i think compiling myself and handle all the
> metastuff myself is somehow dirty) for have a "secure python"
> (you can guess what i mean by "secure" in my case) or must i
> touch myself the source disable some code lines ? If last
> solution, which modifications in which files should i do?

My advice is don't try to secure Python itself: secure the
environment in which the users are using it.

-- 
Grant Edwards   grante Yow!  Did I SELL OUT yet??
  at   
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
(quoted text below my reply)

THANK YOU SO MUCH, Michael!

Criminitly!  Figures!  HA!  I had it the WHOLE TIME, but didn't
realize it!  ;)  (As mentioned, I had FILE installed from GnuWin32.)
DUH!  I just neglected to do a search for "magic1.dll"... the most
obvious of the obvious!

I copied it from C:\Program Files\GnuWin32\bin\magic1.dll to C:
\Program Files\python25\libs.

Imports fine now.  (I'll *test* it later.  Then write-up my HowTo... I
think I'll even see if I can make an EGG for others... SOUNDS "easy"
with EasyInstall [http://peak.telecommunity.com/DevCenter/
EasyInstall]...  I'll -see-...  :) )

Ah, sometimes one CAN'T see the forest for the trees; a few hours
hacking away at getting things going to THIS point will do it to ya...
err, or at least "to me"!  :D


Thanks, again, Michael...
-Larry



On May 11, 11:34 am, Michael Torrie <[EMAIL PROTECTED]> wrote:
> Larry Hale wrote:
> > Now I *presume* my problem (at this point) is that I need to have
> > libmagic named as "magic1.dll" -wherever- this module is looking for
> > it.  I'm just not sure, let alone if this is true, WHERE Python/
> > modules expect to find such things.
>
> > Also, which version(s)/file(s) should be placed where, or...??
>
> The dll you are looking for is here:
>
> http://downloads.sourceforge.net/gnuwin32/file-4.21-bin.zip?modtime=1...
>
> The .dll.a file you mention is just a linker stub for when you want to
> compile against it (as you are doing when building python-magic).
>
> The magic1.dll file in the file-4.21-bin.zip package should be placed
> anywhere in the path.  Since you'll be using it with python, you could
> probably stick it in the python25/bin folder (where ever your python
> system is installed).

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


how to separate words from a string?

2008-05-11 Thread David Anderson
Hi, how can I separate words from a sentence in a string? Like the
java.String.split method
I need something that gets an string "This is a sentence", and return to em
a list["This","is","a","sentence"]
Can anyone help?
Thx
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Jonathsn Cronin
On Sun, 11 May 2008 16:16:53 -0400, John Salerno wrote
(in message <[EMAIL PROTECTED]>):

> XLiIV wrote:
> 
>> The range() function returns a list and list is a sequence, isn't?
> 
> I think you're missing the point. To me, there seems to be a fundamental 
> difference between these two things:
> 
> ---
> 
> people = ['Sam', 'Bob', 'Fred']
> 
> for name in people:
>  print name
> 
> ---
> 
> AND
> 
> ---
> 
> num = 33
> 
> for x in xrange(10):
>  print num += 1
> 
> ---
> 
> To me, the first example is a pure use of the for loop. You are 
> iterating through an object and *using* the items you are stepping through.
> 
> The second example, however, is simply doing something 10 times, and 
> what it's doing has nothing to do with 'x' or xrange. So it seems like 
> an abuse of the for loop.

I agree in principle; the first is iteration and the second is repetition.
In Python, the common idiom for a fixed number of repetitions is iterating 
over a number range.  This is true in most languages I am familiar with, 
probably because fixed repetition, where you don't care about the "index" 
value, is rarely used.

The only language I've used that does have fixed repetition is an (old) 
dialect of lisp, and I'm not sure it even made it into Common Lisp.  
Smalltalk and Ruby do have fixed repetition.

Using range may not be entirely elegant, but is pragmatic, and not, to me, 
particularly ugly.  In Python, unlike some languages, you don't have to 
declare the x.

I think you could add it without too much change to the parsing.

for :
  

Seeing a ":" instead of "in" would mean a repetition statement which would
be interpreted as:
-- if  evaluates to an integer, execute the block that number of 
times.
-- If  evaluates to an iterator, execute the block until the 
iterator is exhausted.

Even if possible, I see this at best a minor improvement and more likely a 
negative because the for keyword is now overloaded. (see "static" in C/Java.) 
You could add a new keyword but the benefit here is much to small to justify 
the trouble.

Jonathan

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


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
After putting the magic1.dll file to C:\Program Files\Python25\DLLs
(looking at the directory structure, that seemed as good a place as
any), now I can *import* the module, but...

>>> import magic
>>> test = magic.Magic()
Traceback (most recent call last):
  File "", line 1, in 
  File "build\bdist.win32\egg\magic.py", line 32, in __init__
  File "build\bdist.win32\egg\magic.py", line 72, in _check_error
magic.MagicException: could not find any magic files!

I've placed

  474,146 magic
1,037,440 magic.mgc
   32,203 magic.mime
   45,696 magic.mime.mgc
   77,312 magic1.dll

into

C:\windows\system32
in Windows/System PATH
AND (simultaneously)
C:\Program Files\python25\DLLs
in sys.path/PYTHONPATH

(I've also tried putting copies into different dirs in both PYTHONPATH
and system PATH, to no avail.)

Obviously, magic1.dll/magic.py (et al) can't FIND the needed file(s),
but I'm not sure how to go about discerning WHERE it/they are looking
- any thought(s)/suggestion(s), anyone??


Thanks in advance!
-Larry


P.S.: Thanks, again, Michael!  ;)  - L
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to separate words from a string?

2008-05-11 Thread Benjamin Kaplan
On Sun, May 11, 2008 at 8:15 PM, David Anderson <[EMAIL PROTECTED]>
wrote:

> Hi, how can I separate words from a sentence in a string? Like the
> java.String.split method
> I need something that gets an string "This is a sentence", and return to em
> a list["This","is","a","sentence"]
> Can anyone help?
> Thx
>

You should probably look in the docs before posting here. Python strings
also have a split method, that does the same thing as in java.
http://docs.python.org/lib/string-methods.html
--
http://mail.python.org/mailman/listinfo/python-list

Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Terry Reedy

"Sven Siegmund" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|> I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
| > can:
|
| Oh I see the posts in this newsgroup do not yet support Unicode.

I think this depends on the reader and maybe the fonts on the system.
OutlookExpress displays hatted c, for instance, fine.

 Most
| of the special characters in my source code have been messed up. But
| anyway, those who know Czech can handle it. The error is replicable
| even with the messed-up characters.



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


Re: Mathematics in Python are not correct

2008-05-11 Thread Terry Reedy

"Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| [EMAIL PROTECTED] wrote:
| >
| >I am stunned that this simple misunderstanding of mine ended in a
| >mathematical clash of a sort. :)  You guys really blew me away wih
| >your mathematical knowledge. And also the 0**0 is a thing I've never
| >thought about trying, until now that is. If the mathematical rule is
| >that EVERYTHING raised to the power of 0 is 1, then we should accept
| >that, even in the case of 0**0. This is just the way it is.
|
| Sure, but it's ALSO the mathematical rule that 0 raised to any power is 
0.

That may be some people's (partial) rule but not everyone's.
There is only agreement on 0 to a positive power.

| Thus, there are multiple solutions to this problem, meaning that there is
| NO solution to the problem.

Only for some people.
a**b := reduce(mul, [a]*b, 1) for all counts a and b is a simple, uniform, 
and useful rule.
Do you have in mind any situations in which it is advantageous to have 0**0 
undefined?

tjr



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


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread Asun Friere
On May 11, 10:54 pm, [EMAIL PROTECTED] wrote:
> To create a tuple with one element, you need to do this:
>
> >>> my_tuple = (1,)# Note the trailing comma after the value 1
> >>> type(my_tuple)
>
> 
>

You needn't at all.  You could simply do this:

>>> your_tuple = 1,

You see, it's not the parentheses that make the tuple.


> But if you do this
>
> >>> my_tuple = (1)
> >>> type(my_tuple)
>
> 
>
> you don't get a tuple.

For which the BDFL should make us eternally grateful.

> it would be clean if Python would convert anything put into ( ) to
> be a tuple

You seriously want 2*(3+4) to return (7,7)?  You call that "clean"?!

At least type(my_tuple) would always return 'tuple,' whether it was or
not. ;)

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


Re: Orlando Florida Python Tutor Needed

2008-05-11 Thread Larry Hale
On May 10, 11:42 am, vbgunz <[EMAIL PROTECTED]> wrote:
> I will pay anyone for a face-to-face tutoring in the Orlando Florida
> area. I will pay $20.00 per hour (minimum 2 hours needed). What I need
> are lessons in Decorators and Class methods. If I can walk away with
> at least 5 lessons taught in both subjects I will be happy to offer an
> additional $20.00.
>
> If you are interested in this offer feel free to either reply through
> email OR here on this thread. There are no string attached, catches,
> etc. I need to learn and if you can teach well, I will be happy to
> learn.
>
> Best Regards
> Victor B. Gonzalez


I know you're looking for "one-on-one" help, direction, and/or
tutelage, but since you've not received an answer (yet), here's some
general info...

---

For Class Methods, perhaps you could mention more of what you need to
know?  Otherwise, generically see:

http://docs.python.org/tut/node11.html#SECTION001134
http://www.geocities.com/foetsch/python/new_style_classes.htm

http://www.diveintopython.org/object_oriented_framework/defining_classes.html

and obviously

http://www.google.com/search?hl=en&q=python+class+methods&btnG=Google+Search

---

For Decorators, have a gander at:


http://www.ddj.com/web-development/184406073;jsessionid=QCNTPTSNXZP2WQSNDLPCKHSCJUNN2JVN?_requestid=749134
http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

and obviously

http://www.google.com/search?hl=en&q=python+decorators&btnG=Google+Search

Decorators are still rather new to -me-, and I've yet to "need" 'em,
but they _seem_ like a handy feature.  (Personally, I don't care too
much for the syntax, but other than explicitly DOING what they do,
which would be [1] messier and/or [2] non-transparent/duplicative, I
sadly have no alternative thought[s]...  ;) )


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


Re: python without while and other "explosive" statements

2008-05-11 Thread Matt Nordhoff
ivo talvet wrote:
> Hello,
> 
> Is it possible to have a python which not handle the execution of
> "while", "for", and other loop statements ? I would like to allow
> remote execution of python on a public irc channel, so i'm looking for
> techniques which would do so people won't be able to crash my computer
> (while 1: os.fork(1)), or at least won't won't freeze my python in a
> infinite loop, make it unresponsive. Is there a compiling option (or
> better, something i can get with apt-get cos i think compiling myself
> and handle all the metastuff myself is somehow dirty) for have a
> "secure python" (you can guess what i mean by "secure" in my case) or
> must i touch myself the source disable some code lines ? If last
> solution, which modifications in which files should i do ? (sorry for
> my bad english)
> 
> Thanks.
> 
> Ivo

 is a pastebin-like website that lets people upload
code in a dozen different languages, and it runs it. They have info up
about how it's secure at .

I'm pretty sure there's another similar website that's specific to
Python, but I can't remember it. Anyway, it was similar, using virtual
machines, a firewall, and killing stuff that ran for longer than 20
seconds, IIRC.

(Thanks for the link to codepad, habnabit.)
-- 
--
http://mail.python.org/mailman/listinfo/python-list


Re: list object

2008-05-11 Thread Larry Hale
On May 10, 12:39 pm, Gandalf <[EMAIL PROTECTED]> wrote:
> my manual contain chapter about lists with python. when i try to copy
> paste :
>
> li = ["a", "b", "mpilgrim", "z", "example"] (1)
>
> it i get this errore:
>
> "TypeError: 'list' object is not callable"
>
> i was wondering if their is  any special module I should import before
> i use this function
>
> i know i ask foolish questions it's my first day with python and i
> have experience only with PHP and javascript, so please be patient
>
> thanks


To expand upon what others have already mentioned, and/or to explain
what's going on...

li ==>> a label for a "list" (presume the author used it as short-
hand?); trying to set it to point-to/"equal"...

["a", "b", "mpilgrim", "z", "example"] ==>> THE LIST

A "list" is a mutable (changeable in-place) container object.
See e.g.: http://www.diveintopython.org/native_data_types/lists.html

(1) ==>> the Python interpreter will interpret this as if you're
attempting to "call" the list object (["a", "b", ...]) as if it were a
function/method


Indeed, the "(1)" is what's causing the problem, but it's -because-
the list *object* is, well, "not callable".  :)

As an aside, see what "li" contains if you do:

li = ["a", "b", "mpilgrim", "z", "example"][1]

;)


Cheers!
-Larry Hale
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Carl Banks
On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> In such cases, the name 'dummy' is conventionally bound to the items
> from the iterator, for clarity of purpose::
>
> for dummy in range(10):
> # do stuff that makes no reference to 'dummy'

Is this documented?  I've never heard of this convention.  It's not
PEP 8, and I've never seen consistent usage of any name.  I'd be
interested in knowing where you read that this was a convention, or in
what subcommunities it's a convention in.

I think dummy is a terrible name to use for this, since in no other
usage I can think of does the word "dummy" suggest something isn't
used.  In fact, quite the opposite.  For example, the dummy_threads
module is most definitely used; the word dummy means that it's
stripped down.  Based on that, your usage of the symbol dummy above
would suggest to me that it's a value used in lieu of something else
(such as a calculated value).

In mathematics, a dummy argument another name for the independent
variable of a function (or more accurately, the symbol used to
represent it), which also doesn't match your usage.

If a value isn't used, then I think the most clear name for it is
"unused".


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


Re: Saving an audio file's waveform into an image

2008-05-11 Thread Larry Hale
On May 9, 1:55 am, Julien <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to pull out the waveform of an audio file and save it
> into an image file, for example in GIF format. Is that achievable, and
> if so, how?
>
> I heard about the Snack module, but the project looks dead and un-
> maintained.
>
> Your advice would be greatly appreciated.
>
> Thanks!
>
> Julien


Would you please provide more info on what you're wanting to
accomplish?

As for "Snack module", all I could find was 
http://www.wanware.com/tsgdocs/snack.html,
which seems "dead", although the Google cached version at
http://64.233.167.104/search?q=cache:gNGrrPqY5RsJ:www.wanware.com/tsgdocs/snack.html+python+snack+module&hl=en&ct=clnk&cd=1&gl=us
makes it sound rather UNlike what you're talking about.  (Other ref's
for my Google search of 
http://www.google.com/search?hl=en&q=python+snack+module&btnG=Google+Search
seemed to show the same thing.)


The short answer is: Huh?/What?/Why?  Why not put the picture + sound
==> video file.  (Sure the image remains static, but there's the
Soundtrack with it!  ;) )


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


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 5:50 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> bc90021 wrote:
> > You are a perfect example of exactly what I was talking about, and why
> > the Python community is such a poor one.
>
> I though you were treated quite fairly all things considered.   (You
> started the personal attacks, the whining about the group, the
> accusations of arrogance, and the refusal to believe we all *knew* the
> error was in your file name calculation and not in Python threads.)
>
> This group is widely acknowledged as one of the more friendly groups
> around,  and in fact we keep it that way by coming down rather hard on
> those who abuse either the members of the group or the purpose of the
> group.

That is a blantant lie.   This group has well known members that are
some of the biggest jackasses I've ever encountered on the internet.
I've never heard a peep out of anyone criticizing their behavior.  If
I were their employer, and I read some of the stuff they posted, I
would fire them on the spot.
--
http://mail.python.org/mailman/listinfo/python-list


anonymous assignment

2008-05-11 Thread Yves Dorfsman

Is there anyway to tell python I don't care about a value ?

Say I want today's year and day, I'd like to do something like:

import time
y, None, d, None, None, None, None = time.localtime()

I know you can't assign anything to None, but I'm sure you get what I mean, 
a special keyword that means I don't care about this value. In this 
particular case, there's got to be a better way than:


d = time.local()
y = d[0]
d = d[1]



Thanks.


Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ivan Illarionov
On Sun, 11 May 2008 18:52:48 -0700, Carl Banks wrote:

> On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
>> In such cases, the name 'dummy' is conventionally bound to the items
>> from the iterator, for clarity of purpose::
>>
>> for dummy in range(10):
>> # do stuff that makes no reference to 'dummy'
> 
> Is this documented?  I've never heard of this convention.  It's not PEP
> 8, and I've never seen consistent usage of any name.  I'd be interested
> in knowing where you read that this was a convention, or in what
> subcommunities it's a convention in.
> 
> I think dummy is a terrible name to use for this, since in no other
> usage I can think of does the word "dummy" suggest something isn't used.
>  In fact, quite the opposite.  For example, the dummy_threads module is
> most definitely used; the word dummy means that it's stripped down. 
> Based on that, your usage of the symbol dummy above would suggest to me
> that it's a value used in lieu of something else (such as a calculated
> value).
> 
> In mathematics, a dummy argument another name for the independent
> variable of a function (or more accurately, the symbol used to represent
> it), which also doesn't match your usage.
> 
> If a value isn't used, then I think the most clear name for it is
> "unused".
> 
> 
> Carl Banks

I agree with Carl. This group is the only place I've heard about this 
convension and it looks terrible IMO. Even if a value is not used, the 
variable still has a meaning: it is a counter, or an index.

I know about the other convention: "for i in xrange" or "for i in range".
Wikipedia agrees with me:
http://en.wikipedia.org/wiki/For_loop
Examples in wikipedia article use either "i" or "counter".

It is established convention in almost every programming language and its 
origins are in mathematics (matrix indices).

Google search for "for dummy in range" (with quotes) gives 164 results
While "for dummy in range" gives 146 000 results. Almost thousand times 
more.

So, "i" is more conventional and as such is more readable.

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


Re: anonymous assignment

2008-05-11 Thread Paul Rubin
Yves Dorfsman <[EMAIL PROTECTED]> writes:
> import time
> y, None, d, None, None, None, None = time.localtime()
> 
> I know you can't assign anything to None, but I'm sure you get what I
> mean, a special keyword that means I don't care about this value.

You can just use a variable name than you ignore.  It's traditional to
use _ but it's not a special keyword, it's just a another variable name:

   y, _, d, _, _, _, _, _, _ = time.localtime()
--
http://mail.python.org/mailman/listinfo/python-list


Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S

2008-05-11 Thread yxs046
Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S
Link :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F08-PN96S.html

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S
Information :

Brand :   Corum Watches ( http://corum.hotwatch.org/ )
Gender :  Ladies
Code :   Corum-Ladies-Watch-196-151-47-0F08-PN96S
Item Variations :   196-151-47-0F08-PN96S, 196151470F08PN96S,
Corum-196-151-47-0F08-PN96S
Movement :Quartz
Bezel :   Diamond
Case Material :Stainless Steel
Case Diameter :   35.5mm
Dial Color :   Pink Mother-of-pearl
Crystal : Scratch Resistant Sapphire
Clasp :   Pink Leather
Water Resistant : 50m/165ft

Stainless Steel Case. Pink Leather Coated Rubber Strap. Pink Mother-of-
pearl Dial. Diamond Bezel. Push Button Deployment Clasp. Domed Scratch
Resistant Sapphire Crystal. Date Displays At 6 O'clock Position.
Chronograph Measures 1/10th Second, 30 Minutes, And 60 Seconds. Case
Diameter 35.5mm. Case Thickness 18mm. Quartz Movement. Water Resistant
At 50 meters (165 feet).

The Same Corum Watches Series :

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F08-PN96R.html

Corum Bubble Diamond Steel Blue Ladies Watch 196-151-47-0F03-FB30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F03-FB30S.html

Corum Bubble Diamond Steel Blue Ladies Watch 196-151-47-0F03-FB30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F03-FB30R.html

Corum Bubble Diamond Steel Brown Ladies Watch 196-151-47-0F02-EB30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F02-EB30R.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-PN94S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-PN94S.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-PN94R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-PN94R.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-FM30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-FM30S.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-FM30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-FM30R.html

Corum Bubble Steel Orange Ladies Watch 196-150-20-0F14-FM30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-150-20-0F14-FM30R.html

Corum Bubble Steel Orange Ladies Watch 196-150-20-0F14-EB30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-150-20-0F14-EB30S.html

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


Re: anonymous assignment

2008-05-11 Thread D'Arcy J.M. Cain
On Mon, 12 May 2008 02:28:13 GMT
Yves Dorfsman <[EMAIL PROTECTED]> wrote:
> particular case, there's got to be a better way than:
> 
> d = time.local()
> y = d[0]
> d = d[1]

Like this?

y, d = time.local()[:2]

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-11 Thread Mark Dickinson
On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> Do you have in mind any situations in which it is advantageous to have 0**0
> undefined?

(Playing devil's advocate here.) If you regard x**y as exp(y*log(x))
then it's not at all clear that 0.**0. should be considered
well-defined. And since Python likes integer and floating-point
operations to match numerically (as far as possible), 0**0 then
also comes into question.

The big problem here is that the power operation is really trying
to combine two subtly different functionalities (integer powers
and real powers), with quite distinct use-cases, into a single
function.  Which leads to problems:  witness the mess that's
C99's pow specification:  why does it make sense for (-2.0)**2.0 to
return 4.0, while (-2.0)**1.9 returns NaN?  And why
should (-2.0)**infinity be well-defined?

It looks like that same mess is going to make it into IEEE 754r.
There were suggestions on the 754r mailing list to separate
the pow functionality out into two separate functions: pown
for integer powers and powr for real powers.  pown(0.0, 0) would
be 1, while powr(x, y) would be defined strictly as exp(y*log(x))
and so powr(0.,0.) would raise the invalid signal.

I have to admit that almost all my uses of ** are with
integer exponents, and I'd be very upset if anyone took
0**0 == 1 away...

Incidentally, the decimal module is slightly schizophrenic about
this:  Decimal(0)**Decimal(0) raises an exception, but
Decimal('Inf')**Decimal(0) returns Decimal(1).  Which doesn't
make a lot of sense, since every reason for making 0**0
undefined seems to apply equally well to infinity**0...

Mark

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


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 10, 11:41 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> I've heard tell of a Python binding for libmagic (file(1) *nixy
> command; seehttp://darwinsys.com/file/).  Generally, has anybody
> built this and worked with it under Windows?
>
> The only thing I've been able to find is the python-magic module 
> athttp://hupp.org/adam/hg/python-magic/.
>
> [1] Is this "THE" python-magic module.  (It seems to be to me, but
> obviously I don't know. :)
>
> [2] Has anybody been able to build THIS version under Windows?
>
> I've gotten as far as completing the "setup.py install" process.
> (After many troubles; I'll post the top-to-bottom HowTo-like info if/
> when I ever get it to work.  :)
>
> At this point, there -is- a "magic" module that can be imported
> (attempted-to, that is), but it fails.
>
> If I go to a cmd window, run the Py interpreter, and do "import magic"
> I get:
>
> [1] an error pop-up (Windows window, which is blocking [as opposed
> to "non-blocking", not "obscuring", though it does that, too] the cmd
> window):
>
> (X) This application has failed to start because magic1.dll
> was not found.  Re-installing the application may fix this problem.
> [OK]
>
> [2] then, within the interpreter, I get:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "build\bdist.win32\egg\magic.py", line 2, in 
>   File "build\bdist.win32\egg\cmagic.py", line 7, in 
>   File "build\bdist.win32\egg\_cmagic.py", line 7, in 
>   File "build\bdist.win32\egg\_cmagic.py", line 6, in
> __bootstrap__
> ImportError: DLL load failed: The specified module could not
> be found.
>
> I'm using Python 2.5 on Windows XP Pro.  I've got CYGWIN installed
> (more info can be provided if necessary) for a copy of file.exe (and
> libmagic.a @ 357KB and libmagic.dll.a @ 25KB in C:\cygwin\lib).  I
> also have GNUWin32, also for file.exe alternatively (and
> libmagic.dll.a @ ~ 8KB in C:\Program Files\GnuWin32\lib).
>
> magic.py in C:\Program Files\Python25\Lib\site-packages\magic-0.1-
> py2.5-win32.egg imports cmagic.py (also in this egg), which imports
> _cmagic.py, which has the following:
>
> def __bootstrap__():
>global __bootstrap__, __loader__, __file__
>import sys, pkg_resources, imp
>__file__ =
> pkg_resources.resource_filename(__name__,'_cmagic.pyd')
>del __bootstrap__, __loader__
>imp.load_dynamic(__name__,__file__)
> __bootstrap__()
>
> Now I *presume* my problem (at this point) is that I need to have
> libmagic named as "magic1.dll" -wherever- this module is looking for
> it.  I'm just not sure, let alone if this is true, WHERE Python/
> modules expect to find such things.
>
> Also, which version(s)/file(s) should be placed where, or...??
>
> Thanks for any/all help/pointers.  I apologize up-front if I left out
> any pertinent info; I'm paranoid about putting in too much (and some
> that may be worthless) already...  :)
>
> Cheers,
> Larry Hale

ALSO: I've even tried putting the 4 "magic" files INTO the .egg
file... still no-go.  :/


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


Re: anonymous assignment

2008-05-11 Thread Yves Dorfsman

Paul Rubin wrote:

Yves Dorfsman <[EMAIL PROTECTED]> writes:

import time
y, None, d, None, None, None, None = time.localtime()

I know you can't assign anything to None, but I'm sure you get what I
mean, a special keyword that means I don't care about this value.


You can just use a variable name than you ignore.  It's traditional to
use _ but it's not a special keyword, it's just a another variable name:

   y, _, d, _, _, _, _, _, _ = time.localtime()


But you still have have a variable that's using memory for nothing. I find 
this unsatisfactory... I don't want to compare languages, but I find the 
perl "undef" elegant.



Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Convention for name indicating "don't care about the value" (was: Is using range() in for loops really Pythonic?)

2008-05-11 Thread Ben Finney
Carl Banks <[EMAIL PROTECTED]> writes:

> On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
> > In such cases, the name 'dummy' is conventionally bound to the items
> > from the iterator, for clarity of purpose::
> >
> > for dummy in range(10):
> > # do stuff that makes no reference to 'dummy'
> 
> Is this documented?

It's not a documented standard, to my knowledge.

> I've never heard of this convention. It's not PEP 8, and I've never
> seen consistent usage of any name. I'd be interested in knowing
> where you read that this was a convention, or in what subcommunities
> it's a convention in.

It has been in this forum that the use of the name '_' for "don't care
about the value" was deprecated, since that name is already overloaded
with other meanings.

> I think dummy is a terrible name to use for this, since in no other
> usage I can think of does the word "dummy" suggest something isn't
> used.

I think it's far superior to '_'. I'd be just as happy with any other
name that explicitly distinguishes itself for this purpose.

> If a value isn't used, then I think the most clear name for it is
> "unused".

Sounds good to me. Now we merely need to convince the world.

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__) highwayman.” —Anthony Taylor |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: anonymous assignment

2008-05-11 Thread Yves Dorfsman

D'Arcy J.M. Cain wrote:

On Mon, 12 May 2008 02:28:13 GMT
Yves Dorfsman <[EMAIL PROTECTED]> wrote:

particular case, there's got to be a better way than:

d = time.local()
y = d[0]
d = d[1]


Like this?

y, d = time.local()[:2]


Sorry this was a typo (again :-), I meant:

d = time.local()
  y = d[0]
  d = d[2]

Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Ben Finney
Paul Rubin  writes:

> Yves Dorfsman <[EMAIL PROTECTED]> writes:
> > I know you can't assign anything to None, but I'm sure you get what I
> > mean, a special keyword that means I don't care about this value.

Snap. This topic was raised today in another thread.

> You can just use a variable name than you ignore. It's traditional
> to use _ but it's not a special keyword, it's just a another
> variable name:
> 
>y, _, d, _, _, _, _, _, _ = time.localtime()

It's a terrible name for that purpose, since it doesn't indicate the
intention explicitly, and it's already overloaded in meaning by a
pre-existing convention (ref. the 'gettext' module in Python and many
other languages).

Far better to use the name 'unused' as suggested by Carl Banks earlier
today.

(good sigmonster, have a cookie)

-- 
 \"Choose mnemonic identifiers. If you can't remember what |
  `\mnemonic means, you've got a problem." —Larry Wall |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread John Salerno
Ben Finney wrote:

> John Salerno <[EMAIL PROTECTED]> writes:
>
>> num = 33
>> 
>> for x in xrange(10):
>> print num += 1
>
> Which is better done by 'num += 10'.
>
> Can you come up with an example that isn't trivially replaced with
> clearer code? That might make it clearer what your concern is.

::sigh:: No, unfortunately I don't have a strong enough grasp of Python
to give a really in-depth example. I understand what you're asking
though. Perhaps people don't use this idiom as much as I think they do,
so to give a trivial example to support my point isn't helpful.

As far as I know, though, I think this is used often enough, so I
thought I'd just ask if there are purists out there who don't like this
use of the loop and feel it's an abuse of the syntax.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Michael Torrie
Larry Hale wrote:
> ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> file... still no-go.  :/

It's often the custom of programs ported from unix to windows to use the
dll location as a key to find the other files that are typically in
share, or etc.  GTK, for example uses ../share and ../etc from the
location where the dlls are stored (if the dlls are in a folder called bin).

In this case I'd try making a folder in the Python25 folder called
"share" and put the contents of the gnuwin32 share/file stuff in there.
 Should look something like this:

c:/python25/share/file/magic.mime.mgc
c:/python25/share/file/magic
c:/python25/share/file/magic.mgc
c:/python25/share/file/magic.mime

Or, judging by a string I found in the dll itself, you might have to put
the files here:

c:/progra~1/File/share/file/magic

Although if such a path really is hardcoded into the dll, this is
certainly a bug, since it will fail on certain non-english windows systems.

Anyway, who knows.  Give these options a try.

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


Re: threading - race condition?

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 13:16:25 -0300, skunkwerk <[EMAIL PROTECTED]> escribió:

> the only issue i have now is that it takes a long time for 100 threads
> to initialize that connection (>5 minutes) - and as i'm doing this on
> a webserver any time i update the code i have to restart all those
> threads, which i'm doing right now in a for loop.  is there any way I
> can keep the thread stuff separate from the rest of the code for this
> file, yet allow access?

Like using a separate thread to create the other 100?

-- 
Gabriel Genellina

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


Re: Convention for name indicating "don't care about the value" (was: Is using range() in for loops really Pythonic?)

2008-05-11 Thread Carl Banks
On May 11, 11:41 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Carl Banks <[EMAIL PROTECTED]> writes:
> > On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> > wrote:
> > > In such cases, the name 'dummy' is conventionally bound to the items
> > > from the iterator, for clarity of purpose::
>
> > > for dummy in range(10):
> > > # do stuff that makes no reference to 'dummy'
>
> > Is this documented?
>
> It's not a documented standard, to my knowledge.
>
> > I've never heard of this convention. It's not PEP 8, and I've never
> > seen consistent usage of any name. I'd be interested in knowing
> > where you read that this was a convention, or in what subcommunities
> > it's a convention in.
>
> It has been in this forum that the use of the name '_' for "don't care
> about the value" was deprecated, since that name is already overloaded
> with other meanings.

That doesn't follow at all from what you wrote: no one in this thread
had even mentioned the usage of "_" for unused values--how did you
expect us to know you were talking about something no one brought up?

So it seems that usage of "dummy" is not a convention, and avoidance
of "_" is not really a convention except on this group.


> > I think dummy is a terrible name to use for this, since in no other
> > usage I can think of does the word "dummy" suggest something isn't
> > used.
>
> I think it's far superior to '_'. I'd be just as happy with any other
> name that explicitly distinguishes itself for this purpose.
>
> > If a value isn't used, then I think the most clear name for it is
> > "unused".
>
> Sounds good to me. Now we merely need to convince the world.

I'm happy to discourage the world from using "_" for this purpose;
ambivalent whether you even need to use a specific name.


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


Re: Free Memory

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 01:06:13 -0300, Patrick Mullen <[EMAIL PROTECTED]> escribió:

> Yeah I don't know much about locals or globals.  I've never used them
> before, just know they are there.  But anyway, to illustrate what I meant by
> the interesting behavior, here is the output (and sorry for it being so
> long):
>
> IDLE 2.6a2
 globals()
> {'__builtins__': , '__name__': '__main__',
> '__doc__': None, '__package__': None}
 globals().clear()
 globals()
> {'__builtins__': {'bytearray': , 'IndexError':  'exceptions.WindowsError'>}}

>
> The OP wanted to clear the interpreter and I took a very broad (and highly
> unresearched) stab at it, and saw some behavior that I wasn't expecting.
> So before, all the builtin variables are hidden away in __builtins__, but
> after clearing globals, they are filled into globals.  This doesn't really
> make sense to me, but I don't know much about __builtins__ or globals.

Look more carefully:

py> globals().clear()
py> len(globals())
1
py> globals().keys()
['__builtins__']

globals() contains now a single entry, the namespace of the __builtin__ module 
(that is, __builtin__.__dict__), not the individual builtin entries (these are 
the dictionary entries that you posted).
As you later noticed, this happens only on IDLE. I don't know why IDLE behaves 
that way, but avoid entering "restricted mode" may be a reason (see 
http://docs.python.org/lib/restricted.html )
Usually, __builtins__ contains a reference to the __builtin__ module itself 
*only* in __main__; in all other modules, __builtins__ contains a reference to 
the __builtin__ namespace (like what you got in IDLE after clearing globals). I 
don't know *why* they are different either.

-- 
Gabriel Genellina

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


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
THANKS, AGAIN, for the reply!  :)

Okay, now I -really- feel silly...  :>

So, when I was going to try what you'd suggested, I noticed something
peculiar: I hadn't "changed" anything on my system, but now, when I
tried to "import magic" I got a missing DLL error.  For a DIFFERENT
DLL!  This got me to thinking...

Turns out, when I was having "success" earlier, I was -in- the C:
\Program Files\GnuWin32\bin directory (where file.exe and related .dll
files are).

So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
PATH.  Everything worked.  I removed all the copious copies of the
DLL, the magic files, etc., littering my hard drive in every other
location.  Still worked.

'Course, I don't honestly know why it didn't work with the files
copied to other locales contained in the sys/Py paths... perhaps it
was, as you mentioned, wanting the tree-structure to be the same?  (I
haven't the heart to check this out fully right now... *maybe* at a
later time...  ;) )

Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
THAT... you know, all the "obvious"/"I've been programming/working in
computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
'hacker'..." stuff.  I -swear-!

[EGG ON FACE]

[SIGH]  Well, I'd say "live and learn", but I'm still scratching my
head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
off to work _with_ the module now, then work-up my HowTo (and
experiment with making an "egg"?? ;) )...


Caio!
-Larry  :P  :)



On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
> Larry Hale wrote:
> > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > file... still no-go.  :/
>
> It's often the custom of programs ported from unix to windows to use the
> dll location as a key to find the other files that are typically in
> share, or etc.  GTK, for example uses ../share and ../etc from the
> location where the dlls are stored (if the dlls are in a folder called bin).
>
> In this case I'd try making a folder in the Python25 folder called
> "share" and put the contents of the gnuwin32 share/file stuff in there.
>  Should look something like this:
>
> c:/python25/share/file/magic.mime.mgc
> c:/python25/share/file/magic
> c:/python25/share/file/magic.mgc
> c:/python25/share/file/magic.mime
>
> Or, judging by a string I found in the dll itself, you might have to put
> the files here:
>
> c:/progra~1/File/share/file/magic
>
> Although if such a path really is hardcoded into the dll, this is
> certainly a bug, since it will fail on certain non-english windows systems.
>
> Anyway, who knows.  Give these options a try.

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


Accepting text input

2008-05-11 Thread Collin
I'm pretty new to Python, but this has really bugged me. I can't find a 
way around it.



The problem is that, when I use raw_input("sajfasjdf") whatever, or 
input("dsjfadsjfa"), you can only have numerical values as answers.


Any help would be appreciated. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accepting text input

2008-05-11 Thread Collin

Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't find a 
way around it.



The problem is that, when I use raw_input("sajfasjdf") whatever, or 
input("dsjfadsjfa"), you can only have numerical values as answers.


Any help would be appreciated. Thanks.



Oh, wow. I feel so stupid. Please disregard this message. <_<

I read the error message just now a bit more carefully, and I tried 
something. I tried defining "yes" as some random numerical value. Then 
when I did:

(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ivan Illarionov
>> In such cases, the name 'dummy' is conventionally bound to the items
>> from the iterator, for clarity of purpose
[..]
> If a value isn't used, then I think the most clear name for it is
> "unused".
[...]

Maybe my brain works differently, but I find both "dummy" and "unused" 
are extremely confusing names for loop counters. The loop begins to look 
like it doesn't iterate at all if its counter is dummy or unused.

If it *counts* it is *used* and it's *not* dummy.

Why reinvent the wheel when "a common identifier naming convention is for 
the loop counter to use the variable names i, j and k (and so on if 
needed)" (from Wikipedia http://en.wikipedia.org/wiki/Loop_counter )

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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
John Salerno <[EMAIL PROTECTED]> writes:

> Ben Finney wrote:
> 
> > John Salerno <[EMAIL PROTECTED]> writes:
> >
> >> num = 33
> >> 
> >> for x in xrange(10):
> >> print num += 1
> >
> > Which is better done by 'num += 10'.
> >
> > Can you come up with an example that isn't trivially replaced with
> > clearer code? That might make it clearer what your concern is.
> 
> ::sigh:: No, unfortunately I don't have a strong enough grasp of
> Python to give a really in-depth example.

It need not be in-depth, merely illustrative of the problem being
addressed.

> I understand what you're asking though. Perhaps people don't use
> this idiom as much as I think they do, so to give a trivial example
> to support my point isn't helpful.

I think that the idiom

for unused in xrange(10):
# do stuff with no reference to 'unused'

is quite common. Is that what you're asking about?

> As far as I know, though, I think this is used often enough, so I
> thought I'd just ask if there are purists out there who don't like
> this use of the loop and feel it's an abuse of the syntax.

No, it seems quite a normal usage of the syntax and a good use of an
iterator.

With "do something N times", there must be *something* to keep track
of which iteration we're up to (or, equivalently, how many iterations
remain) at a given moment. A Python iterator seems a fine choice to
hold that information, and better than many alternatives.

-- 
 \ "My house is on the median strip of a highway. You don't really |
  `\notice, except I have to leave the driveway doing 60 MPH."  -- |
_o__)Steven Wright |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread MC

Hi!


You want 2*(3+4) to return (7,7)?


For have that:  2*(3+4,)




--
@-salutations

Michel Claveau


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


Re: pickle problem

2008-05-11 Thread castironpi
On May 11, 6:21 pm, [EMAIL PROTECTED] wrote:
> On May 8, 7:29 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 8, 4:35 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
> > > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>
> > > > On Thu, 08 May 2008 08:55:35 -0700, krustymonkey wrote:
>
> > > >> The thing is, I'm not using slots by choice.  I'm using the standard
> > > >> lib "socket" class, which apparently uses slots.
>
> > > > `socket` objects can't be pickled.  Not just because of the
> > > > `__slot__`\s but because a substantial part of their state lives in
> > > > the operating system's space.
>
> > > Of course, if it makes sense to pickle sockets in the application, one
> > > is can do so by defining __getstate__ and __setstate__:
>
> > > class Connection(object):
> > >     def __init__(self, host, port):
> > >         self.host = host
> > >         self.port = port
> > >         self.init_sock()
>
> > >     def init_sock(self):
> > >         self.sock = socket.socket()
> > >         self.sock.connect((host, port))
> > >         ... init communication ...
>
> > >     def __getstate__(self):
> > >         # pickle self as a (host, port) pair
> > >         return self.host, self.port
>
> > >     def __setstate__(self, state):
> > >         # reinstate self by setting host and port and
> > >         # recreating the socket
> > >         self.host, self.port = state
> > >         self.init_sock()
>
> > I, local, am mystified that you'd want to pickle a socket.  It's a
> > live connection, which flies on a pocket dollar.  You don't want it on
> > disk, do you?
>
> > If you're running a net buoy through a cluster somewhere, do you want
> > to drop a server and reconnect?  Is Amazon's EC2 up and running?
>
> > Certainly no one was talking on the internet.  Were you?
>
> > I don't think you hit anything but banks surfing the web, and the
> > American dollar is notoriously stuffy.  Pump a wi-fi to a diner,
> > though, and you're just talking more.  Where's Usenet?
>
> The idea is a pre-fork socket server.  What I want to do is fork off
> some child processes from the parent and use IPC to send the
> connection object (via socket.accept()) over a pipe to one of the
> preexisting child processes and have said child handle the
> transaction.  Think Apache, if you want an example of what I'm trying
> to do here.  This alleviates the process startup cost that occurs when
> you fork.  If the socket object can't be serialized, is there another
> way to go about handling this in python?- Hide quoted text -
>
> - Show quoted text -

That's out of my expertise.  You would have to either hack it on a
router you are running (masquerade), or choose a different family of
sockets.  For HTTP, you could issue a 'reroute' return.  Just multi-
thread your server process.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python, are you ill?

2008-05-11 Thread castironpi
On May 11, 6:26 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
> >If you are in the interactive prompt of the Python interpreter and you
> >do this
>
> >print """Testing\"""   or   print '''Testing\'''
>
> >you get three dots [...] as if Python expects a code block.
>
> ...which it does.
>
> >If you
> >press Enter, you get three dots again, and again, and again... You
> >can't get out of the code block with pressing the Enter key; you have
> >to press Ctrl+Z (if you're in Linux) in order to get out of that code
> >block,
>
> No, you don't.  You can also enter """ or ''' to properly close the quote.
>
> >If you do
>
> >print "Testing\"   or   print 'Testing\'
>
> >you get an error, but not of you use the triple quotes. Is that a bug
> >in the interpreter perhaps?
>
> As a general rule, when you are just beginning to learn some product, it is
> safe to assume that anything you see as a bug in the product is almost
> certainly a flaw in your understanding of the product.
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.

I hold further, it is more profitable, unless you can change it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accepting text input

2008-05-11 Thread Gabriel Genellina
En Mon, 12 May 2008 01:54:28 -0300, Collin <[EMAIL PROTECTED]> escribió:

> Collin wrote:
>> I'm pretty new to Python, but this has really bugged me. I can't find a
>> way around it.
>>
>>
>> The problem is that, when I use raw_input("sajfasjdf") whatever, or
>> input("dsjfadsjfa"), you can only have numerical values as answers.
>>
>> Any help would be appreciated. Thanks.
>
>
> Oh, wow. I feel so stupid. Please disregard this message. <_<

No need to apologize...

> I read the error message just now a bit more carefully, and I tried
> something. I tried defining "yes" as some random numerical value. Then
> when I did:
> (example code)
>
> yes = 123123983 #some number
> test = input("Test test test ")
> if test == yes:
>   print "It worked."
> else:
>   print "failed"
>
> (example code off)

The usual way for Python<3.0 is:

answer = raw_input("Test test test ").lower()
if answer == "yes":
 ...

The input() function evaluates user input as an expression: if he types 2+5 the 
input() function returns the integer 7. I would never use input() in a program 
- it's way too unsafe; use always raw_input instead.

-- 
Gabriel Genellina

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


Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
Hi,

Again a noob question.

Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is it
correct to conclude that there is no RDBMS agnostic, single/uniform DB
access API for Python ?
Something in the lines of JDBC for Java, DBD for Perl etc. ?

How is the RDBMS change handled for solutions which need to work with
different RDBMSs ??

-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Mathematics in Python are not correct

2008-05-11 Thread Terry Reedy

"Mark Dickinson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
|> Do you have in mind any situations in which it is advantageous to have 
0**0
|> undefined?

| (Playing devil's advocate here.) If you regard x**y as exp(y*log(x))

Which, of course, I was not, but for the sake of discussion

| then it's not at all clear that 0.**0. should be considered well-defined.

Then it seems equally dubious that 0.**y, y>0, should be well-defined.
It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well 
defined whether y is 0 or not, even though there is a discontinuity in the 
limit.
.
...
| The big problem here is that the power operation is really trying
| to combine two subtly different functionalities (integer powers
| and real powers), with quite distinct use-cases, into a single
| function.  Which leads to problems:  witness the mess that's
| C99's pow specification:  why does it make sense for (-2.0)**2.0 to
| return 4.0, while (-2.0)**1.9 returns NaN?

2.5 raises an exception.  In 3.0,
>>> (-2)**1.
(3.999722741113-1.2566370355167477e-07j)

| Incidentally, the decimal module is slightly schizophrenic about this:

That module follows the IBM-led standard, no matter how crazy.

Terry Jan Reedy



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


Re: anonymous assignment

2008-05-11 Thread Marc 'BlackJack' Rintsch
On Mon, 12 May 2008 03:40:03 +, Yves Dorfsman wrote:

> Paul Rubin wrote:
>
>> You can just use a variable name than you ignore.  It's traditional to
>> use _ but it's not a special keyword, it's just a another variable
>> name:
>> 
>>y, _, d, _, _, _, _, _, _ = time.localtime()
> 
> But you still have have a variable that's using memory for nothing. I
> find this unsatisfactory...

Get over it…

Or use `operator.itemgetter()`:

In [36]: operator.itemgetter(0, 2)(time.localtime())
Out[36]: (2008, 12)

:-)

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Re: Best technology for agent/web server architecture

2008-05-11 Thread Gabriel Genellina
> 2008/5/8 M.-A. Lemburg <[EMAIL PROTECTED]>:
>
>> SOAP would be a good choice if you want to send to data to other
>> servers as well, e.g. Java-based ones.
>>
>> XML-RPC and JSON are better for simple data structures.
>>
>> If you have control over both client and server and don't
>> need to bother with other backends or frontends, Python
>> pickle is the best choice.

En Fri, 09 May 2008 05:41:07 -0300, Florencio Cano <[EMAIL PROTECTED]> escribió:

> I have control over agent and client but I'm not sure how to use
> pickle for this task. Do you suggest to pickle the objects that I want
> to send and send it over a usual socket? I have searched a bit in
> Google and I have seen that Pickle is insecure by default. What do you
> think about this?

"insecure" means that someone could build a specially crafted pickle able to 
run arbitrary code on the unpickling environment. One way to avoid that is to 
only accept pickles from trusted sources: using SSL by example.

-- 
Gabriel Genellina

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


hai friends

2008-05-11 Thread chandran . ramu1
hai dear,
"may all good things come into your life today and always"
www.goodhistory5.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
Ivan Illarionov <[EMAIL PROTECTED]> writes:

> >> In such cases, the name 'dummy' is conventionally bound to the items
> >> from the iterator, for clarity of purpose
> [..]
> > If a value isn't used, then I think the most clear name for it is
> > "unused".
> [...]
> 
> Maybe my brain works differently, but I find both "dummy" and
> "unused" are extremely confusing names for loop counters. The loop
> begins to look like it doesn't iterate at all if its counter is
> dummy or unused.
> 
> If it *counts* it is *used* and it's *not* dummy.

The value is unused by any of the code inside the block. For the
purposes of that block, it is a dummy value.

That something *else* (the iterator driving the 'for') is taking care
of knowing when the loop is finished is great. However, in the code
the programmer is writing, the loop counter is entirely unused.

> Why reinvent the wheel when "a common identifier naming convention
> is for the loop counter to use the variable names i, j and k (and so
> on if needed)" (from Wikipedia
> http://en.wikipedia.org/wiki/Loop_counter )

That is also regrettably common in Python code. It still suffers from
being unnecessarily ambiguous, since there are *also* plenty of loops
using 'i', 'j', etc. where the loop counter *is* used.

Differentiating these use cases by appropriate naming is, IMO, worth
the effort of choosing a meaningful name.

-- 
 \  "Ignorance more frequently begets confidence than does |
  `\   knowledge." —Charles Darwin, _The Descent of Man_, 1871 |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: cgitb performance issue

2008-05-11 Thread Gabriel Genellina
En Mon, 05 May 2008 15:56:26 -0300, Ethan Furman <[EMAIL PROTECTED]> escribió:

> I tried adding a form to our website for uploading large files.
> Personally, I dislike the forms that tell you you did something wrong
> and make you re-enter *all* your data again, so this one cycles and
> remembers your answers, and only prompts for the file once the rest of
> the entered data is good.  However, the first time the form loads it can
> take up to 30 seconds... any ideas why?

Hard to tell without looking at the code... And what has cgitb to do with this?

-- 
Gabriel Genellina

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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Paddy
On May 11, 9:28 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
Hi John, Arnaud;

> Contrived example:
>
> # Print 'hello' 10 times; x is not used
> for x in xrange(10):
> print 'hello'

I've used Fortran and C and so would tend to use either i,j,k as the
unused loop variable above, or, for clarity, call it something
descriptive like loop_count, if the loop body would be clearer.

I would also just use range for small, (especially small constant),
ranges.

>
> # By changing what is iterated over, no unused variable:
> from itertools import repeat
> for msg in repeat('hello', 10):
> print msg
I guess I would not go to the trouble of using itertools.repeat unless
it was simplifying/homogenising a larger expression - i.e if it was
part of some functional expression

I've never fealt the need for a separate repeat statement myself
either.

- Paddy.

P.S: I do understand that your examples are contrived. Just my
thoughts.

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


Re: anonymous assignment

2008-05-11 Thread Ben Finney
Yves Dorfsman <[EMAIL PROTECTED]> writes:

> Paul Rubin wrote:
> > Yves Dorfsman <[EMAIL PROTECTED]> writes:
> >> import time
> >> y, None, d, None, None, None, None = time.localtime()
> >>
> >> I know you can't assign anything to None, but I'm sure you get what I
> >> mean, a special keyword that means I don't care about this value.
> >
> > You can just use a variable name than you ignore.  It's traditional to
> > use _ but it's not a special keyword, it's just a another variable name:
> >
> >y, _, d, _, _, _, _, _, _ = time.localtime()
> 
> But you still have have a variable that's using memory for nothing.

No, you have one extra unused name binding. The values that you don't
want to use have *already* been allocated by the time the above
statement is executed. Name binding doesn't copy the values, it merely
binds a name to them. There's no "variable" in the above statement.

-- 
 \   “Holy human pressure cookers, Batman!” —Robin |
  `\   |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: anonymous assignment

2008-05-11 Thread Arnaud Delobelle
Yves Dorfsman <[EMAIL PROTECTED]> writes:

> Is there anyway to tell python I don't care about a value ?
>
> Say I want today's year and day, I'd like to do something like:
>
> import time
> y, None, d, None, None, None, None = time.localtime()
>
> I know you can't assign anything to None, but I'm sure you get what I
> mean, a special keyword that means I don't care about this value. In
> this particular case, there's got to be a better way than:
>
> d = time.local()
> y = d[0]
> d = d[1]
>

I use Paul Rubin's solution (which is frown upon by many:), but it's
true it would be nice for tuples to have something like an extract()
method:

y, d = time.localtime.extract(0, 2)

Where 

mytuple.extract(i1, i2, i3...)

would mean:

tuple(mytuple[i] for i in (i1, i2, i3...))

Or perhaps allow indexing by tuples:

mytuple[i1, i2, i3...]

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


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply!  :)
>
> Okay, now I -really- feel silly...  :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error.  For a DIFFERENT
> DLL!  This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH.  Everything worked.  I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location.  Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same?  (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time...  ;) )
>
> Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff.  I -swear-!
>
> [EGG ON FACE]
>
> [SIGH]  Well, I'd say "live and learn", but I'm still scratching my
> head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry  :P  :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go.  :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc.  GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> >  Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows.  Give these options a try.



UPDATE: HOORAY!!!  Well, actually, was about two steps forward, one
back.  But I've gotten it all sorted out now!  :)

I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.

The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages.  I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong.  These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.

If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:

>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with...  :)
'MS-DOS executable, MZ for MS-DOS'  # <-- This is what's
returned...

Alternately, if one wishes to leave/place the magic files elsewhere,
do like:

>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is

NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine.  (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.)  Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file )  :)


THANKS SO MUCH, Michael, for your answers and helping me alone the
way...  :)


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


Re: computing with characters

2008-05-11 Thread Gabriel Genellina
En Tue, 06 May 2008 08:16:55 -0300, <[EMAIL PROTECTED]> escribió:

> I tend to do ", ".join("%s" % e for e in item)
>
> Is there any difference between this and str()?

Use the timeit module to measure performance:

C:\TEMP>python -m timeit "for i in xrange(1): str(i)"
10 loops, best of 3: 81.8 msec per loop

C:\TEMP>python -m timeit "for i in xrange(1): '%s' % i"
10 loops, best of 3: 78.5 msec per loop

The %s version consistently wins in my system -2.5.1 on WinXP- for a wide range 
of inputs.

-- 
Gabriel Genellina

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


Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Laszlo Nagy

Banibrata Dutta írta:

Hi,
 
Again a noob question.
 
Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is 
it correct to conclude that there is no RDBMS agnostic, single/uniform 
DB access API for Python ?

Something in the lines of JDBC for Java, DBD for Perl etc. ?
 
How is the RDBMS change handled for solutions which need to work with 
different RDBMSs ??

http://www.python.org/dev/peps/pep-0249/

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


Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
On 5/12/08, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>
> Banibrata Dutta írta:
>
>> Hi,
>>  Again a noob question.
>>  Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is it
>> correct to conclude that there is no RDBMS agnostic, single/uniform DB
>> access API for Python ?
>> Something in the lines of JDBC for Java, DBD for Perl etc. ?
>>  How is the RDBMS change handled for solutions which need to work with
>> different RDBMSs ??
>>
> http://www.python.org/dev/peps/pep-0249/
>


That appears to be only an API specification. Are there any implementations
of that ?

-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
Found that SnakeSQL does implement DB2.0 API. However are there such
implementations for MySQL ?

On 5/12/08, Banibrata Dutta <[EMAIL PROTECTED]> wrote:
>
>
> On 5/12/08, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>>
>> Banibrata Dutta írta:
>>
>>> Hi,
>>>  Again a noob question.
>>>  Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is
>>> it correct to conclude that there is no RDBMS agnostic, single/uniform DB
>>> access API for Python ?
>>> Something in the lines of JDBC for Java, DBD for Perl etc. ?
>>>  How is the RDBMS change handled for solutions which need to work with
>>> different RDBMSs ??
>>>
>> http://www.python.org/dev/peps/pep-0249/
>>
>
>
> That appears to be only an API specification. Are there any implementations
> of that ?
>
> --
> regards,
> Banibrata
> http://www.linkedin.com/in/bdutta
> http://octapod.wordpress.com
>



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply!  :)
>
> Okay, now I -really- feel silly...  :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error.  For a DIFFERENT
> DLL!  This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH.  Everything worked.  I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location.  Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same?  (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time...  ;) )
>
> Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff.  I -swear-!
>
> [EGG ON FACE]
>
> [SIGH]  Well, I'd say "live and learn", but I'm still scratching my
> head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry  :P  :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go.  :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc.  GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> >  Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows.  Give these options a try.



UPDATE: HOORAY!!!  Well, actually, was about two steps forward, one
back.  But I've gotten it all sorted out now!  :)

I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.

The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages.  I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong.  These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.

If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:

>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with...  :)
'MS-DOS executable, MZ for MS-DOS'  # <-- This is what's
returned...

Alternately, if one wishes to leave/place the magic files elsewhere,
do like:

>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is

NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine.  (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.)  Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file )  :)


THANKS SO MUCH, Michael, for your answers and helping me alone the
way...  :)


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


Re: Initializing a subclass with a super object?

2008-05-11 Thread Francesco Bochicchio
On Sat, 10 May 2008 18:09:02 -0700, frankdmartinez wrote:

> Hi, Terry.
> Yeah, no.  If we think of the inherited B as an object nested
> within a1, I'm attempting to initialize that B with b1 by accessing
> the B, say, via a function call.  I don't see how using a python
> factory achieves this.

But there is not such a thing, in Python. What you have is that A
has the same attributes/methods of B plus its own. 
What you could do is  adding in class A a method like this:

  class A(B):
 ...
 def set_b_attributes(self, instance_of_b):
 for k, value in instance_of_b.__dict__:
setattr(self, k, value )

and the use it like this:

   a1.set_b_attributes(b1)

Of course, if b attributes are few and always the same it is more
readable assigning them explicitely:

 def set_b_attributes(self, instance_of_b):
 self.attr1 = instance_of_b.attr1
 self.attr2 = instance_of_b.attr2
 

Ciao
-
FB



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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread XLiIV
On May 11, 4:19 am, John Salerno <[EMAIL PROTECTED]> wrote:
> I know it's popular and very handy, but I'm curious if there are purists
> out there who think that using something like:
>
> for x in range(10):
>     #do something 10 times
>
> is unPythonic. The reason I ask is because the structure of the for loop
> seems to be for iterating through a sequence. It seems somewhat
> artificial to use the for loop to do something a certain number of
> times, like above.
>
> Anyone out there refuse to use it this way, or is it just impossible to
> avoid?

The range() function returns a list and list is a sequence, isn't?

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


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread castironpi
On May 11, 12:38 am, Paul Rubin  wrote:
> John Salerno <[EMAIL PROTECTED]> writes:
> > for x in range(10):
> >     #do something 10 times
>
> > is unPythonic. The reason I ask is because the structure of the for loop
> > seems to be for iterating through a sequence. It seems somewhat
> > artificial to use the for loop to do something a certain number of
> > times, like above.
>
> It is pretty natural in imperative-style code.  The one thing I'd do
> differently is use xrange instead of range, to avoid creating a
> 10-element list in memory before starting the loop.

If you give extras to memory, can Python live?
--
http://mail.python.org/mailman/listinfo/python-list


Some error messages in Python are ugly

2008-05-11 Thread wxPythoner
This really looks ugly for an error message:

[1]+  Stopped python


Please explain to me the role of the '+' sign. And why is there such a
gap between 'Stopped' and 'python'?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Any other UI kits with text widget similar to that in Tk?

2008-05-11 Thread Neil Hodgson

Kenneth McDonald:
I'm wondering if any of the other GUI kits have a text widget that is 
similar in power to the one in Tk.


   The main text widget in GTK+ was modeled after Tk but I don't know 
how well it succeeded in implementing this.


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


Unimport statement

2008-05-11 Thread wxPythoner
We should have that statement, so that problems, expressed in
http://groups.google.com/group/comp.lang.python/browse_thread/thread/3bda1fc4895ec886/bc5fe40cfbd10124?lnk=raot#bc5fe40cfbd10124,
would not occur.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Some error messages in Python are ugly

2008-05-11 Thread Marc 'BlackJack' Rintsch
On Sun, 11 May 2008 01:10:19 -0700, wxPythoner wrote:

> This really looks ugly for an error message:
> 
> [1]+  Stopped python

It's neither an error message nor does it come from Python.  It's a
message from your shell about job control.  Seems you have stopped the
running process, which happens to be Python, by pressing + or
- for example.

> Please explain to me the role of the '+' sign.

Refer to the manual of your shell.  I guess it says, that the stopped
process was/is the current job, i.e. the one commands like ``fg`` or
``bg`` operate on if you leave out the argument.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Some error messages in Python are ugly

2008-05-11 Thread Florencio Cano
This is not a Python error, this is a bash message that appears when
you press ctrl+z and put the application in the background. Execute fg
to return the app to the foreground.

2008/5/11  <[EMAIL PROTECTED]>:
> This really looks ugly for an error message:
>
> [1]+  Stopped python
>
>
> Please explain to me the role of the '+' sign. And why is there such a
> gap between 'Stopped' and 'python'?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unimport statement

2008-05-11 Thread Filip Štědronský
The main problem are references to objects within a module, because
we can NEVER be sure there aren't any, even though we cleaned up
everything, that's just a consequence of Python nature. We can keep
the old objects referenced and it would make an equivalent to the
reload() builting, just without loading the module, in effect the
same as removing it from sys.modules and deleting imported references.
I do not see any possibe clean way to unload a module...

On Ne, kvě 11, 2008 at 10:02:15 +0200, [EMAIL PROTECTED] wrote:
> We should have that statement, so that problems, expressed in
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/3bda1fc4895ec886/bc5fe40cfbd10124?lnk=raot#bc5fe40cfbd10124,
> would not occur.


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

what does int means for python ?

2008-05-11 Thread alefajnie
#!/usr/bin/env python

arr = [[0 for c in range(0, 10)] for r in range(0, 10)] #
10x10 array

arr[2,3] # throws TypeError: list indices must be
integers
arr[int(2), int(3)] # also throws TypeError: list indices must be
integers !

-
what is wrong in above script ?


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


Re: what does int means for python ?

2008-05-11 Thread Irmen de Jong

alefajnie wrote:

#!/usr/bin/env python

arr = [[0 for c in range(0, 10)] for r in range(0, 10)] #
10x10 array

arr[2,3] # throws TypeError: list indices must be
integers
arr[int(2), int(3)] # also throws TypeError: list indices must be
integers !

-
what is wrong in above script ?




try arr[2][3] instead.

basically your version is trying to index an array with a tuple argument (2,3).

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


Re: what does int means for python ?

2008-05-11 Thread alefajnie
>
> try arr[2][3] instead.
>
> basically your version is trying to index an array with a tuple argument 
> (2,3).
>
> --irmen


oh, you're right.

btw, is any simple way to create multi-dimension array ?
any built-in function ?
--
http://mail.python.org/mailman/listinfo/python-list


How to uninstall something installed by "setup.py install"?

2008-05-11 Thread tinnews
I have installed a development version of rdiff-backup using its
"setup.py install" but now find I need to uninstall it.  Is there any
'easy' way to do this and/or can I find out what files it has
installed where so I can remove them?

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


Re: what does int means for python ?

2008-05-11 Thread mimi.vx
On May 11, 12:05 pm, alefajnie <[EMAIL PROTECTED]> wrote:
> > try arr[2][3] instead.
>
> > basically your version is trying to index an array with a tuple argument 
> > (2,3).
>
> > --irmen
>
> oh, you're right.
>
> btw, is any simple way to create multi-dimension array ?
> any built-in function ?

test numpy from scipy package :)
on www.scipy.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-11 Thread Max M

[EMAIL PROTECTED] skrev:


I have two another interesting things to discuss about, for which I'll
open new posts on this group. Look for "Python doesn't recognize quote
types" and "Python, are you ill?".


You have a tendency to form your questions as complaints about Python 
being broken.


You will probably get better responses if you just state that there are 
things you do not understand, and ask why it works that way.



--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

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


Re: Some error messages in Python are ugly

2008-05-11 Thread george . f . rice
On May 11, 3:10 am, [EMAIL PROTECTED] wrote:
> This really looks ugly for an error message:
>
> [1]+  Stopped python
>
> Please explain to me the role of the '+' sign. And why is there such a
> gap between 'Stopped' and 'python'?

I suspect you were running the python command line in a Linux shell
such as bash, and pressed Control-Z.

The message you list above is NOT an error message from Python, but
rather an informational message from the Linux shell. The short answer
is to type "fg" and press Enter twice, and Python will resume
executing.

Here's the long answer.

This message from the Linux shell is telling you that the python
process (application) has been stopped, and is no longer executing.
"[1]" tells you the job number; Linux supports  multiple stopped jobs,
and gives each a number to make it easy for you to give them
commands.  "+" tells you that this is the "active job"; it's at the
top of the queue, and is the job that will respond to your job-related
commands by default (i.e., if you don't supply a job number).

You can list all jobs in the queue by typing "jobs" at the Linux shell
prompt. You can begin running the "active job" again by typing fg
(which means "foreground"); you could also switch the "active job" to
running in the background by typing bg, although that wouldn't be
useful with the Python shell.

You can learn more about managing jobs from the Python shell here:
http://www.slackbasics.org/html/chap-procmgmt.html

Great question!


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


Re: Python doesn't recognize quote types

2008-05-11 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> There's a thing that bugs me in Python. Look at this...
> 
 print "Testing\"
> SyntaxError: EOL while scanning single-quoted string
> 
> 
> Please focus on the part of the error message that states "while
> scanning single-quoted string". How can Python claim it scanned a
> single-quoted string when I fed it with a double-quoted string? Is
> quote type (single quote and double quote) recognition not implemented
> in Python?
> 
Of course it is, but that isn't what is meant here.

Python supports single-quoted strings which are delimited by either a 
single quote or a double quote mark. It also supports triple-quoted strings 
which are delimited either by three single quotes or three double quotes.

The overloaded meaning of 'single' is perhaps unfortunate.
--
http://mail.python.org/mailman/listinfo/python-list


Make Python create a tuple with one element in a clean way

2008-05-11 Thread wxPythoner
To create a tuple with one element, you need to do this:

>>> my_tuple = (1,)# Note the trailing comma after the value 1
>>> type(my_tuple)



But if you do this

>>> my_tuple = (1)
>>> type(my_tuple)


you don't get a tuple. I thought that just putting a value inside ( )
would make a tuple. Apparently that is not the case. I hate ugly code
so it would be clean if Python would convert anything put into ( ) to
be a tuple, even if just one value was put in (without having to use
that ugly looking comma with no value after it).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to uninstall something installed by "setup.py install"?

2008-05-11 Thread Ben Finney
[EMAIL PROTECTED] writes:

> I have installed a development version of rdiff-backup using its
> "setup.py install" but now find I need to uninstall it. Is there any
> 'easy' way to do this and/or can I find out what files it has
> installed where so I can remove them?

Sadly, the re-invention of package management as seen in
'easy_install' does not implement an "uninstall" command.

This is one reason why many of us avoid it and use system-wide package
management instead. Unfortunately, not all operating systems are
mature enough to have decent package management.

-- 
 \  "Yesterday I saw a subliminal advertising executive for just a |
  `\second."  -- Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread Filip Štědronský
Hello,

> so it would be clean if Python would convert anything put into ( ) to
> be a tuple, even if just one value was put in (without having to use
> that ugly looking comma with no value after it).

if it worked that way, it will absolutely mess up Python syntax, because
we mathematicians are used to use parentheses to force explicit operator
precedence, to group expressions, etc.

Should (1+1)*2 yield 4 or (2,2) ?

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


Problem with custom events in wxpython

2008-05-11 Thread Jimmy
hi, all

I'm having a problem with creating custom events in wxpython.

I have a class A handling some data processing work and another class
B of GUI matter. I need GUI to display information when data in A is
updated.
I know cutom events in wxpython may work. But I found no material
paricularly
helpful :(

can anyone write me some demo code to show how to do this or ant
reference to
materials? thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread alex23
On May 11, 10:54 pm, [EMAIL PROTECTED] wrote:
> I thought that just putting a value inside ( )
> would make a tuple. Apparently that is not the case.

It's not the case at all. Check out the Tuples & Sequences section in
the python docs at http://docs.python.org/tut/node7:

"A tuple consists of a number of values separated by commas"

So it's not the parentheses that define it as a tuple, but the comma.

>>> my_tuple = 1,
>>> my_tuple
(1,)
>>> type(my_tuple)


Hope this helps.

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


Re: Mathematics in Python are not correct

2008-05-11 Thread Grant Edwards
On 2008-05-11, Max M <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] skrev:
>
>> I have two another interesting things to discuss about, for
>> which I'll open new posts on this group. Look for "Python
>> doesn't recognize quote types" and "Python, are you ill?".
>
> You have a tendency to form your questions as complaints about
> Python being broken.
>
> You will probably get better responses if you just state that
> there are things you do not understand, and ask why it works
> that way.

The OP has already been banned from the wxWidgets IRC and the
wxPython mailing list.  His MO is to post a never ending stream
of whining, flame-bait, and demands that wxWidgets, wxPython,
(or whatever) be changed to suit his tastes regardless of the
justification for the current design and the amount of breakage
it would cause. wxPythoner (AKA "Chester) also seemed fond of
constantly giving wrong/misleading answers when other
inexperienced users asked technical questions.

He especially liked to post messages with subjects like "To
Rogin Dunn" and "To wxPython Developers" mailing list
instructing them to change various things in wxWidgets,
wxPython, and Python.  He consistently ignored pointers to
documentation and explanations of why things were done the way
they were.  

On top of all that, his fowl language and insulting attitude
finally got him banned:

http://article.gmane.org/gmane.comp.python.wxpython/58645
http://article.gmane.org/gmane.comp.python.wxpython/58695

So it's best to probably just ignore him...

-- 
Grant Edwards   grante Yow!  LBJ, LBJ, how many
  at   JOKES did you tell today??!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >