Announcing a feature update (v1.3) of YaMA, the meeting assistant

2008-05-12 Thread Atul
Hi,

Yet Another Meeting Assistant (YaMA), will help you with the Agenda,
Meeting Invitations, Minutes of a Meeting as well as Action Items. If
you are the assigned minute taker at any meeting, this tool is for
you.

Checkout http://yama.sourceforge.net/

YaMA is written in Python and Tkinter, is open source software
released under GPLv2, and is hosted by SourceForge
(www.sourceforge.net)

Whats New in version 1.3 :

1. Usability enhancements
2. Minor Bug Fixes
3. Export Meeting Invitation and Action Items to iCalendar format to
interoperate with other calendaring applications.

Thanks and Regards,
--
Atul
--
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Mathematics in Python are not correct

2008-05-12 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, y0, 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-12 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-12 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-12 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-12 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-12 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-12 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-12 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-12 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-12 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-12 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:\TEMPpython -m timeit for i in xrange(1): str(i)
10 loops, best of 3: 81.8 msec per loop

C:\TEMPpython -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-12 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-12 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-12 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-12 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: Is using range() in for loops really Pythonic?

2008-05-12 Thread Ivan Illarionov
On Mon, 12 May 2008 16:24:23 +1000, Ben Finney wrote:
[...]
 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.

Even if the counter is not used inside the loop's body it's still in 
control of the whole loop and, IMO, any special discriminating and non-
conventional name doesn't worth the added confusion.

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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Gabriel Genellina
En Sat, 10 May 2008 22:12:37 -0300, globalrev [EMAIL PROTECTED] escribió:

 http://reddit.com/r/programming/info/18td4/comments

 claims people take a lot of time to write a simple program like this:


 Write a program that prints the numbers from 1 to 100. But for
 multiples of three print Fizz instead of the number and for the
 multiples of five print Buzz. For numbers which are multiples of
 both three and five print FizzBuzz.

 for i in range(1,101):
 if i%3 == 0 and i%5 != 0:
 print Fizz
 elif i%5 == 0 and i%3 != 0:
 print Buzz
 elif i%5 == 0 and i%3 == 0:
 print FizzBuzz
 else:
 print i


 is there a better way than my solution? is mine ok?

Is it correct? Did you get at it in less than 15 minutes? If so, then it's OK.
The original test was not write the most convoluted algorithm you can think 
of, nor write the best program to solve this. It was a *practical* test: if 
you can't get anything remotely working for such a simple problem in 15 
minutes, we're not interested in your services.

(We used this question last year - some people gave a sensible answer in less 
than 5 minutes, but others did not even know how to start)

-- 
Gabriel Genellina

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


Re: Module python-magic on/for Windows?

2008-05-12 Thread Larry Hale
On May 12, 1:34 am, Larry Hale [EMAIL PROTECTED] wrote:

 The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
 has the man pages...


Err...  I meant http://downloads.sourceforge.net/gnuwin32/file-4.21-
bin.zip?modtime=1180175868big_mirror=1!  :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-12 Thread Larry Hale
On May 12, 1:34 am, Larry Hale [EMAIL PROTECTED] wrote:

 The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
 has the man pages...


Err...  I meant http://downloads.sourceforge.net/gnuwin32/file-4.21-
bin.zip?modtime=1180175868big_mirror=1!  :)
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-05-12 Thread Roel Schroeven

John Salerno schreef:

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.


Perhaps a function to print some text a number of times:

def print_n(text, n):
  for i in xrange(n):
print text

(Though I guess you can replace that with print '\n'.join(msg * n) )

--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

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


module global variables

2008-05-12 Thread pistacchio
hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and the Bartender

2008-05-12 Thread Aspersieman

[EMAIL PROTECTED] wrote:

Incidentally, now that everyone knows English, writer would like to
critique his behavior.  I have leaned to the group for approval, at
times by disparaging the efforts of others, but other times not.  I
have expressed negative emotion.  Is anyone in earshot getting work
done that I am interfering with?

Otherwise, I might start telling jokes.

Sincerely,
Two For Bartenders.

P.S.  Please don't write the movies.
--
http://mail.python.org/mailman/listinfo/python-list

  

Huh?

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


Re: File Creation Not Working In A Thread Class?

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

 On Sun, 11 May 2008 19:55:31 +, Duncan Booth wrote:
 
 7stud [EMAIL PROTECTED] wrote:
 
 
                             tempfileName =
 \proctemp\\                             +
 self.matrix[c][0] + _other.txt\
 
 It wouldn't exactly result in either of the error messages you
 posted, but I expect the spurious quote marks round the filename will
 be giving you problems.
 
 Surely you want the filename to be something like
 'proctemp\fred_other.txt' rather than 'proctemp\fred_other.txt'
 with the spurious double quotes?
 
 Yup, that's what it was.  I figured it out two seconds before this
 post.  However, it will be interesting to see how it handles files
 with spaces in the name...
 
It will handle spaces just fine.

You need to try and understand the difference between passing arguments to 
a program, where the shell will try to parse the command line into separate 
arguments so spaces have to be escaped somehow, and calling a function 
within a program where no such parsing takes place.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with custom events in wxpython

2008-05-12 Thread Jimmy
On May 11, 11:27 pm, Frank Niessink [EMAIL PROTECTED] wrote:
 Hi Jimmy,

 2008/5/11 Jimmy [EMAIL PROTECTED]:

  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.

 You may want to look at the pubsub module. Available as wx.lib.pubsub
 in wxPython:http://www.wxpython.org/docs/api/wx.lib.pubsub-module.html,
 and also available separately on PyPI:http://pypi.python.org/pypi/PyPubSub/

 Cheers, Frank

hi, thanks
it works! however, it seems the message can not be exchanged between
processes :(
actually what I want to do is let a running process send data to GUI
process and display it
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python doesn't recognize quote types

2008-05-12 Thread Duncan Booth
Dennis Lee Bieber [EMAIL PROTECTED] wrote:
  The sloppy use of single quote for the apostrophe is unfortunate
G

True, but that problem is outside of the Python community's control. Given 
that people do often refer to single quote when they mean apostrophe the 
error message should be written so as to minimise confusion. 

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


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

2008-05-12 Thread Ben Finney
Ivan Illarionov [EMAIL PROTECTED] writes:

 On Mon, 12 May 2008 16:24:23 +1000, Ben Finney wrote:
 [...]
  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.
 
 Even if the counter is not used inside the loop's body it's still in
 control of the whole loop

Not in Python it's not. The values that come out of the iterator
aren't in control of the loop. The state for the loop is in the
*iterator*, not the values that come out.

Having access to the values that come from the iterator is usually
useful, but regardless of whether one uses them or not, they're *not*
controlling the loop, and it's confusing to imply that they are.

So, when not using the values that come from the controlling iterator,
it's good to make that explicit. If Python supported it, we might
prefer to use no name at all for something that isn't used, but the
'for' syntax doesn't allow that.

In the absence of supporting syntax, the next best thing is to choose
a name that *does* make it explicit that the values will not be used.

-- 
 \ “All television is educational television. The question is: |
  `\   what is it teaching?” —Nicholas Johnson |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

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

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

 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.

The problem with all of these names is that they also have long
precedent as names of values that *will* be used inside the loop.

Because of the precedent of those names, choosing one of those names
doesn't make it clear to the reader that the value is never used; they
have no indication from you of that until they look over the code a
few times. It's implicit rather than explicit.

-- 
 \ As I bit into the nectarine, it had a crisp juiciness about it |
  `\  that was very pleasurable - until I realized it wasn't a |
_o__)nectarine at all, but A HUMAN HEAD!!  -- Jack Handey |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: source beautifier

2008-05-12 Thread Marco Mariani

Stefan Behnel wrote:


http://www.polystyle.com/features/python-beautifier.jsp

I've never used it, but the example is quite clear.


I tend to believe that running these tools on some average Python code would
not even change whitespace. ;)


I bet it's idempotent against _your_ code, but not in the context of 
python beginners or people who just made up their mind about what coding 
style to use.

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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread bockman
On 12 Mag, 09:00, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Sat, 10 May 2008 22:12:37 -0300, globalrev [EMAIL PROTECTED] escribió:





 http://reddit.com/r/programming/info/18td4/comments

  claims people take a lot of time to write a simple program like this:

  Write a program that prints the numbers from 1 to 100. But for
  multiples of three print Fizz instead of the number and for the
  multiples of five print Buzz. For numbers which are multiples of
  both three and five print FizzBuzz.

  for i in range(1,101):
      if i%3 == 0 and i%5 != 0:
          print Fizz
      elif i%5 == 0 and i%3 != 0:
          print Buzz
      elif i%5 == 0 and i%3 == 0:
          print FizzBuzz
      else:
          print i

  is there a better way than my solution? is mine ok?

 Is it correct? Did you get at it in less than 15 minutes? If so, then it's OK.
 The original test was not write the most convoluted algorithm you can think 
 of, nor write the best program to solve this. It was a *practical* test: 
 if you can't get anything remotely working for such a simple problem in 15 
 minutes, we're not interested in your services.

 (We used this question last year - some people gave a sensible answer in less 
 than 5 minutes, but others did not even know how to start)

 --
 Gabriel Genellina- Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

As a test, I would leave out the last sentence, and see how many
people (and how fast) figure out than a number can be multiple of
three _and_ five and that the requirement is somehow incomplete ...

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


Re: module global variables

2008-05-12 Thread alex23
On May 12, 5:17 pm, pistacchio [EMAIL PROTECTED] wrote:
 hi to all!
 can i load a module passing to it, automatically and as default, all
 the caller's global variables to act as module's global variables?
 thanks

module = __import__('module', globals=globals())

I think that's what you're looking for.

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


Re: module global variables

2008-05-12 Thread pistacchio
On 12 Mag, 10:01, alex23 [EMAIL PROTECTED] wrote:
 On May 12, 5:17 pm, pistacchio [EMAIL PROTECTED] wrote:

  hi to all!
  can i load a module passing to it, automatically and as default, all
  the caller's global variables to act as module's global variables?
  thanks

 module = __import__('module', globals=globals())

 I think that's what you're looking for.

 - alex23


hmm, well, maybe yes.. should i ovveride the standard import function
of the module?
say that the module is called pycatrix, would adding this to the
module solve the problem?

def __import__('pycatrix', globals=globals()):

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


Re: module global variables

2008-05-12 Thread pistacchio
On 12 Mag, 10:10, pistacchio [EMAIL PROTECTED] wrote:
 On 12 Mag, 10:01, alex23 [EMAIL PROTECTED] wrote:

  On May 12, 5:17 pm, pistacchio [EMAIL PROTECTED] wrote:

   hi to all!
   can i load a module passing to it, automatically and as default, all
   the caller's global variables to act as module's global variables?
   thanks

  module = __import__('module', globals=globals())

  I think that's what you're looking for.

  - alex23

 hmm, well, maybe yes.. should i ovveride the standard import function
 of the module?
 say that the module is called pycatrix, would adding this to the
 module solve the problem?

 def __import__('pycatrix', globals=globals()):

pardon, this:
def __import__('pycatrix', globals=globals()):
pass
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Arnaud Delobelle
On May 11, 4:36 am, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2008-05-11, John Machin [EMAIL PROTECTED] wrote:



  Write a program that prints the numbers from 1 to 100. But for
  multiples of three print Fizz instead of the number and for the
  multiples of five print Buzz. For numbers which are multiples of
  both three and five print FizzBuzz.

  for i in range(1,101):
      if i%3 == 0 and i%5 != 0:
          print Fizz
      elif i%5 == 0 and i%3 != 0:
          print Buzz
      elif i%5 == 0 and i%3 == 0:
          print FizzBuzz
      else:
          print i

  is there a better way than my solution? is mine ok?

  Try doing it using %3 and %5 only once each.

 for i in xrange(101):
     print ((,Fizz)[i%3==0] + (,Buzz)[i%5==0]) or str(i)

 His is better though, since it's more obvious what's intended.

 Here's one that's less opaque

 for i in xrange(101):
     s = 
     if i%3 == 0: s += Fizz
     if i%5 == 0: s += Buzz
     if s:
         print s
     else:
         print i


Let's not forget to generalise the problem and code it OOP-style :)

class FizzBuzzer(object):
def __init__(self, *fizzles):
self.fizzles = fizzles
def translate(self, n):
return ''.join(val for (p, val) in self.fizzles if not n%p) or
n
def range(self, start, stop=None, step=None):
if stop is None:
start, stop = 0, start
if step is None:
step = 1
for n in xrange(start, stop, step):
yield self.translate(n)
def __getitem__(self, obj):
if isinstance(obj, slice):
return self.range(obj.start, obj.stop, obj.step)
else:
return self.translate(obj)

# FizzBuzzer in action:

 fizzbuzz = FizzBuzzer((3, 'Fizz'), (5, 'Buzz'))
 for val in fizzbuzz[1:21]:
... print val
...
1 21 1
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
 abc = FizzBuzzer((2, 'Ah'), (3, 'Bee'), (5, 'Cee'))
 list(abc[25:35])
25 35 1
['Cee', 'Ah', 'Bee', 'Ah', 29, 'AhBeeCee', 31, 'Ah', 'Bee', 'Ah']


--
Arnaud

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


Re: threading - race condition?

2008-05-12 Thread Rhamphoryncus
On May 11, 10:16 am, skunkwerk [EMAIL PROTECTED] wrote:
 On May 10, 1:31 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:



  On Fri, 9 May 2008 08:40:38 -0700 (PDT),skunkwerk[EMAIL PROTECTED]
  declaimed the following in comp.lang.python:

  Coming in late...

   On May 9, 12:12 am, John Nagle [EMAIL PROTECTED] wrote:
   skunkwerkwrote:
 i've declared a bunch of workerthreads(100) and a queue into which
 new requests are inserted, like so:

  snip

 queue = Queue.Queue(0)
  WORKERS=100
 for i in range(WORKERS):
thread = SDBThread(queue)
thread.setDaemon(True)
thread.start()

 the thread:

 class SimpleDBThread ( threading.Thread ):
def __init__ ( self, queue ):
self.__queue = queue

  Note: double-leading __ means name mangling -- typically only
  needed when doing multiple layers of inheritance where different parents
  have similar named items that need to be kept independent; a single _ is
  the convention for don't touch me unless you know what you are doing

threading.Thread.__init__ ( self )
def run ( self ):
while 1:
item = self.__queue.get()
if item!=None:
model = domain.get_item(item[0])
logger.debug('sdbthread item:'+item[0])
title = model['title']
scraped = model['scraped']
logger.debug(sdbthread title:+title)

 any suggestions?
 thanks

  snip

   thanks John, Gabriel,
 here's the 'put' side of the requests:

   def prepSDBSearch(results):
  modelList = [0]
  counter=1
  for result in results:
  data = [result.item, counter, modelList]
  queue.put(data)
  counter+=1
  while modelList[0]  len(results):
  print 'waiting...'#wait for them to come home
  modelList.pop(0)#now remove '0'
  return modelList

  My suggestion, if you really want diagnostic help -- follow the
  common recommendation of posting the minimal /runable (if erroneous)/
  code... If domain.get_item() is some sort of RDBM access, you might
  fake it using a pre-loaded dictionary -- anything that allows it to
  return something when given the key value.

   responses to your follow ups:
   1)  'item' in thethreadsis a list that corresponds to the 'data'
   list in the above function.  it's not global, and the initial values
   seem ok, but i'm not sure if every time i pass in data to the queue it
   passes in the same memory address or declares a new 'data' list (which
   I guess is what I want)

  Rather confusing usage... In your put you have a list whose first
  element is result.item, but then in the work thread, you refer to the
  entire list as item

   3)  the first item in the modelList is a counter that keeps track of
   the number ofthreadsfor this call that have completed - is there any
   better way of doing this?

  Where? None of your posted code shows either counter or modelList
  being used by thethreads.

  And yes, if you havethreadstrying to update a shared mutable, you
  have a race condition.

  You also have a problem if you are using counter to define where
  in modelList a thread is supposed to store its results -- as you can not
  access an element that doesn't already exist...

  a = [0]
  a[3] = 1#failure, need to create elements 1, 2, 3 first

  Now, if position is irrelevant, and a thread just appends its
  results to modelList, then you don't need some counter, all you need is
  to check the length of modelList against the count expected.

  Overall -- even though you are passing things via the queue, the
  contents being pass via the queue are being treated as if they were
  global entities (you could make modelList a global, remove it from the
  queue entries, and have the same net access)...

  IOWs, you have too much coupling between thethreadsand the feed
  routine...

  As for me... I'd be using a second queue for return values...

  WORKERTHREADS = 100
  feed = Queue.Queue()
  result = Queue.Queue()

  def worker():
  while True:
  (ID, item) = feed.get() #I leave the queues 
  globals
  
  #since they perform locking
  
  #internally
  model = domain.get_item(item)
  results.put( (ID, model[title], model[scraped]) )

  for i in range(WORKERTHREADS):
  aThread = threading.Thread(target=worker)
  #overkill to subclass as there is now no specialized init
  #and if I really wanted to make the queues non-global
 

Re: module global variables

2008-05-12 Thread Marco Mariani

pistacchio wrote:

On 12 Mag, 10:01, alex23 [EMAIL PROTECTED] wrote:

On May 12, 5:17 pm, pistacchio [EMAIL PROTECTED] wrote:


hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?


Are you positively sure you need this?

Modifying imported modules is already quite fragile, but this.. it's 
basically a reversed(import *)


It's quite messy. Where quite equals to very
--
http://mail.python.org/mailman/listinfo/python-list


Import/Create module from buffer

2008-05-12 Thread Gruik
Hi people,

I'm currently working on python embedding with C++. My goal is that
the C++ part handle files writing/reading so that the Python part only
works with buffers.

I succeeded in buffer exchanges. The problem is that some of the files
I read/write are python files so that, before embedding, I imported
them as modules when I needed them.

But now that the Python part only receive buffers, I can't do it
anymore. So I wonder :
- is it possible to import module from a buffer instead of files?
- or is it possible to create a module object from my buffer?

I looked on the Internet but didn't find anything about that. Does
anyone have an idea?

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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Arnaud Delobelle
On May 12, 9:30 am, Arnaud Delobelle [EMAIL PROTECTED] wrote:
[...]
 # FizzBuzzer in action:

  fizzbuzz = FizzBuzzer((3, 'Fizz'), (5, 'Buzz'))
  for val in fizzbuzz[1:21]:

 ...     print val
 ...
 1 21 1

Ignore this, it's debugging output

 1
 2
 Fizz
 4
 Buzz
 Fizz
 7
 8
 Fizz
 Buzz
 11
 Fizz
 13
 14
 FizzBuzz
 16
 17
 Fizz
 19
 Buzz abc = FizzBuzzer((2, 'Ah'), (3, 'Bee'), (5, 'Cee'))
  list(abc[25:35])

 25 35 1
^
Same

 ['Cee', 'Ah', 'Bee', 'Ah', 29, 'AhBeeCee', 31, 'Ah', 'Bee', 'Ah']

--
Arnaud

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


Re: anonymous assignment

2008-05-12 Thread Arnaud Delobelle
On May 12, 7:31 am, Arnaud Delobelle [EMAIL PROTECTED] wrote:
 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

here is a very sophisticated implementation :)

 def extract(indices, seq):
... return tuple(seq[i] for i in indices)
...
 y, d = extract((0, 2), time.localtime())
 y, d
(2008, 12)

--
Arnaud

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


Re: module global variables

2008-05-12 Thread pistacchio
On 12 Mag, 10:47, Marco Mariani [EMAIL PROTECTED] wrote:
 pistacchio wrote:
  On 12 Mag, 10:01, alex23 [EMAIL PROTECTED] wrote:
  On May 12, 5:17 pm, pistacchio [EMAIL PROTECTED] wrote:

  hi to all!
  can i load a module passing to it, automatically and as default, all
  the caller's global variables to act as module's global variables?

 Are you positively sure you need this?

 Modifying imported modules is already quite fragile, but this.. it's
 basically a reversed(import *)

 It's quite messy. Where quite equals to very

well, i'm writing a module called pycatrix. within the module i have
compile / exec statements in a functions that work on global
variables. ( exec compiledTemplate in globals() ).

now, i don't want to be forced (or force the end user) to import to
call the module's function with a compulsory globals() as argument.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with custom events in wxpython

2008-05-12 Thread Frank Niessink
Hi Jimmy,

2008/5/12 Jimmy [EMAIL PROTECTED]:
 On May 11, 11:27 pm, Frank Niessink [EMAIL PROTECTED] wrote:
   2008/5/11 Jimmy [EMAIL PROTECTED]:
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.
  
  You may want to look at the pubsub module.

  it works! however, it seems the message can not be exchanged between
  processes :(
  actually what I want to do is let a running process send data to GUI
  process and display it

Well, that is some crucial information you didn't mention in your
original question... I guess for the communication between processes
you can use the regular python batteries available or something like
Pyro. In your GUI process you can use a thread to listen/wait for new
information to display and then send it to the main (GUI) thread. See
http://wiki.wxpython.org/LongRunningTasks

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


Re: Problem with help() in python/ipython interpreters

2008-05-12 Thread Gabriel Genellina
En Fri, 09 May 2008 20:45:09 -0300, Casey [EMAIL PROTECTED] escribió:

 I'm running python 2.5.2 on WinXP.  I've always used a GUI for
 interactive development, but I wanted to try out ipython which better
 supports matplotlib in this mode.  Unfortunately, whenever I try to
 use help() I get the following error:

 (Sys) The system cannot find the file specified.
  C:\documents

 It turns out that the regular (python.exe) interpreter has the same
 problem.  I have the HTML docs installed, my PYTHONDOCS environment
 variable points to the HTML directory, and I actually uninstalled and
 reinstalled every library I use from scratch to make sure it wasn't
 some random config issue.

I don't know exactly how does help() try to find the documentation, but I have 
these differences:

- I don't have a PYTHONDOCS variable (nor PYTHONPATH nor anything similar)
- The Windows registry contains this entry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.5\Help\Main Python 
Documentation]
@=C:\\Apps\\Python25\\Doc\\Python25.chm
- I *think* that I installed the HTML docs on that same directory a long time 
ago...

Hope this info could help you.

-- 
Gabriel Genellina

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


Re: Best technology for agent/web server architecture

2008-05-12 Thread Irmen de Jong

Gabriel Genellina wrote:

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.



While Pyro (http://pyro.sourceforge.net) uses pickle by default, it is well understood 
that you'll have to deal with a potential security issue if your server is open to 
untrusted/uncontrolled clients.

Pyro provides several things that could help you here:
- you can define a connection authenticator that checks client IP and/or 
passphrases
- you can switch to an XML based serialisation protocol (courtesy of gnosis 
tools)
- you can run Pyro over SSL and let SSL deal with authentication/encryption/...

Cheers
Irmen de Jong
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-12 Thread Michele Simionato
On May 12, 4:28 am, Yves Dorfsman [EMAIL PROTECTED] wrote:
there's got to be a better way than:

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

Uses Python 2.6! ;)

Python 2.6a3 (r26a3:62861, May 12 2008, 11:41:56)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type help, copyright, credits or license for more information.
 import time
 time.localtime()
time.struct_time(tm_year=2008, tm_mon=5, tm_mday=12, tm_hour=11,
tm_min=43, tm_sec=47, tm_wday=0, tm_yday=133, tm_isdst=1)
 t=time.localtime()
 t.tm_year, t.tm_mday
(2008, 12)


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


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

2008-05-12 Thread Gabriel Genellina
En Mon, 12 May 2008 03:52:59 -0300, Banibrata Dutta [EMAIL PROTECTED] 
escribió:

 Found that SnakeSQL does implement DB2.0 API. However are there such
 implementations for MySQL ?

MySQLdb

-- 
Gabriel Genellina

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


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

2008-05-12 Thread Ivan Illarionov
 On Mon, 12 May 2008 16:24:23 +1000, Ben Finney wrote: [...]
  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.
 
 Even if the counter is not used inside the loop's body it's still in
 control of the whole loop
 
 Not in Python it's not. The values that come out of the iterator aren't
 in control of the loop. The state for the loop is in the *iterator*,
 not the values that come out.
 
 Having access to the values that come from the iterator is usually
 useful, but regardless of whether one uses them or not, they're *not*
 controlling the loop, and it's confusing to imply that they are.

I agree that in control was incorrect phrase.
 
 So, when not using the values that come from the controlling iterator,
 it's good to make that explicit. If Python supported it, we might prefer
 to use no name at all for something that isn't used, but the 'for'
 syntax doesn't allow that.
 
 In the absence of supporting syntax, the next best thing is to choose a
 name that *does* make it explicit that the values will not be used.

Name 'i' does not imply whether it's used inside the loop or not.
IMO it perfectly covers both cases.

It may have small advantage to make it explicit that the values will not 
be used, but names like dummy, unused, ignored or junk can be 
confusing for some people and break the established conventions for 
counter variable names (and these conventions are reasonable and are 
taken from mathematics). i is still the best choice.

And let's agree to disagree. It's clear that we have different opinions 
and it looks that this discussion is not going to change them.

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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Chris
On May 11, 3:12 am, globalrev [EMAIL PROTECTED] wrote:
 http://reddit.com/r/programming/info/18td4/comments

 claims people take a lot of time to write a simple program like this:

 Write a program that prints the numbers from 1 to 100. But for
 multiples of three print Fizz instead of the number and for the
 multiples of five print Buzz. For numbers which are multiples of
 both three and five print FizzBuzz.

 for i in range(1,101):
     if i%3 == 0 and i%5 != 0:
         print Fizz
     elif i%5 == 0 and i%3 != 0:
         print Buzz
     elif i%5 == 0 and i%3 == 0:
         print FizzBuzz
     else:
         print i

 is there a better way than my solution? is mine ok?

personally if you're just checking if a modulus result is 0 or not I
would rather do as it looks neat imho.

for i in xrange(1,101):
if not i % 3 and i % 5:
print 'Fizz'
elif i % 3 and not i % 5:
print 'Buzz'
elif not i % 3 and not i % 5:
print 'FizzBuzz'
else:
print i
--
http://mail.python.org/mailman/listinfo/python-list


artificiall, agent, movement

2008-05-12 Thread Iman
hi
i'm working on some simulation project . i'm going to simulate traffic
of a city.
this simulation has cars , passengers , non-movable objects and
Traffic signals  .
i've made cars as intelligent agent . it has thinking method ,
changing states agents ...
the main problem is i have problem to move my agents in world .
it would be possible to add some method to agent which move  agent in
random  destination .
but i'm trying to find some patterns which is designed  for this
problems .
is there any sample source code in python or links, docs to help me ?
 thanks for your attention .
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-12 Thread Gabriel Genellina
En Mon, 12 May 2008 06:45:40 -0300, Michele Simionato [EMAIL PROTECTED] 
escribió:
 On May 12, 4:28 am, Yves Dorfsman [EMAIL PROTECTED] wrote:
 there's got to be a better way than:

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

 Uses Python 2.6! ;)

 Python 2.6a3 (r26a3:62861, May 12 2008, 11:41:56)
 [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
 Type help, copyright, credits or license for more information.
 import time
 time.localtime()
 time.struct_time(tm_year=2008, tm_mon=5, tm_mday=12, tm_hour=11,
 tm_min=43, tm_sec=47, tm_wday=0, tm_yday=133, tm_isdst=1)
 t=time.localtime()
 t.tm_year, t.tm_mday
 (2008, 12)

No need of 2.6 - the above code works since Python 2.2 at least:

Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
 import time
 t=time.localtime()
 type(t)
type 'time.struct_time'
 t.tm_year
2008

(but struct_time objects were printed as regular tuples)

-- 
Gabriel Genellina

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


Re: Import/Create module from buffer

2008-05-12 Thread Gabriel Genellina
En Mon, 12 May 2008 05:49:22 -0300, Gruik [EMAIL PROTECTED] escribió:

 I'm currently working on python embedding with C++. My goal is that
 the C++ part handle files writing/reading so that the Python part only
 works with buffers.

 I succeeded in buffer exchanges. The problem is that some of the files
 I read/write are python files so that, before embedding, I imported
 them as modules when I needed them.

 But now that the Python part only receive buffers, I can't do it
 anymore. So I wonder :
 - is it possible to import module from a buffer instead of files?
 - or is it possible to create a module object from my buffer?

Yes, first compile the buffer to get a code object, then use 
PyImport_ExecCodeModule. See how this function is used in import.c

-- 
Gabriel Genellina

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


Re: python without while and other explosive statements

2008-05-12 Thread ivo talvet
thanks for the tips, pam limits and http://codepad.org/ are both
interesting tracks.

Ivo

2008/5/12 Matt Nordhoff [EMAIL PROTECTED]:

 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

  http://codepad.org/ 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 http://codepad.org/about.

  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: Import/Create module from buffer

2008-05-12 Thread Gruik
On May 12, 12:31 pm, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Mon, 12 May 2008 05:49:22 -0300, Gruik [EMAIL PROTECTED] escribió:

  I'm currently working on python embedding with C++. My goal is that
  the C++ part handle files writing/reading so that the Python part only
  works with buffers.

  I succeeded in buffer exchanges. The problem is that some of the files
  I read/write are python files so that, before embedding, I imported
  them as modules when I needed them.

  But now that the Python part only receive buffers, I can't do it
  anymore. So I wonder :
  - is it possible to import module from a buffer instead of files?
  - or is it possible to create a module object from my buffer?

 Yes, first compile the buffer to get a code object, then use 
 PyImport_ExecCodeModule. See how this function is used in import.c

 --
 Gabriel Genellina

Thanks for your quick answer !
I think I'll have no problem with that in C++ and I'm going to try it
right after this message.

But before that 1 question: what if I'm in Python ?
Following your solution, I did that in Python :

def load_buffer(buffer) :
compiled_buffer = compile(buffer, module_name, exec)
exec(compiled_buffer)

It works great except that I can't have a module object and that it is
as if I did from module import *
But I need the module object and not an import * behavior.
Any idea about the way to do that?

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


Re: Import/Create module from buffer

2008-05-12 Thread Irmen de Jong

Gruik wrote:


But before that 1 question: what if I'm in Python ?
Following your solution, I did that in Python :

def load_buffer(buffer) :
compiled_buffer = compile(buffer, module_name, exec)
exec(compiled_buffer)

It works great except that I can't have a module object and that it is
as if I did from module import *
But I need the module object and not an import * behavior.
Any idea about the way to do that?


Something along the lines of:

import new
mymodule = new.module(mymodule)
exec code in mymodule.__dict__



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


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Duncan Booth
Ivan Illarionov [EMAIL PROTECTED] wrote:

 is there a better way than my solution? is mine ok?
 
 ['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
  or str(i) for i in xrange(1, 101)]
 
 -- Ivan
 
 or, more correctly, if you actually need to print:
 
 sys.stdout.write('\n'.join('%s%s' % 
 (not i%3 and 'Fizz' or '', not i%5 aBuzz' or '') 
 or str(i) 
 for i in xrange(1, 101)))

I think the variant I came up with is a bit clearer:

for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread John Machin

Duncan Booth wrote:

Ivan Illarionov [EMAIL PROTECTED] wrote:


is there a better way than my solution? is mine ok?

['%s%s' % (not i%3 and 'Fizz' or '', not i%5 and 'Buzz' or '')
 or str(i) for i in xrange(1, 101)]

-- Ivan

or, more correctly, if you actually need to print:

sys.stdout.write('\n'.join('%s%s' % 
(not i%3 and 'Fizz' or '', not i%5 aBuzz' or '') 
or str(i) 
for i in xrange(1, 101)))


I think the variant I came up with is a bit clearer:

for i in range(1,101):
print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i


More than a bit clearer, IMO. How about
print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
(or perhaps
print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
to save looking up the precedence rules) ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-12 Thread Michael Torrie
Michael Torrie wrote:
 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

I used linux's strace command to trace the file calls of file.exe via
wine (fun!) and verified that magic1.dll indeed will first in
c:/progra~1/File/share/file/magic and then in ../share/file
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-12 Thread Michael Torrie
Larry Hale wrote:
 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...  :)

Glad it's working for you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Arnaud Delobelle
On May 12, 1:30 pm, John Machin [EMAIL PROTECTED] wrote:
 Duncan Booth wrote:
[...]
  I think the variant I came up with is a bit clearer:

  for i in range(1,101):
     print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i

 More than a bit clearer, IMO. How about
      print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
 (or perhaps
      print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
 to save looking up the precedence rules) ?

Stuff clarity!  How about

for i in xrange(1, 101):
print 'FizzBuzz'[4*(i%30):4+4*(i%51)] or i

--
Arnaud

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


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

2008-05-12 Thread Robert.Spilleboudt

I am using Snack to process the audio signal of a rc transmitter.
Look at
http://www.speech.kth.se/snack/
Another audio processing: PortAudio and the Python module PyAudio. Look 
at http://people.csail.mit.edu/hubert/pyaudio/

Robert

Julien 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

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


Re: anonymous assignment

2008-05-12 Thread Richard G Riley
Yves Dorfsman [EMAIL PROTECTED] writes:

 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

or .localtime()? or is this local() specific to a different python
version?

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


Re: Import/Create module from buffer

2008-05-12 Thread Gruik
On May 12, 1:48 pm, Irmen de Jong [EMAIL PROTECTED] wrote:
 Gruik wrote:
  But before that 1 question: what if I'm in Python ?
  Following your solution, I did that in Python :

      def load_buffer(buffer) :
          compiled_buffer = compile(buffer, module_name, exec)
          exec(compiled_buffer)

  It works great except that I can't have a module object and that it is
  as if I did from module import *
  But I need the module object and not an import * behavior.
  Any idea about the way to do that?

 Something along the lines of:

 import new
 mymodule = new.module(mymodule)
 exec code in mymodule.__dict__

 --irmen

Yeah it works !

exec(compiled_module, globals(), mymodule.__dict__)

Just to add mymodule to sys.modules and it's good!

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


Re: Initializing a subclass with a super object?

2008-05-12 Thread frankdmartinez
On May 11, 3:19 am, Francesco Bochicchio [EMAIL PROTECTED] wrote:
 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)

Hi, Francesco.
Thanx!  That's actually exactly what I needed (though I didn't
know it).
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Max Erickson
Arnaud Delobelle [EMAIL PROTECTED] wrote:

 On May 12, 1:30 pm, John Machin [EMAIL PROTECTED] wrote:
 Duncan Booth wrote:
 [...]
  I think the variant I came up with is a bit clearer:

  for i in range(1,101):
     print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else
  'Buzz') or 
  i

 More than a bit clearer, IMO. How about
      print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or
 i (or perhaps
      print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz'))
 or i to save looking up the precedence rules) ?
 
 Stuff clarity!  How about
 
 for i in xrange(1, 101):
 print 'FizzBuzz'[4*(i%30):4+4*(i%51)] or i
 
 --
 Arnaud
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 

With no loop:

i=1
execprint'FizzBuzz'[4*(i%30):4+4*(i%51)]or i;i+=1;*100


max

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

Re: Now what!?

2008-05-12 Thread Marco Mariani

notbob wrote:


frustrated and give up on learning programming, not really caring much for
coding, anyway.  But, dammit, I'm gonna stick with it this time.  I'll learn
python if it kills me!


No, it won't kill you but make you stronger ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: artificiall, agent, movement

2008-05-12 Thread Gerry
Many city travel surveys collect source destination trip-start data;
you might be able to find one of these studies.

I think each car in your simulation should have a destination.  Then
the simulation needs a route-finder, and cars can progress along their
routes as traffic permits -- or even change routes if traffic seems
too slow.

I think if you start with a very small city -- perhaps just a 5 by 5
grid, and generate sources and destinations at intersections randomly
along the perimeter, you'll have enough to prototype all of the
building blocks.

Gerry


On May 12, 6:37 am, Iman [EMAIL PROTECTED] wrote:
 hi
 i'm working on some simulation project . i'm going to simulate traffic
 of a city.
 this simulation has cars , passengers , non-movable objects and
 Traffic signals  .
 i've made cars as intelligent agent . it has thinking method ,
 changing states agents ...
 the main problem is i have problem to move my agents in world .
 it would be possible to add some method to agent which move  agent in
 random  destination .
 but i'm trying to find some patterns which is designed  for this
 problems .
 is there any sample source code in python or links, docs to help me ?
  thanks for your attention .

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


execfile python3k

2008-05-12 Thread Odys
Hi there,

Since execfile() is removed in Python 3.0
I have question about using exec.

I know about
  exec(open('filename').read())
but from documentation the 1st arg of exec can be 'file object'.
However
   exec(open('filename'))
does not work.
Does anybody have idea how to construct 'file object' then?

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


Re: artificiall, agent, movement

2008-05-12 Thread Paul McGuire
On May 12, 5:37 am, Iman [EMAIL PROTECTED] wrote:
 is there any sample source code in python or links, docs to help me ?
  thanks for your attention .

I've used SimPy in the past to implement a factory simulation.  The
SimPy web site claims that it has been used for traffic simulation,
but does not give any links.

http://simpy.sourceforge.net/index.html

I found it to be a very neat discrete event simulator, making good use
of Python language features (especially generators).

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Mark Dickinson
On May 12, 2:09 am, Terry Reedy [EMAIL PROTECTED] wrote:
 Then it seems equally dubious that 0.**y, y0, 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.

Well, there's a difference:  the limit of exp(y*log(x)) as (x, y) -
(0, a) exists for all finite nonzero a.  The limit as (x, y) -
(0, 0) doesn't.

 2.5 raises an exception.  In 3.0, (-2)**1.

 (3.999722741113-1.2566370355167477e-07j)

Interesting---I hadn't realised that 3.0 had changed this.
I can't quite decide whether I like this behaviour much.  It
seems to be the only case where a computation involving only
floats can produce a complex number.


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

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

Yeah---I know. :-).  The current decimal __pow__ code is mostly
my fault, at least in 2.5.2/2.6/3.0 onwards.  For what it's
worth, the author of the Decimal standard has indicated that
the behaviour of 0**0 might change after IEEE 754r finally
sees the light of day.

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


Compiling Python using Microsoft Visual C++ 2008

2008-05-12 Thread Colin J. Williams


1.I have both 2.5 and 2.6 but both 
appear, under Recent Projects, as 
pcbuild.  It would be helpful if the 
Python Version could be indicated.
2.With 2.6, Python compiles and executes 
OK but various packages are not 
compiled, eg sqlite3.

3.Pythonw compiles OK but not sqlite3.
4.Mike Fletcher suggests an approach 
(http://www.vrplumber.com/programming/mstoolkit/) 
with Visual C for Python 2.4.  Is this 
still the recommended way to compile 
Python 2.6?
5.Python 2.5 source refers to an Older 
Visual C.  Automatic conversion to 
Visual C 2008 gives the message “Some of 
the properties associated with the 
solution could not be read.”  All 
projects except one had a single 
warning, there were no errors reported.
6.After conversion there is no python 
project, it is flagged “unavailable”.
7.Pythoncore builds with no errors and 6 
warnings but there is no executable.
8.Python 2.5 build _tkinter fails – 
tcl.h not found.


I would welcom advice on how to proceed.

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


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

2008-05-12 Thread Grant Edwards
On 2008-05-12, Ben Finney [EMAIL PROTECTED] wrote:

 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.

The value may be unused, but for me it's the name that matters,
not the value.   The name might be in use by other code, and
the careless choice of a dummy name that's _supposed_ to be
unused has broken code precisely becuase the name was being
used (for something else).  Requiring that the user pollute a
namespace with a useless name is a wart.

 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.

Perhaps I'm the only one who's ever been stupid enough to
overwrite an index named i (that is being used) with another
index named i (that isn't being used)...


-- 
Grant Edwards   grante Yow! All of life is a blur
  at   of Republicans and meat!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: frameword vs application server?

2008-05-12 Thread Diez B. Roggisch

walterbyrd schrieb:

Can somebody help me understand the difference? Not just where Python
is concerned, but in general?

As I understand it, an application server is supposed to be a great
help in developing apps, because most of the business logic is already
there. It seems to me that, usually when applications servers are
discussed, people are talking about Java.


First of all, this is a misconception. An app-server may provide a wide 
range of infrastructure, however this has nothing to do with business 
logic. THat can merely pick parts of that infrastructure to build upon. 
But the distinction to a powerful framework is slim enough.


And it should be (and has been often so) said that especially in the 
java-world, app-servers and the specifications the implement (j2ee) are 
over-engineered and complicated.



I suppose most popular Python frameworks incorporate an application
server, but I get the idea that those app servers are not nearly as
sophisticed as something like JBoss.


The sophistication is a matter of perspective - some of it stems from 
the fact that in java, you need a lot more code to make even pretty 
simple things work. Think of delegation to business objects (session 
beans) that get their respective calls wrapped so that they take place 
inside a transactional context.


Which involves a great deal of design-abstractions, code-generators and 
tons of XML to glue these together.


Or three lines of code in python...



I am not sure if a Python app server, that works like a Java app
server would make sense.


As mentioned above - in some aspects, that is not really needed. But if 
you want more of an app-server, have a look at ZOPE, Kamaelia and maybe 
even twisted.


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


Re: Compiling Python using Microsoft Visual C++ 2008

2008-05-12 Thread Martin v. Löwis
 1.I have both 2.5 and 2.6 but both appear, under Recent Projects, as
 pcbuild.  It would be helpful if the Python Version could be indicated.

Hover over the link, and it will display the full path, which you can
then infer to reason about the specific copy of Python you are using.

In any case, compiling Python 2.5 with VS 2008 is not supported.

 2.With 2.6, Python compiles and executes OK but various packages are not
 compiled, eg sqlite3.

See PCbuild/readme.txt.

 3.Pythonw compiles OK but not sqlite3.

So what's the error?

 4.Mike Fletcher suggests an approach
 (http://www.vrplumber.com/programming/mstoolkit/) with Visual C for
 Python 2.4.  Is this still the recommended way to compile Python 2.6?

No. Either use the full product, or the express edition. Neither
requires and additional setup.

 5.Python 2.5 source refers to an Older Visual C.  Automatic conversion
 to Visual C 2008 gives the message “Some of the properties associated
 with the solution could not be read.”  All projects except one had a
 single warning, there were no errors reported.
 6.After conversion there is no python project, it is flagged “unavailable”.

See above. This procedure is not supported; you are on your own.
Get a copy of VS 2003 if you want to follow the official
recommendations.

 7.Pythoncore builds with no errors and 6 warnings but there is no
 executable.
 8.Python 2.5 build _tkinter fails – tcl.h not found.

See PCbuild/readme.txt.

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


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

2008-05-12 Thread Peter Decker
On Mon, May 12, 2008 at 1:45 AM, Banibrata Dutta
[EMAIL PROTECTED] wrote:

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 ?

You might want to take a look at Dabo (http://dabodev.com). They have
a backend-agnostic interface for working with different databases. I
don't do database apps myself, so I can't comment on how well it
works, but based on the comments of others on the Dabo email lists, it
seems as though it works well enough.

-- 

# p.d.
--
http://mail.python.org/mailman/listinfo/python-list


Removing option from optparse

2008-05-12 Thread GustavoTabares
Hello,

I'm trying to figure out if the following is a bug or if I'm using the
remove_option in the wrong way.

#!/usr/bin/env python
import optparse
parser = optparse.OptionParser()
parser.add_option(--test, help=This is a test option)
parser.remove_option('--test')
print parser.parse_args()

this will output:
(Values at 0x6beb8: {'test': None}, [])

If you execute the --help on the file above you will not see --test as
expected. I'm curious as to why parse_args is still returning this as
an option.

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


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

2008-05-12 Thread Grant Edwards
On 2008-05-12, Ben Finney [EMAIL PROTECTED] wrote:

I too, agree that requiring a name be bound to the values
coming out of the iterator seems wrong.

 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.

An iterator like xrange() is an excellent choice. But, since
the iterator contains that information, why require that that
value be exported by the iterator and bound to an externally
visible name?  In the case in question, the only thing you need
from the iterator is the StopIteration exception.  To me,
exposing the internal state of the iterator and requiring that
the user bind a name to it each time through the loop feels
we're like driving a nail with a screwdriver.

-- 
Grant Edwards   grante Yow! Was my SOY LOAF left
  at   out in th'RAIN?  It tastes
   visi.comREAL GOOD!!
--
http://mail.python.org/mailman/listinfo/python-list


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

2008-05-12 Thread Grant Edwards
On 2008-05-12, Ben Finney [EMAIL PROTECTED] wrote:
 Paddy [EMAIL PROTECTED] writes:

 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.

 The problem with all of these names is that they also have long
 precedent as names of values that *will* be used inside the loop.

I guess people who standardize on loop_count never nest loops. :)

 Because of the precedent of those names, choosing one of those
 names doesn't make it clear to the reader that the value is
 never used; they have no indication from you of that until
 they look over the code a few times. It's implicit rather than
 explicit.

And when somebody adds a nested loop things fall apart.

-- 
Grant Edwards   grante Yow! BARBARA STANWYCK makes
  at   me nervous!!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing option from optparse

2008-05-12 Thread Diez B. Roggisch

[EMAIL PROTECTED] schrieb:

Hello,

I'm trying to figure out if the following is a bug or if I'm using the
remove_option in the wrong way.

#!/usr/bin/env python
import optparse
parser = optparse.OptionParser()
parser.add_option(--test, help=This is a test option)
parser.remove_option('--test')
print parser.parse_args()

this will output:
(Values at 0x6beb8: {'test': None}, [])

If you execute the --help on the file above you will not see --test as
expected. I'm curious as to why parse_args is still returning this as
an option.


I'm guessing here - but it is *one* thing to disable an option for the 
user because of whatever condition, and another to remove the options 
default value that code could possibly rely on to work. So I'd say the 
behavior is sane.


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


Discount, Chanel Prada Coach Women's Sandals, LV DG Fendi Versace Sunglasses

2008-05-12 Thread www.globwholesale.com
Discount Coach Sandals, Dior Sandals, Prada  Sandals, Chanel Sandals,
Versace Sandals, Crocs Sandals, LV Sandals, ( G U C C I ) Sandals,
Women's Sandals Men's Slippers From
China

Brand Sunglasses Wholesale:

 Discount, Prada Sunglasses
 Discount, DG Sunglasses
 Discount, Fendi Sunglasses
 Discount, Burberry Sunglasses
 Discount, Chanel Sunglasses
 Discount, LV Sunglasses
 Discount, Dior Sunglasses
 Discount, (G U C C I ) Sunglasses
 Discount, Armani Sunglasses
 Discount, Versace Sunglasses
 Discount, AF Sunglasses
 Discount, LV Sunglasses

Wholesale, Prada Sunglasses
Wholesale,  DG Sunglasses
Wholesale,  Fendi Sunglasses
Wholesale,  Burberry Sunglasses
Wholesale,  Chanel Sunglasses
Wholesale,  LV Sunglasses
Wholesale,  Dior Sunglasses
Wholesale,  ( G U C C I ) Sunglasses
Wholesale,  Armani Sunglasses
Wholesale,  Versace Sunglasses
Wholesale,  AF Sunglasses
Wholesale,  LV Sunglasses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python using Microsoft Visual C++ 2008

2008-05-12 Thread Colin J. Williams

Martin v. Löwis wrote:

1.I have both 2.5 and 2.6 but both appear, under Recent Projects, as
pcbuild.  It would be helpful if the Python Version could be indicated.


Hover over the link, and it will display the full path, which you can
then infer to reason about the specific copy of Python you are using.


Lovely, thanks.  It's at the bottom of 
the screen.




In any case, compiling Python 2.5 with VS 2008 is not supported.


2.With 2.6, Python compiles and executes OK but various packages are not
compiled, eg sqlite3.


See PCbuild/readme.txt.


I presume that this is PCbuild8.txt




3.Pythonw compiles OK but not sqlite3.


So what's the error?


4.Mike Fletcher suggests an approach
(http://www.vrplumber.com/programming/mstoolkit/) with Visual C for
Python 2.4.  Is this still the recommended way to compile Python 2.6?


No. Either use the full product, or the express edition. Neither
requires and additional setup.


5.Python 2.5 source refers to an Older Visual C.  Automatic conversion
to Visual C 2008 gives the message “Some of the properties associated
with the solution could not be read.”  All projects except one had a
single warning, there were no errors reported.
6.After conversion there is no python project, it is flagged “unavailable”.


See above. This procedure is not supported; you are on your own.
Get a copy of VS 2003 if you want to follow the official
recommendations.


7.Pythoncore builds with no errors and 6 warnings but there is no
executable.
8.Python 2.5 build _tkinter fails – tcl.h not found.


See PCbuild/readme.txt.

Regards,
Martin


Thanks.  I'll look at the readme more 
carefully and seek VS 2003.


Now, I would like to remove Python 2.5 
from VS 2008 but see no obvious way of 
getting rid of it.


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


buffering choking sys.stdin.readlines() ?

2008-05-12 Thread cshirky
Newbie question:

I'm trying to turn a large XML file (~7G compressed) into a YAML file,
and my program seems to be buffering the input.

IOtest.py is just

  import sys
  for line in sys.stdin.readlines():
print line

but when I run

$ gzcat bigXMLfile.gz | IOtest.py

but it hangs then dies.

The goal of the program is to build a YAML file with print statements,
rather than building a gigantic nested dictionary, but I am obviously
doing something wrong in passing input through without buffering. Any
advice gratefully fielded.

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


Re: Write a python blog/website?

2008-05-12 Thread Dotan Cohen
2008/5/9 Sumon Sadhu [EMAIL PROTECTED]:
 Hey Dotan,

 My apologies if this post caused offense. Your assertion is right, maybe i
 should have emailed everyone individually like i've done with the first 45
 sites, but it was never my intention to spam.

Sumon, I think that you do not understand the perception of spam in
technological circles. Today, there is no way to initiate contact with
a business offer via email. None. All email solicitations are
unwelcome. I tell you this to help you. I do not know if you receive
5000 spam messages a week like I receive, but know that a sizeable
portion of the Python list gets considerably more. These people hate
spam.

 We're programmers like yourself, trying to build something that provides a
 lot of benefit. You can see our intentions are genuine (and our python ad
 server was fun to build)

Actually, I am not a programmer by trade. I learn python for fun while
I study mechanical engineering. I read the python list for the wisdom
that passes, and rarely post.

 So while i appreciate your response, it was never my attention to be
 spammy

I recognized that from the beginning, and stated that in my original
post. Which should have been kept private between us, now I realize.

Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--
http://mail.python.org/mailman/listinfo/python-list

RE: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Delaney, Timothy (Tim)
Mensanator wrote:

 Ok, I agree with 101, but I wouldn't necessarily
 say the others were unfortunate. You might be
 surprised at how often such fixations discover
 bugs, something that I have a gift for.

The discovering, the making, or both? ;)

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Arnaud Delobelle
On 12 May, 15:21, Mark Dickinson [EMAIL PROTECTED] wrote:
 On May 12, 2:09 am, Terry Reedy [EMAIL PROTECTED] wrote:

  Then it seems equally dubious that 0.**y, y0, 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.

 Well, there's a difference:  the limit of exp(y*log(x)) as (x, y) -
 (0, a) exists for all finite nonzero a.  The limit as (x, y) -
 (0, 0) doesn't.

But exp(y*log(x)) - 1 as (x, y) - (0, 0) along any analytic curve
which is not the x=0 axis (I think at least - it seems easy to prove
that given f and g analytic over R, f(x)*ln g(x) - 0 as x - 0 if
f(0)=g(0)=0 and g(x)0 in the neighbourhood of 0).  This should cover
most practical uses?

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


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

2008-05-12 Thread Paddy
On May 12, 3:46 pm, Grant Edwards [EMAIL PROTECTED] wrote:
 On 2008-05-12, Ben Finney [EMAIL PROTECTED] wrote:

  Paddy [EMAIL PROTECTED] writes:

  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.

  The problem with all of these names is that they also have long
  precedent as names of values that *will* be used inside the loop.

 I guess people who standardize on loop_count never nest loops. :)

  Because of the precedent of those names, choosing one of those
  names doesn't make it clear to the reader that the value is
  never used; they have no indication from you of that until
  they look over the code a few times. It's implicit rather than
  explicit.

 And when somebody adds a nested loop things fall apart.
I don't have an example to hand. A lot of casses of repeat_X_times
inside a loop of repeat_Y_times would naturally be written as
repeat_Y*X_times.
Oh, wait a bit,
oversimplified_example_alert
for i in range(3):
  print Stay!
  for j in range(2):
print Come over.
/oversimplified_example_alert

Which could become:

for outer_stay_repetions in range(3):
  print Stay!
  for inner_come_over_repetions in range(2):
print Come over.

But the second is daft. Nested repeats don't neccessarily pose a
problem to choosing meaningful names for repeat counters that are not
going to be referenced in the loop body, and most times i,j,k are fine
for used and un-used loop indices I find.

- Paddy
(Or were you just having a laugh ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: buffering choking sys.stdin.readlines() ?

2008-05-12 Thread Jean-Paul Calderone

On Mon, 12 May 2008 08:05:39 -0700 (PDT), cshirky [EMAIL PROTECTED] wrote:

Newbie question:

I'm trying to turn a large XML file (~7G compressed) into a YAML file,
and my program seems to be buffering the input.

IOtest.py is just

 import sys
 for line in sys.stdin.readlines():
   print line

but when I run

$ gzcat bigXMLfile.gz | IOtest.py

but it hangs then dies.


file.readlines reads the entire file into a list in memory.  You may not
want to do this.  You could try, instead, iterating over sys.stdin,
which should not try to load the entire file into memory.

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


Re: buffering choking sys.stdin.readlines() ?

2008-05-12 Thread Diez B. Roggisch

cshirky schrieb:

Newbie question:

I'm trying to turn a large XML file (~7G compressed) into a YAML file,
and my program seems to be buffering the input.

IOtest.py is just

  import sys
  for line in sys.stdin.readlines():
print line

but when I run

$ gzcat bigXMLfile.gz | IOtest.py

but it hangs then dies.

The goal of the program is to build a YAML file with print statements,
rather than building a gigantic nested dictionary, but I am obviously
doing something wrong in passing input through without buffering. Any
advice gratefully fielded.


readlines() reads all of the file into the memory. Try using xreadlines, 
the generator-version, instead. And I'm not 100% sure, but I *think* doing


for line in sys.stdin:
   ...

does exactly that.

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


Socket and cycle problem

2008-05-12 Thread petr . poupa
Hello,
I am beginner but so I need help. I have small script for receive data
from port 3883, but it print only once.

import socket

HOST = 'localhost'
PORT = 3883
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
data = s.recv(2048)
s.close()
print 'receive data from server:', `data`

So I try to write cycle to this script, like this:

import socket

HOST = 'localhost'
PORT = 3883
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while 1:
s.connect((HOST, PORT))
data = s.recv(2048)
s.close()
print 'receive data from server:', `data`

But Python reporting:

Traceback (most recent call last):
  File C:\Documents and Settings\poupa\Plocha\TCP3.py, line 7, in
module
s.connect((HOST, PORT))
  File string, line 1, in connect
  File C:\Python25\lib\socket.py, line 141, in _dummy
raise error(EBADF, 'Bad file descriptor')
error: (9, 'Bad file descriptor')

Where is the mistake? I dont know.

thaks for help
Petr
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you fail at FizzBuzz? simple prog test

2008-05-12 Thread Paul Hankin
On May 12, 1:59 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote:
 On May 12, 1:30 pm, John Machin [EMAIL PROTECTED] wrote:

  Duncan Booth wrote:
 [...]
   I think the variant I came up with is a bit clearer:

   for i in range(1,101):
  print '%s%s' % ('' if i%3 else 'Fizz', '' if i%5 else 'Buzz') or i

  More than a bit clearer, IMO. How about
   print ('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz') or i
  (or perhaps
   print (('' if i%3 else 'Fizz') + ('' if i%5 else 'Buzz')) or i
  to save looking up the precedence rules) ?

 Stuff clarity!  How about

 for i in xrange(1, 101):
 print 'FizzBuzz'[4*(i%30):4+4*(i%51)] or i

for i in xrange(1, 101):
print 'Fizz'*(i%31)+'Buzz'*(i%51) or i

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Lou Pecora
In article 
[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.

Well, it's really not that simple.  You've seen that 0**0 can lead to 
problems in various areas of mathematics (check the Wikipedia article on 
analysis/calculus application vs. combinatorics and discrete math).  You 
have to be aware of those dangers, what the language (Python here), and 
what your application requires.  Consistency in mathematics is vital.  
If you are using 0**0=1, then your code should be consistent with that 
usage.

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


Pydev 1.3.17 Released

2008-05-12 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.17 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Minor bug-fixes

Release Highlights in Pydev:
--

* Pydev Package Explorer: projects that had the project folder in the
pythonpath did not show children items correctly.
* Debugger: Disable all works. Patch from: Oldrich Jedlicka
* Debugger: Problem when making a step return / step over
* Code-completion: Working for attributes found in a superclass
imported with a relative import
  Patches from Felix Schwarz:
  o Allow to configure an interpreter even if the workspace path
name contains spaces
  o Completion server does not work when the eclipse directory
contains spaces
  o Fix deletion of resources in pydev package explorer for Eclipse 3.4



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-12 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Terry Reedy [EMAIL PROTECTED] wrote:

 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, y0, 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.

Huh?  That discontinuity is the problem.  Actually, the problem is 
that the function f(x,y)=x**y=exp(y*ln(x)) will be double valued at x=0 
and y=0.  It's value will depend on the direction in which the limit 
approaches (x,y)=(0,0).  You cannot have a function that has two values 
at one domain point without adding branch cuts (see complex functions 
like ln(z), z is complex).  That's not well defined -- in your sense.  
You are choosing a branch cut and you must make sure the rest of your 
math and code are consistent with that.  You should also tell any users 
of your code about that decision.

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


Re: Socket and cycle problem

2008-05-12 Thread Jean-Paul Calderone

On Mon, 12 May 2008 08:34:07 -0700 (PDT), [EMAIL PROTECTED] wrote:

Hello,
I am beginner but so I need help. I have small script for receive data
from port 3883, but it print only once.

import socket

HOST = 'localhost'
PORT = 3883
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
data = s.recv(2048)
s.close()
print 'receive data from server:', `data`

So I try to write cycle to this script, like this:

import socket

HOST = 'localhost'
PORT = 3883
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while 1:
   s.connect((HOST, PORT))
   data = s.recv(2048)
   s.close()
   print 'receive data from server:', `data`

But Python reporting:

Traceback (most recent call last):
 File C:\Documents and Settings\poupa\Plocha\TCP3.py, line 7, in
module
   s.connect((HOST, PORT))
 File string, line 1, in connect
 File C:\Python25\lib\socket.py, line 141, in _dummy
   raise error(EBADF, 'Bad file descriptor')
error: (9, 'Bad file descriptor')

Where is the mistake? I dont know.


You cannot reconnect a socket.  You need to create a new one for each
connection.  It's also almost certainly the case that the way you are
receiving data is incorrect.  There is no guarantee that you will get
2048 bytes from socket.recv(2048).  It isn't even guaranteed that all
the bytes written to the socket by the peer will be returned by such
a call.  Instead, you need a framing protocol to determine when all
data has been received.  For example, you might length prefix the
data, or you might insert a delimiter (or a terminator) at the end.  Or
if there is exactly one message to receive, then you should just read
until the recv call returns '', indicating EOF.

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


In metaclass, when to use __new__ vs. __init__?

2008-05-12 Thread Matthew Wilson
I have been experimenting with metaclasses lately.  It seems possible to
define a metaclass by either subclassing type and then either redefining
__init__ or __new__. 

Here's the signature for __init__:

def __init__(cls, name, bases, d):

and here's __new__:

def __new__(meta, classname, bases, d):

Every metaclass I have found monkeys with d, which is available in both
methods.  So when is it better to use one vs the other?

Thanks for the help.

Matt

--
Programming, life in Cleveland, growing vegetables, other stuff.
http://blog.tplus1.com
--
http://mail.python.org/mailman/listinfo/python-list


passing *args recursively

2008-05-12 Thread Guillermo

Hi,

This must be very basic, but how'd you pass the same *args several
levels deep?


def func2(*args)

print args # ((1, 2, 3),)
# i want this to output (1, 2, 3) as func1!
# there must be some better way than args[0]?

def func1(*args):

print args # (1, 2, 3)
func2(args)

func1(1,2,3)

Thanks!

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


Re: Socket and cycle problem

2008-05-12 Thread petr . poupa
On 12 Kvě, 17:54, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On Mon, 12 May 2008 08:34:07 -0700 (PDT), [EMAIL PROTECTED] wrote:
 Hello,
 I am beginner but so I need help. I have small script for receive data
 from port 3883, but it print only once.

 import socket

 HOST = 'localhost'
 PORT = 3883
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect((HOST, PORT))
 data = s.recv(2048)
 s.close()
 print 'receive data from server:', `data`

 So I try to write cycle to this script, like this:

 import socket

 HOST = 'localhost'
 PORT = 3883
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 while 1:
 s.connect((HOST, PORT))
 data = s.recv(2048)
 s.close()
 print 'receive data from server:', `data`

 But Python reporting:

 Traceback (most recent call last):
   File C:\Documents and Settings\poupa\Plocha\TCP3.py, line 7, in
 module
 s.connect((HOST, PORT))
   File string, line 1, in connect
   File C:\Python25\lib\socket.py, line 141, in _dummy
 raise error(EBADF, 'Bad file descriptor')
 error: (9, 'Bad file descriptor')

 Where is the mistake? I dont know.

 You cannot reconnect a socket.  You need to create a new one for each
 connection.  It's also almost certainly the case that the way you are
 receiving data is incorrect.  There is no guarantee that you will get
 2048 bytes from socket.recv(2048).  It isn't even guaranteed that all
 the bytes written to the socket by the peer will be returned by such
 a call.  Instead, you need a framing protocol to determine when all
 data has been received.  For example, you might length prefix the
 data, or you might insert a delimiter (or a terminator) at the end.  Or
 if there is exactly one message to receive, then you should just read
 until the recv call returns '', indicating EOF.

 Jean-Paul

ok thanks, but I am true greenhorn, so you think that the best way is
write new script?
Could you send me code if it isnt long, becase I have no idea and
unfortunately time as well.

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


Re: passing *args recursively

2008-05-12 Thread Jerry Hill
On Mon, May 12, 2008 at 12:19 PM, Guillermo
[EMAIL PROTECTED] wrote:
  def func1(*args):
 print args # (1, 2, 3)
 func2(args)

change this line to:
func2(*args)

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


Re: passing *args recursively

2008-05-12 Thread Matimus
On May 12, 9:19 am, Guillermo [EMAIL PROTECTED] wrote:
 Hi,

 This must be very basic, but how'd you pass the same *args several
 levels deep?

 def func2(*args)

 print args # ((1, 2, 3),)
 # i want this to output (1, 2, 3) as func1!
 # there must be some better way than args[0]?

 def func1(*args):

 print args # (1, 2, 3)
 func2(args)

 func1(1,2,3)

 Thanks!

 Guillermo

def func1(*args):
print args
func2(*args) # don't forget the '*'

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


Re: Compiling Python using Microsoft Visual C++ 2008

2008-05-12 Thread Christian Heimes
Colin J. Williams schrieb:
 See PCbuild/readme.txt.
 
 I presume that this is PCbuild8.txt

No, it's PCbuild/readme.txt in Python 2.6 and 3.0

By the way you can call Tools\buildbot\external.bat from the root
directory of the 2.6 and 3.0. It checks out and build the dependencies.
The script requires the VS 9.0 tools and the svn command line executables.

Christian

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Mark Dickinson
On May 12, 11:15 am, Arnaud Delobelle [EMAIL PROTECTED] wrote:

 But exp(y*log(x)) - 1 as (x, y) - (0, 0) along any analytic curve
 which is not the x=0 axis (I think at least - it seems easy to prove
 that given f and g analytic over R, f(x)*ln g(x) - 0 as x - 0 if
 f(0)=g(0)=0 and g(x)0 in the neighbourhood of 0).

Agreed.  And this makes an excellent argument that if you're going to
choose a number for 0.0**0.0 then it's got to be 1.  But I still don't
find it completely convincing as an argument that 0.0**0.0 should be
defined at all.

 This should cover most practical uses?

Maybe.  But if you're evaluating x**y in a situation where x and y
represent physical quantities, or otherwise have some degree of error,
then you probably want to be warned if x and y both turn out to be
zero.


I seem to be digging myself into a hole here.  I'm personally
firmly in the 0**0 should be 1 camp, and always have been---
there are just too many practical benefits to defining 0**0==1
to ignore, and in the case where you're interested in integer
exponents anything else is just plain wrong. The lack of
continuity of the power function at (0,0) seems a small
price to pay.

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


Re: Python doesn't recognize quote types

2008-05-12 Thread MRAB
On May 12, 8:31 am, Duncan Booth [EMAIL PROTECTED] wrote:
 Dennis Lee Bieber [EMAIL PROTECTED] wrote:

   The sloppy use of single quote for the apostrophe is unfortunate
 G

 True, but that problem is outside of the Python community's control. Given
 that people do often refer to single quote when they mean apostrophe the
 error message should be written so as to minimise confusion.

FYI, there are actually 2 types of quote character, single and double,
each with 2 forms, left and right. In Unicode the single-quote
characters are U+2018 (‘) and U+2019 (’) and the double-quote
characters are U+201C (“) and U+201D (”). The right-hand single-quote
is also the apostrophe.

In order to reduce the size of the character set needed, computer
manufacturers introduced 'sexless' quote characters, the single-quote/
aphostrophe U+0027 (') and double-quote U+0022 ().
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >