Learning Python: Code critique please

2008-06-21 Thread macoovacany
Hello all,
   I'm trying to learn various programming languages (I did MATLAB at
uni), and have decided to start with Python. The programming exercises
are derived from Larry O'brien's a href=http://www.knowing.net/
PermaLink,guid,f3b9ba36-848e-43f8-9caa-232ec216192d.aspx15
Programming Exercises /a. First one is up with a couple of comments
of my own.

Any suggestions, corrections, things that I have done wrong, could do
better, etc, please feel free to post a comment.

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


Re: An idiom for code generation with exec

2008-06-21 Thread eliben
d = {}
  execcode in globals(), d
   return d['foo']

 My way:

   return function(compile(code, 'string', 'exec'), globals())


With some help from the guys at IRC I came to realize your way doesn't
do the same. It creates a function that, when called, creates 'foo' on
globals(). This is not exactly what I need.

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


Re: An idiom for code generation with exec

2008-06-21 Thread eliben
On Jun 20, 2:44 pm, Peter Otten [EMAIL PROTECTED] wrote:
 eliben wrote:
  Additionally, I've found indentation to be a problem in such
  constructs. Is there a workable way to indent the code at the level of
  build_func, and not on column 0 ?

 execif 1: + code.rstrip()

 Peter

Why is the 'if' needed here ? I had .strip work for me:

def make_func():
code = 
def foo(packet):
return ord(packet[3]) + 256 * ord(packet[4])


d = {}
exec code.strip() in globals(), d
return d['foo']

Without .strip this doesn't work:

Traceback (most recent call last):
  File exec_code_generation.py, line 25, in module
foo = make_func()
  File exec_code_generation.py, line 20, in make_func
exec code in globals(), d
  File string, line 2
def foo(packet):
^
IndentationError: unexpected indent

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


Re: An idiom for code generation with exec

2008-06-21 Thread Peter Otten
eliben wrote:

 On Jun 20, 2:44 pm, Peter Otten [EMAIL PROTECTED] wrote:
 eliben wrote:
  Additionally, I've found indentation to be a problem in such
  constructs. Is there a workable way to indent the code at the level of
  build_func, and not on column 0 ?

 execif 1: + code.rstrip()

 Peter
 
 Why is the 'if' needed here ? I had .strip work for me:

A simple .strip() doesn't work if the code comprises multiple lines:

 def f():
... return 
... x = 42
... if x  0:
... print x
... 
...
 exec if 1:\n + f().rstrip()
42
 exec f().strip()
Traceback (most recent call last):
  File stdin, line 1, in module
  File string, line 2
if x  0:
^
IndentationError: unexpected indent

You can of course split the code into lines, calculate the indentation of
the first non-white line, remove that indentation from all lines and then
rejoin.

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


Re: An idiom for code generation with exec

2008-06-21 Thread eliben
On Jun 21, 8:52 am, Peter Otten [EMAIL PROTECTED] wrote:
 eliben wrote:
  On Jun 20, 2:44 pm, Peter Otten [EMAIL PROTECTED] wrote:
  eliben wrote:
   Additionally, I've found indentation to be a problem in such
   constructs. Is there a workable way to indent the code at the level of
   build_func, and not on column 0 ?

  execif 1: + code.rstrip()

  Peter

  Why is the 'if' needed here ? I had .strip work for me:

 A simple .strip() doesn't work if the code comprises multiple lines:

  def f():

 ... return 
 ... x = 42
 ... if x  0:
 ... print x
 ... 
 ... exec if 1:\n + f().rstrip()
 42
  exec f().strip()

 Traceback (most recent call last):
   File stdin, line 1, in module
   File string, line 2
 if x  0:
 ^
 IndentationError: unexpected indent


I see. In my case I only evaluate function definitions with 'exec', so
I only need to de-indent the first line, and the others can be
indented because they're in a new scope anyway. What you suggest works
for arbitrary code and not only function definitions. It's a nice
trick with the if 1: :-)


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


Re: Weird local variables behaviors

2008-06-21 Thread Sebastjan Trepca
I see, intuitively one would think it would try to get it from global
context as it's not yet bound in the local.

Thanks for the explanation.

Sebastjan


On Sat, Jun 21, 2008 at 5:48 AM, Dan Bishop [EMAIL PROTECTED] wrote:
 On Jun 20, 7:32 pm, Matt Nordhoff [EMAIL PROTECTED] wrote:
 Sebastjan Trepca wrote:
  Hey,

  can someone please explain this behavior:

  The code:

  def test1(value=1):
  def inner():
  print value
  inner()

  def test2(value=2):
  def inner():
  value = value
  inner()

  test1()
  test2()

  [EMAIL PROTECTED] ~/dev/tests]$ python locals.py
  1
  Traceback (most recent call last):
File locals.py, line 13, in module
  test2()
File locals.py, line 10, in test2
  inner()
File locals.py, line 9, in inner
  value = value
  UnboundLocalError: local variable 'value' referenced before assignment

  Why can't he find the variable in the second case?

  Thanks, Sebastjan

 Python doesn't like when you read a variable that exists in an outer
 scope, then try to assign to it in this scope.

 (When you do a = b, b is processed first. In this case, Python
 doesn't find a value variable in this scope, so it checks the outer
 scope, and does find it. But then when it gets to the a =  part...
 well, I don't know, but it doesn't like it.)

 In a language like C++, the scope of a variable is determined by the
 declaration.

 int x; // A
 class Example
 {
   int x; // B
   void f()
   {
  int x; // C
  x = 42; // Which x?
   }
 };

 The x referred to in the statement x = 42; refers to local
 variable of Example::f.  If line C were removed, then it would refer
 to the member variable of class Example.  And if line B were removed,
 then it would refer to the global variable.

 In Python, however, there are no declarations.  Therefore, it requires
 another approach.  What it chose was:

 (1) Explicit self for object attributes.
 (2) A function's local variables are defined as those appearing on the
 left side of an assignment.  Whether the name happens to refer to a
 global is NOT considered.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Python is behavior

2008-06-21 Thread Lie
On Jun 21, 2:14 am, Gary Herron [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  On Jun 20, 9:38 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:

  On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), [EMAIL PROTECTED] wrote:

  I am not certain why this is the case, but...

  a = 256
  b = 256
  a is b

  True

  a = 257
  b = 257
  a is b

  False

  Can anyone explain this further? Why does it happen? 8-bit integer
  differences?

 http://mail.python.org/pipermail/python-list/2001-November/113994.html

  Jean-Paul

  Thank you for this Jean-Paul. I did know about the identity of
  objects, but my curiosity is based on the 256 number. Are the 2^8
  integers cached due to the internal loops, or is there any other
  specific reason? Is this something that can be controlled?

 Python provides no way to change that number, but of course you can
 always fiddle with the source code and recompile.   The actual value is
 a trade off (like any caching scheme) of cache-space versus efficiency
 gains.   The value has changed at least once in recent versions of Python.

And if your code breaks because of this, don't whine, 'cause you've
already been warned not to rely on it. Exactly the same arguments with
other people that is/going to whine because they break the
encapsulation.
--
http://mail.python.org/mailman/listinfo/python-list


earn money from Blogs

2008-06-21 Thread Katreena
Hello friends..,

Welcome to the world of Information Technology,Enjoy the fragrance of
Modern Life styleMake ur Living more comfortable than everbefore!

Earn Millions of Dollars legal Income With Little Efforts In ur Spare
time!

Success usually comes to those who are too busy to be looking for it.

Visit Related sites,Hollywood Movies and Videos etc..,
- Hide quoted text -

www.hollywoodmoviespot4u.blogspot.com



bra href=http://www.hollywoodmoviespot4u.blogspot.com;img

src=http://images.orkut.com/orkut/albums2/
ATcAAABsx9X_PdEKRPfeN3jnJfBnpD_jMPl3wHs0fzVsWL9p5ajVn48qiB5dC7XIC6sRU4wdlveMwNIrBr1iOlB24r6NAJtU9VDgrW-
iCuDGAM2T7zW6uE-cK9pN9g.jpgHii…Click  image/a



xxx

a href=http://www.hollywoodmoviespot4u.blogspot.com;img

src=http://actress-trisha.com/trisha-gallery/albums/cute%20trisha
%20saree%20photos/normal_cute_trisha_in_saree_photos_1_
%2870%29.jpgHi..Click me/a/p

xxx



a href=http://www.hollywoodmoviespot4u.blogspot.com;img

src=http://bp0.blogger.com/_8HN_k9I49ws/RxJZG3MtwuI/AJ4/o6ATL-
Md1OU/s400/celeb-ad2.jpgHi..Click me/a/p

xx

a href=http://www.hollywoodmoviespot4u.blogspot.com;img
src=http://www.celebrites-selection.com/photos_copper/albums/A/
Aishwarya/Aishwarya_2304.jpgHi..Click me/a/p


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


exec with custom dict

2008-06-21 Thread Anand

Hi,

I am trying to use exec with custom dict.
I am trying to print the value of variable x in 2 places. It is
printing it at the first place and failing at the second place.

class Env(dict):
def __getitem__(self, key):
return self.get(key, key)

code = 
print x
def f(): return x


env = Env()
exec(code, env)
print env['f']()

Here is the output I'm getting.

x
Traceback (most recent call last):
  File a.py, line 14, in module
print env['f']()
  File string, line 3, in f
NameError: global name 'x' is not defined

Can somebody explain me what is happening?

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


How to convert a into a

2008-06-21 Thread dominique
Hello All,

In a wx GUI,  I would like to let the user choose between ,  or =.
So, I created a combobox and when the user chooses  for instance, I
wanted to return  (the objective is to send the operator into another
complex method):
Example:
if variable == :
return 

But this is invalid syntax.

How can I transform a  into the  operator ie without parenthesis,
so that I can load it into another function ?

Thanks in advance

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


Re: How to convert a into a

2008-06-21 Thread John Machin
On Jun 21, 9:17 pm, dominique [EMAIL PROTECTED] wrote:
 Hello All,

 In a wx GUI,  I would like to let the user choose between ,  or =.
 So, I created a combobox and when the user chooses  for instance, I
 wanted to return  (the objective is to send the operator into another
 complex method):
 Example:
 if variable == :
 return 

 But this is invalid syntax.

 How can I transform a  into the  operator ie without parenthesis,
 so that I can load it into another function ?

Look at the operator module. In your above example:

return {
   '': operator.gt,
   '=': operator.eq,
   '': operator.lt,
   }[variable]

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


Re: Rytk�sen l�ht�oletukset kaatuneet fotonien energiaan liittyvien rtistiriitaisuuksien vuoksi?

2008-06-21 Thread Santeri Friman
Oli taas härski vedätys ydinalaltamme. Eli ei antanut Kalli julkisuuteen
edes sitä laajasti tunnettua faktaa, että hänen mm. 60v juhlat järjesti, kas
kummaa TVO! Olisi toimittajilta kyllä ollut minimi vaatia edes näin räikeää
faktaa esille.

Mutta kuten olemme saaneet tottua ydinhallinnon tekemiin
rötös/lahjusjuttuepäilyihin ei maassamme tietysti kukaan yksinkertaisesti
uskalla kajota. Ei vaikka kyseessä oli siis juttu, joka on laajasti jo nyt
paikkakunnilla tiedossa.

No toki Lipposen kaltaiset massarahavirrat ydinalalta on klassikkoja ja
niin maare perusteellisen hiljaa ollaan mm. Lipposen nykyrahoittajan
ydinalan lonkeroista myös näissä. Sopii kysyä, että halutaanko totuutta
ydinkorruptiomme tasoista oikeasti edes etsiä?(
--
http://mail.python.org/mailman/listinfo/python-list

some jordan shoes and something for wholesale

2008-06-21 Thread jim
would you  want to buy cheap something?welcome to www.wholenikee.cn
--
http://mail.python.org/mailman/listinfo/python-list


some jordan shoes and something for wholesale

2008-06-21 Thread tom
would you  want to buy cheap something?welcome to www.wholenikee.cn
--
http://mail.python.org/mailman/listinfo/python-list


Fast and easy GUI prototyping with Python

2008-06-21 Thread erokar
Which tools would you use? I want the interface design to be as easy
and fast as possible, all ideology aside. I'm considering either
IronPython+Visual Studio or Python+Qt -- but I'm open for other
suggestions.

Visual Studio seems to offer the easiest solution, but is IronPython
stable enough? How easy is the IronPython/Visual Studi integration?
What about IronPython Studio?
--
http://mail.python.org/mailman/listinfo/python-list


Re: An idiom for code generation with exec

2008-06-21 Thread Lie
On Jun 21, 2:02 pm, eliben [EMAIL PROTECTED] wrote:
 On Jun 21, 8:52 am, Peter Otten [EMAIL PROTECTED] wrote:



  eliben wrote:
   On Jun 20, 2:44 pm, Peter Otten [EMAIL PROTECTED] wrote:
   eliben wrote:
Additionally, I've found indentation to be a problem in such
constructs. Is there a workable way to indent the code at the level of
build_func, and not on column 0 ?

   execif 1: + code.rstrip()

   Peter

   Why is the 'if' needed here ? I had .strip work for me:

  A simple .strip() doesn't work if the code comprises multiple lines:

   def f():

  ...     return 
  ...     x = 42
  ...     if x  0:
  ...             print x
  ...     
  ... exec if 1:\n + f().rstrip()
  42
   exec f().strip()

  Traceback (most recent call last):
    File stdin, line 1, in module
    File string, line 2
      if x  0:
      ^
  IndentationError: unexpected indent

 I see. In my case I only evaluate function definitions with 'exec', so
 I only need to de-indent the first line, and the others can be
 indented because they're in a new scope anyway. What you suggest works
 for arbitrary code and not only function definitions. It's a nice
 trick with the if 1: :-)

Have you actually profiled your code? Or are you just basing this
assumptions on guesses?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Sebastian lunar Wiesner
[EMAIL PROTECTED] [EMAIL PROTECTED]:

 Which tools would you use? I want the interface design to be as easy
 and fast as possible, all ideology aside. I'm considering either
 IronPython+Visual Studio or Python+Qt -- but I'm open for other
 suggestions.

I'm using the latter, and am perfectly happy with a combination of Qt
Designer as GUI editor and emacs as code editor.

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a into a

2008-06-21 Thread dominique
On Jun 21, 1:37 pm, John Machin [EMAIL PROTECTED] wrote:

 Look at the operator module. In your above example:

 return {
'': operator.gt,
'=': operator.eq,
'': operator.lt,
}[variable]

 Cheers,
 John

Thanks a lot John
Dominique
--
http://mail.python.org/mailman/listinfo/python-list


Way to unblock sys.stdin.readline() call

2008-06-21 Thread joamag
HI,

Is there any possible way to unblock the sys.stdin.readline() call
from a different thread.
Something like sys.stdin.write() but that would actually work ...
something to put characters in the stdin...

Thanks in advance,
João
--
http://mail.python.org/mailman/listinfo/python-list


Re: An idiom for code generation with exec

2008-06-21 Thread eliben
  I see. In my case I only evaluate function definitions with 'exec', so
  I only need to de-indent the first line, and the others can be
  indented because they're in a new scope anyway. What you suggest works
  for arbitrary code and not only function definitions. It's a nice
  trick with the if 1: :-)

 Have you actually profiled your code? Or are you just basing this
 assumptions on guesses?

First of all, I see absolutely no connection between your question and
the text you quote. Is there? Or did you pick one post randomly to
post your question on?

Second, yes - I have profiled my code.

Third, this is a very typical torture path one has to go through when
asking about code generation. It is true of almost all communities,
except Lisp, perhaps. You have to convince everyone that you have a
real reason to do what you do. The simple norm of getting a reply to
your question doesn't work when you get to code generation. I wonder
why is it so. How many people have been actually burned by bad code
generation techniques, and how many are just parroting goto is evil
because it's the accepted thing to say. This is an interesting point
to ponder.

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


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread eliben
On Jun 21, 3:36 pm, [EMAIL PROTECTED] wrote:
 Which tools would you use? I want the interface design to be as easy
 and fast as possible, all ideology aside. I'm considering either
 IronPython+Visual Studio or Python+Qt -- but I'm open for other
 suggestions.

 Visual Studio seems to offer the easiest solution, but is IronPython
 stable enough? How easy is the IronPython/Visual Studi integration?
 What about IronPython Studio?

I've had success using wxPython in conjunctin with wxGlade. wxGlade is
quite flexible, allows quick previews and generates code that's not
bad. The wxPython binding is very well supported and works nicely in
practice. And, best of all, this solution is both free and completely
cross-platform.

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


Getting column names from a cursor using ODBC module?

2008-06-21 Thread dananrg
Is there any way to retrieve column names from a cursor using the ODBC
module? Or must I, in advance, create a dictionary of column position
and column names for a particular table before I can access column
values by column names? I'd prefer sticking with the ODBC module for
now because it comes standard in Python.

I'm using Python 2.4 at the moment.

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


sys.settrace 'call' event behavior

2008-06-21 Thread Michal Kwiatkowski
I'm building a tool to trace all function calls using sys.settrace
function from the standard library. One of the awkward behaviors of
this facility is that the class definitions are reported as 'call'
events.[1] Since I don't want to catch class definitions, only
function calls, I'm looking for a way to differentiate between those
two. So far I have only vague clues about how to do that.

At the bottom of this mail is a simple script that prints all
attributes (except for the bytecode) of the traced code. In the sample
code Bar class is defined and foo function is called after that. The
following trace output is reported:

Bar, 0, 0, (), (), (), (None,), ('__name__', '__module__', 'None'),
foo.py, 21, , 1, 66
foo, 0, 0, (), (), (), (None,), (), foo.py, 25, , 1, 67

Class definition and function call differs on four attributes. Two of
them, co_name and co_firstlineno are not very helpful. Other two are
co_names and co_flags. The latter differs only by the CO_OPTIMIZED
flag, which is for internal use only[2]. So we're left with
co_names, which is a tuple containing the names used by the
bytecode. Is that helpful in distinguishing between class definitions
and function calls? Do you have any other ideas on how to tell them
apart?

Source of the sample script I used follows.

def trace(frame, event, arg):
if event == 'call':
print ', '.join(map(str, [frame.f_code.co_name,
  frame.f_code.co_argcount,
  frame.f_code.co_nlocals,
  frame.f_code.co_varnames,
  frame.f_code.co_cellvars,
  frame.f_code.co_freevars,
  frame.f_code.co_consts,
  frame.f_code.co_names,
  frame.f_code.co_filename,
  frame.f_code.co_firstlineno,
  frame.f_code.co_lnotab,
  frame.f_code.co_stacksize,
  frame.f_code.co_flags]))
return trace

import sys
sys.settrace(trace)

class Bar(object):
None
pass

def foo():
pass

foo()

[1] It is strange for me, but documented properly.
http://docs.python.org/lib/debugger-hooks.html says that call event
happens when a function is called (or some other code block
entered).

[2] http://docs.python.org/ref/types.html#l2h-145

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


Re: Getting column names from a cursor using ODBC module?

2008-06-21 Thread John Machin
On Jun 21, 11:58 pm, [EMAIL PROTECTED] wrote:
 Is there any way to retrieve column names from a cursor using the ODBC
 module? Or must I, in advance, create a dictionary of column position
 and column names for a particular table before I can access column
 values by column names? I'd prefer sticking with the ODBC module for
 now because it comes standard in Python.

 I'm using Python 2.4 at the moment.

 Thanks.

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


Re: Getting column names from a cursor using ODBC module?

2008-06-21 Thread John Machin
On Jun 21, 11:58 pm, [EMAIL PROTECTED] wrote:
 Is there any way to retrieve column names from a cursor using the ODBC
 module? Or must I, in advance, create a dictionary of column position
 and column names for a particular table before I can access column
 values by column names? I'd prefer sticking with the ODBC module for
 now because it comes standard in Python.

 I'm using Python 2.4 at the moment.


Do you mean the odbc module? If so, it doesn't come standard in
Python; it's part of the win32 package.

I haven't used it for years -- my preference on Windows these days
would be mxODBC if the client would pay the licence fee, otherwise
pyodbc. Sorry I'm not answering your question ... perhaps you should
be asking a different question :)

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


Re: Getting column names from a cursor using ODBC module?

2008-06-21 Thread John Machin
On Jun 22, 12:19 am, John Machin [EMAIL PROTECTED] wrote:
 On Jun 21, 11:58 pm, [EMAIL PROTECTED] wrote:

  Is there any way to retrieve column names from a cursor using the ODBC
  module? Or must I, in advance, create a dictionary of column position
  and column names for a particular table before I can access column
  values by column names? I'd prefer sticking with the ODBC module for
  now because it comes standard in Python.

  I'm using Python 2.4 at the moment.

 Do you mean the odbc module? If so, it doesn't come standard in
 Python; it's part of the win32 package.

 I haven't used it for years -- my preference on Windows these days
 would be mxODBC if the client would pay the licence fee, otherwise
 pyodbc. Sorry I'm not answering your question ... perhaps you should
 be asking a different question :)

 Cheers,
 John

But to help you answer your question: if the module that you are using
supports the 2.0 version of the database API (see 
http://www.python.org/dev/peps/pep-0249/),
then it will support the cursor.description attribute, which gives you
not only the name but the type and 5 other bits of info about each
column. If it doesn't, I'd suggest moving on.

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


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Val-Amart
On 21 июн, 15:36, [EMAIL PROTECTED] wrote:
 Which tools would you use? I want the interface design to be as easy
 and fast as possible, all ideology aside. I'm considering either
 IronPython+Visual Studio or Python+Qt -- but I'm open for other
 suggestions.

 Visual Studio seems to offer the easiest solution, but is IronPython
 stable enough? How easy is the IronPython/Visual Studi integration?
 What about IronPython Studio?

Use PyQt. You will gain great portability +all the functionality built
in qt.
You can try PyGTK also, though i wont recommend it.
--
http://mail.python.org/mailman/listinfo/python-list

Re: An idiom for code generation with exec

2008-06-21 Thread George Sakkis
On Jun 21, 9:40 am, eliben [EMAIL PROTECTED] wrote:

   I see. In my case I only evaluate function definitions with 'exec', so
   I only need to de-indent the first line, and the others can be
   indented because they're in a new scope anyway. What you suggest works
   for arbitrary code and not only function definitions. It's a nice
   trick with the if 1: :-)

  Have you actually profiled your code? Or are you just basing this
  assumptions on guesses?

 First of all, I see absolutely no connection between your question and
 the text you quote. Is there? Or did you pick one post randomly to
 post your question on?

 Second, yes - I have profiled my code.

 Third, this is a very typical torture path one has to go through when
 asking about code generation. It is true of almost all communities,
 except Lisp, perhaps. You have to convince everyone that you have a
 real reason to do what you do. The simple norm of getting a reply to
 your question doesn't work when you get to code generation. I wonder
 why is it so. How many people have been actually burned by bad code
 generation techniques, and how many are just parroting goto is evil
 because it's the accepted thing to say. This is an interesting point
 to ponder.

It's not as much that many people have been burned but that, like
goto, 99% of the time there are better alternatives. Off the top of my
head, two recurring threads in c.l.py related to dynamic code
generation and evaluation are:
- Asking how to dynamically generate variable names (for i in
xrange(10): exec 'x%d = %d' % (i,i)) instead of using a regular
dictionary.
- Using function names instead of the actual function objects and
calling eval(), not knowing that functions are first-class objects (or
not even familiar with what that means).

So even if your use case belongs to the exceptional 1% where dynamic
code generation is justified, you should expect people to question it
by default.

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


Re: advanced listcomprehenions?

2008-06-21 Thread Mark Wooding
Terry Reedy [EMAIL PROTECTED] wrote:

 The lookup table is a constant.  If made a tuple, it will be compiled as 
 a constant (as least in 2.6, maybe 2.5).  

Force of habit.  I tend to work on lists by indexing and/or iterating,
and on tuples by destructuring, and choose types based on the kinds of
things I'll be doing.  But I did intentionally ensure that the tables
were constant so that readers could apply the obvious optimization if
they wanted.  (Also, unnecessarily computing str(i) seemed bad.)

 In any case, it could (and to me should) be lifted out of the string
 comp.

For performance, yes.  But doing a modexp is going to kill performance
anyway, so I decided to save screen lines.  After all, applying even
fairly basic number theory to a problem like this isn't really what one
might call a readable solution. ;-)

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: optparse functionality missing

2008-06-21 Thread Mark Wooding
Jeff Keasler [EMAIL PROTECTED] wrote:

 In a scripting environment, I often want to strip some of the command
 line options off the argument list, and then pass the remaining
 options to another module that is deeper in the tool chain.

The difficulty is that you can't do an accurate parse without knowing
which options take arguments.  For example, what are the options here?

  foo -xyzzy -abcdef -ghi -ghi -g -hi

Well, `-z', `-f' and `-g' take arguments; the `-g' argument is
optional.  So the correct options to pass along are

  -x -y -zzy -a -b -c -d -e -f-ghi -ghi -g -h -i

Not so obvious, is it? ;-)

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


mod_wsgi vs mod_python interfaces

2008-06-21 Thread Pau Freixes
Hi list,

I remember red into this list that mod_wsgi is more faster than mod_python.
Why ?

WSIG it's only a true specification for deploy and performance Python
applications running into web servers, mod python it's like mod wsgi but
it's only a not official specification between Apache and Python aplications
or frameworks. Therefore the real difference between both module are a kind
of protocol/interface for talk with Python Aplication.

mod_wsgi and mod_python are written in C and only how their internal data
structures and memory managment and other issues can justify a different
performance. Or WSGI interface it's more efficient than mod_python interface
?

What do you think about this ?

-- 
Pau Freixes
Linux GNU/User
--
http://mail.python.org/mailman/listinfo/python-list

Re: Way to unblock sys.stdin.readline() call

2008-06-21 Thread Cédric Lucantis
Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit :
 HI,

 Is there any possible way to unblock the sys.stdin.readline() call
 from a different thread.
 Something like sys.stdin.write() but that would actually work ...
 something to put characters in the stdin...


Do you mean setting stdin in non-blocking mode ? On unix you can do it with 
the fcntl module (you'll find more infos in the libc docs) :

fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)

and catch IOErrors with errno = EAGAIN. But I don't know how to do it in a 
portable way, suggestions welcome :)

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is behavior

2008-06-21 Thread Martin v. Löwis
 For some reason, stacking multiple statements reuses the same object.

Each code object has a co_consts tuple referring to all constants used
in the code. The compiler interns duplicate constants for a single
compiler run, resulting in the same object being used when the code
is put into a single line (or in a function, or module).

When the code is split into multiple interactive statements, the
compiler runs multiple times, and doesn't know anything about past
runs.

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


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Fuzzyman
On Jun 21, 1:36 pm, [EMAIL PROTECTED] wrote:
 Which tools would you use? I want the interface design to be as easy
 and fast as possible, all ideology aside. I'm considering 
 eitherIronPython+Visual Studio or Python+Qt -- but I'm open for other
 suggestions.

 Visual Studio seems to offer the easiest solution, but isIronPython
 stable enough? How easy is theIronPython/Visual Studi integration?
 What aboutIronPythonStudio?

IronPython 1 is very stable. IronPython 2 is still in beta.

The IronPython 1 and Visual Studio 2005 integration (via the SDK) is
pretty good. Personally I think IronPython Studio is a bit immature -
and I don't like the way it generates Python code anyway.

The Windows Forms designer in Visual Studio is pretty good.
Unfortunately better than most GUI designers available for other
Python compatible toolkits. I still don't like the designer for
creating UIs with fluid layouts - I don't think it handles them very
well.

In my opinion, the best way to use the designer is to actually
generate C# rather than IronPython code. You can then subclass from
IronPython and implement the programmed behaviour - using the designer
only for the UI layout.

Windows Forms is very cross platform now with Mono. Mono now has full
coverage of the .NET 2.0 winforms APIs.

Michael Foord
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: urllib (54, 'Connection reset by peer') error

2008-06-21 Thread John Nagle

Tim Golden wrote:

[EMAIL PROTECTED] wrote:

Thanks for the help.  The error handling worked to a certain extent
but after a while the server does seem to stop responding to my
requests.

I have a list of about 7,000 links to pages I want to parse the HTML
of (it's basically a web crawler) but after a certain number of
urlretrieve() or urlopen() calls the server just stops responding.
Anyone know of a way to get around this?  I don't own the server so I
can't make any modifications on that side.


I think someone's already mentioned this, but it's almost
certainly an explicit or implicit throttling on the remote server.
If you're pulling 7,000 pages from a single server you need to
be sure that you're within the Terms of Use of that service, or
at the least you need to contact the maintainers in courtesy to
confirm that this is acceptable.

If you don't you may well cause your IP block to be banned on
their network, which could affect others as well as yourself.


   Interestingly, lp.findlaw.com doesn't have any visible terms of service.
The information being downloaded is case law, which is public domain, so
there's no copyright issue.  Some throttling and retry is needed to slow
down the process, but it should be fixable.

   Try this: put in the retry code someone else suggested.  Use a variable
retry delay, and wait one retry delay between downloading files.  Whenever
a download fails, double the retry delay and try
again; don't let it get bigger than, say, 256 seconds.  When a download
succeeds, halve the retry delay, but don't let it get smaller than 1 second.
That will make your downloader self-tune to the throttling imposed by
the server.

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


Re: Strange re problem

2008-06-21 Thread TYR
On Jun 20, 3:35 pm, Paul McGuire [EMAIL PROTECTED] wrote:
 On Jun 20, 6:01 am, TYR [EMAIL PROTECTED] wrote:

Thank you very much. This pyparsing module looks damned useful.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread erokar
Thanks for your input. The prototype will be running on Windows only.
Portability  and being able to develop on other platforms would be a
bonus, but is not a requirement. I guess the choice is going to be
between Visual Studio and Qt. Of importance is:

1) Being able to develop and change (dummy) GUI prototypes very fast,
i.e. drag and drop. I've tried Visual Studio's form designer -- it
seems quite capable. Don't know about Qt's designer -- is it as easy
and fast to use?

2) The Qt vs. .NET API. I have no experience with Qt's API and a
rudimentary experience with the .NET API (seems powerfull but also big
and complex).

Michael: Interesting suggestion to just subclass C#, maybe that's the
way to go.
--
http://mail.python.org/mailman/listinfo/python-list


install py2exe in vista

2008-06-21 Thread Herman
 I want to install it in
vistahttp://www.daniweb.com/forums/thread130469.html#,
but i get this message in the process:
could not create... py2exe-py2.5

I press 'OK', then..
could not set key value python 2.5 py2exe-0.6.8

I press 'OK' again, then...
could not set key value
c:\Python25\Removepy2exe.exe -u c:\python25\py2exe-wininst.log

The installation goes on and do something, run some postinstall script.

I thought it should be ok, but i fail even creating a simple hello word exe.
I get this message after i run python setup.py install:
running install
running build
running install_egg_info
Writing c:\Python25\Lib\site-packages\UNKNOWN-0.0.0-py2.5-egg-info

No output is created.

Can I anyone help me with this?  http://www.addthis.com/bookmark.php
  http://www.daniweb.com/forums/editpost.php?do=editpostp=631985
--
http://mail.python.org/mailman/listinfo/python-list

Unbuffered stdout/auto-flush

2008-06-21 Thread Yang Zhang
Hi, is there any way to get unbuffered stdout/stderr without relying on 
the -u flag to python or calling .flush() on each print (including 
indirect hacks like replacing sys.stdout with a wrapper that succeeds 
each write() with a flush())?  Thanks in advance!

--
Yang Zhang
http://www.mit.edu/~y_z/
--
http://mail.python.org/mailman/listinfo/python-list


SSL

2008-06-21 Thread Ricardo Tiago
Hi,

Is it possible to access a https site using a certificate and keeping the
session alive like it happens in the browsers?  I'm doing a command line app
that needs to access a https site to retrieve information but using the
httplib, each time i make a request it asks for the pem pass phrase.

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

passing control to other window

2008-06-21 Thread varun chadha
i am trying to develop a application using Tkinter in which a new
window pops out on a particular button press.though i can pass control
automatically to that window using .force_focus() method and disabling
all my widgets in previous window but the technique is not so clean.
for eg. when u click 'save' a window pops out asking for location but
u can still close your previous window using the 'cross-mark' on top
right corner with save window still open.
can anyone help me out!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Way to unblock sys.stdin.readline() call

2008-06-21 Thread joamag
On Jun 21, 4:46 pm, Cédric Lucantis [EMAIL PROTECTED] wrote:
 Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit :

  HI,

  Is there any possible way to unblock the sys.stdin.readline() call
  from a different thread.
  Something like sys.stdin.write() but that would actually work ...
  something to put characters in the stdin...

 Do you mean setting stdin in non-blocking mode ? On unix you can do it with
 the fcntl module (you'll find more infos in the libc docs) :

 fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)

 and catch IOErrors with errno = EAGAIN. But I don't know how to do it in a
 portable way, suggestions welcome :)

 --
 Cédric Lucantis

Thanks for the advice that's a way of solving my problem, but I really
need a portable way of doing it...

The application I’m build is meant to be run in more platforms than
Unix ... so I really need a portable way of doing that or something
else that unblocks the read call in the stdin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Welho luopunut TF-boxin markkinoinnista.

2008-06-21 Thread Aleksi Krause
01.05.2008 Jää historian kirjoihin erityispäivämääränä josta alkaa ydinalan
vaikeudet kasautumaan aivan erityisesti myös Suomessa. Jo siitä asti kun
puollisentoista vuotta sitten Krister Fuuglesangin NASA:n
avaruusionisaatioraportin tiedot maapalloa kohtaavasta vääjäämättömästä
ydinvoimapäästöjen megatuhosta vuodettiin maailman päättäjille ydinalan
alasajon välttämättömyys on ollut tiedossa. Samasta pohjasta jopa IPCC
ennakoi koko ilmastojärjestelmän tuhoa 10v sisällä. Mutta toukokuusta alkaa
myös tietomuruja mainiyusta maailmanhistorian suurimmasta
ydinkatastrofitulemisesta vuotaa, esim. kauttani viimein suuren kansanmassan
tietoisuuteen. Mistä tarkemmin on kyse. Maailman metastabiilinen
perustaustataso on 10-kertaistunut totaalisen tuhoisaan suuntaansa
romahdellen. Luonto itsessään viestittää katastrofaalisista
mehiläistuhoviesteistä ja vastaavantyyppisistä
ydinkampamaneetti-invaasioista kiihtyvästi. Einsteinin 5v
mehiläishäviämisnäytöistä ennakoima ionosfäärituho on vyöryämässä kaikin
merkein ihmiskunnan kohtaloksi.

Onnistuin saamaan ydinalan silkaksi kauhuksi YVA 4/TEM tiedostoihin
maininnat siitä, että tulevat sukupolvet voivat myös arkistofaktojen
perusteella tuomita nykyiset ydintoimitsijat, firmat ja päättäjät ydinalan
kansainväliseen Nyyrbergin oikeudenkäyntiin päättäjiemme nyttemmin kiistatta
tietämistä rikoksistaan ihmiskuntaa vastaan. Niin pitkälle on prosessi
edennyt, että Sisäministeriö jo panikoi tämän tulevan faktan tietäen!
YLE-teksti-TV kirjoitti, miten vähin äänin oli muutettu maamme lakia
rajusti:  Rikoksista ihmisyyttä vastaan on toimeenpantu lakimuutos 01.05
lukien, että jatkossa henkilöitä, ryhmiä ja teollisuuslaitoksia jne. jotka
tuomitaan erittäin raskauttavista (ydin) ja sotatoimista kansaansa vastaan
ja rikoksista ihmisyyttä vastaan ei voida tuomita Suomesta kansainvälisiin
Haagin tuomioistuimiin saamaan jopa kuolemantuomioitaan. Vaan jopa näin
rajuista rikoksista langetetaan korkeintaan Suomen lainsäädännöllä paikan
päällä maksimirangaistukseksi rajaten vain elinkautisiksi! Siis huh, hu
alkaa ydinherrojemme polvet tutista alati kasvavien ydinrikosilmitulojen
paineissa! Ilmankos Heiniluoma sanoi, ettei Suomeen TVO:n kaavailemia
isotooppilaitostartteja ja ydinvoimaloittemme keskeisiä
plutoniumpoltto-oikeuksia, uraanikaivosmassiiveineen ja
ydinjätekäsittelyineen EU:sta kiirehditä. Vaan oltiin yht äkkiä sitä mieltä,
ettei edes seuraavakaan hallitus tunke kokoomuksen/TVO/Posiva:n
suunnattomaksi mieliharmiksi lupaa hakien kansantahtoa vastaan
edellämainittuihin NATOn hyväksymiin-optiotoimiin.

02.04-08. Uutiset kertoivat, että jälleen kerran oli Norjassa 200km Oslosta
pohjoiseen Ottessa sortunut tektoniliikunnasta 300m pitkä ja 50m leveä
kalliorinne ja allle oli hautautunut  vähintään 150 hengen pakolaisvirran
startanneen väestön kymmenet talot. Edellisestä tästä kuuluisasta 2500 km
pitkästä Laatokka-Skotlantitektonisesta Litoraanisaumalikunnasta Olkiluodon
läpi olimme saaneet viestejä Norjasta 5 hengen kuolemaepäilystä ja 7m
liikuneesta vuorirojahduksesta kuukausi sitten. Päivän selvästi tämä
kyseinen maailman syvin maanpäällinen tektonisauma on hurjasti
aktivoitumassa. Niin ruotsalaisvoimalat, kuin  Olkiluodon kaikki laittomasti
mm. kallioon ankkuroidut ydinvoimalat tulevat liikuntojen murskaamina
joutumaan suunnattomiin vaikeuksiin. 5cm/v liikuva sauma kun tuottaa
jatkossa ruotsalaisopein huikeita mitattuja yli 8 Rihterin maanjäristyksiä!
Edes vuoden takaista 450m kallioliikuntoa Ruotsissa saati saman aikaista 14
Norjan luolan tuhoa ei olla uskallettu tutkia julkisesti. Virannoimaisten
panikointi muutti jo nyt koko Ruotsin tektonisaumaan ydinjätehautauskuviot
totaalisesti syväporausmalleihinsa. Esimauksi myös Suomeen 10 kertaistuneine
lisämaksuin turvarajamuutospakoin. Mutta kaikesta näkee, ettei luonto tähän
tyydy, vaan pahentaa odotettaan alati!
--
http://mail.python.org/mailman/listinfo/python-list

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-21 Thread Bart Kastermans
On Jun 17, 1:01 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 En Mon, 16 Jun 2008 07:34:06 -0300, Bart Kastermans [EMAIL PROTECTED] 
 escribió:

  Summary: can't verify big O claim, how to properly time this?

  This is interesting.  I had never attempted to verify a big O
  statement
  before, and decided that it would be worth trying.  So I wrote some
  code to
  collect data, and I can't find that it goes quadratic.

 In your test code, you're concatenating only two strings, that's a *single* 
 operation, and takes time proportional to the total length.
 The quadratic behavior appears when you do *several* concatenations in a row 
 (like in your original code, where += was used several times to build a 
 result).
 If you want to verify it, try joining N strings of size M (for varying values 
 of N and M), and plot total time vs. N (for a given M value), and total time 
 vs. M (for a given N value) and finally total time vs. (N*M), see what 
 happens and post your findings again.

 --
 Gabriel Genellina

I did the work and found that for trees it does not go quadratic at
all, from the computations you suggest it is easy to get quadratic
behavior though.  Also this does not depend in any way I can see on
the implementation by Python.  Actual time might certainly improve by
doing it differently (changing the constants), but the big O results
won't.

For pictures and math I have put it up on my blog again see:
http://kasterma.wordpress.com/2008/06/21/complexity-of-string-concatenation-ii/

Thanks to everyone who commented so far on this subject.  I had some
good fun with it so far.

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


Re: Getting column names from a cursor using ODBC module?

2008-06-21 Thread Chris
On Jun 21, 3:58 pm, [EMAIL PROTECTED] wrote:
 Is there any way to retrieve column names from a cursor using the ODBC
 module? Or must I, in advance, create a dictionary of column position
 and column names for a particular table before I can access column
 values by column names? I'd prefer sticking with the ODBC module for
 now because it comes standard in Python.

 I'm using Python 2.4 at the moment.

 Thanks.

You should be able to do

column_names = [d[0] for d in cursor.description]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Fuzzyman
On Jun 21, 6:15 pm, [EMAIL PROTECTED] wrote:
 Thanks for your input. The prototype will be running on Windows only.
 Portability  and being able to develop on other platforms would be a
 bonus, but is not a requirement. I guess the choice is going to be
 between Visual Studio and Qt. Of importance is:

 1) Being able to develop and change (dummy) GUI prototypes very fast,
 i.e. drag and drop. I've tried Visual Studio's form designer -- it
 seems quite capable. Don't know about Qt's designer -- is it as easy
 and fast to use?

 2) The Qt vs. .NET API. I have no experience with Qt's API and a
 rudimentary experience with the .NET API (seems powerfull but also big
 and complex).

 Michael: Interesting suggestion to just subclass C#, maybe that's the
 way to go.

I found the Windows Forms APIs pretty straightforward. You can get a
good introduction to the .NET APIs from IronPython in Action. ;-)

Michael Foord
http://www.ironpythoninaction.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Way to unblock sys.stdin.readline() call

2008-06-21 Thread Jean-Paul Calderone

On Sat, 21 Jun 2008 12:35:02 -0700 (PDT), joamag [EMAIL PROTECTED] wrote:

On Jun 21, 4:46 pm, Cédric Lucantis [EMAIL PROTECTED] wrote:

Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit :

 HI,

 Is there any possible way to unblock the sys.stdin.readline() call
 from a different thread.
 Something like sys.stdin.write() but that would actually work ...
 something to put characters in the stdin...

Do you mean setting stdin in non-blocking mode ? On unix you can do it with
the fcntl module (you'll find more infos in the libc docs) :

fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)

and catch IOErrors with errno = EAGAIN. But I don't know how to do it in a
portable way, suggestions welcome :)

--
Cédric Lucantis


Thanks for the advice that's a way of solving my problem, but I really
need a portable way of doing it...

The application I’m build is meant to be run in more platforms than
Unix ... so I really need a portable way of doing that or something
else that unblocks the read call in the stdin


Twisted supports asynchronous handling of stdin on both POSIX and Windows.

See stdiodemo.py and stdin.py under the Miscellaenous section at
http://twistedmatrix.com/projects/core/documentation/examples/

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

Re: Sqlite3 textfactory and user-defined function

2008-06-21 Thread Gerhard Häring
[EMAIL PROTECTED] wrote:
 I've run into a problem with text encoding in the Sqlite3 module.  I
 think it may be a bug.  By default sqlite3 converts strings in the
 database from UTF-8 to unicode.  This conversion can be controlled by
 changing the connection's text_factory.
 
 I have a database that stores strings in 8-bit ISO-8859.  So, I set
 the text_factory to do no conversion.  In my database I use user
 defined functions.  I noticed that even when I set text_factory =
 lambda x:x, it appears to do UTF-8 to unicode conversion on strings
 that are passed to my user defined function. [...]

I've answered the same question on the pysqlite mailing list a few weeks
back:

Thread Trouble with create_function interface to sqlite

http://itsystementwicklung.de/pipermail/list-pysqlite/2008-May/62.html

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


Re: Way to unblock sys.stdin.readline() call

2008-06-21 Thread Terry Reedy



joamag wrote:


Is there any possible way to unblock the sys.stdin.readline() call
from a different thread.


If you want the thread to do something 'else' when no input is 
available, would this work?  Put readline in a thread that puts lines in 
a q=queue.Quese().  Then

try:
l=q.ge_nowait
process l
except queue.Empty
whatever without l

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


trying to find a substring in a string

2008-06-21 Thread barnacle . steve
I'm trying to write what should be a simple script in Python, which
I've never ever used before.

Essentially, I have a text file that has a list of full path file
names to other files, separated by carriage returns.
Contents of first file:
c:\blah.txt
c:\blah1.txt
c:\blah2.txt

The goal is for the user to specify another file, and then search the
specified file for instances of files from the first file.
Contents of user specified file:
file = c:\blah.txt
file = c:\blah1.txt

My goal is for the program to tell me that it found c:\blah.txt and c:
\blah1.txt.

I've read the contents of the existing file into an array, where each
element is a line from the file. I did the same thing with the user
specified file. I thought it would be a simple nested for loop to find
them, but I'm having no luck finding the strings. The string find
method doesn't do it for me. I've tried regular expressions, but it
never finds a match. I think it doesn't like when I do
re.compile(variableName), but without a debugger I have no way to tell
what's going on at all.

I keep telling myself this should be really simple, but I'm ready to
jump out a window.

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


My n00bie brain hurts after Python setup.py install.

2008-06-21 Thread bsagert
I downloaded Mark Pilgrims's feedparser.py in a zipfile to my Windows
machine, unzipped it and tried to install it to no avail.

Here is the result =

C:\python c:\scripts\feedparser-4.1\setup.py install
running install
running build
running build_py
file feedparser.py (for module feedparser) not found
running install_lib
warning: install_lib: 'build\lib' does not exist -- no Python modules
to install
running install_egg_info
Writing C:\Python25\Lib\site-packages\feedparser-4.1-py2.5.egg-info

WTF? The file feedparser.py did exist in the same place as setup.py.
Even if it works, what exactly does this setup.py do for me? If I just
manually place feedparser.py in my Python site-packages file it works
fine. As for that egg-info file, I googled python eggs and now I am
really confused.



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


Re: trying to find a substring in a string

2008-06-21 Thread Terry Reedy



[EMAIL PROTECTED] wrote:

I'm trying to write what should be a simple script in Python, which
I've never ever used before.

Essentially, I have a text file that has a list of full path file
names to other files, separated by carriage returns.
Contents of first file:
c:\blah.txt
c:\blah1.txt
c:\blah2.txt

The goal is for the user to specify another file, and then search the
specified file for instances of files from the first file.
Contents of user specified file:
file = c:\blah.txt
file = c:\blah1.txt

My goal is for the program to tell me that it found c:\blah.txt and c:
\blah1.txt.

I've read the contents of the existing file into an array, where each
element is a line from the file. 


Put each stripped (to delete \n) line into a set.  Then parse out the 
filenames and check that they are in the set.  Something like


def getname(line): whatever)

s=set(line.strip() for line in open('allfiles.txt', 'r'))
for line in open('paths.txt'):
  if getname(line) not in s:
return '%s not found'%line
else:
  return 'all found'

tjr

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


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Michael Torrie
[EMAIL PROTECTED] wrote:
 2) The Qt vs. .NET API. I have no experience with Qt's API and a
 rudimentary experience with the .NET API (seems powerfull but also big
 and complex).

Qt's API is very very good.  Easy to use and extremely powerful.  Note
that in Python a number of Qt's APIs are not used in favor of Python
native apis for things like file and socket I/O, IPC, Threads, and so
forth.  Additionally, PyQT does allow you the flexibility to move to
other platforms.  That need may not exist for you now, but it never
makes sense to me to needlessly lock yourself down.  As far as GUI
design goes, Qt and SWF would be on par, likely.  It's a bit of a
misnomer to be comparing Qt to the .NET API.  In IronPython you can of
course leverage all the class libraries in the CLR, but most python
programmers prefer to use python native libraries wherever possible.  If
you follow that, then it's SWF that compares to Qt.  I've not used VS
2008's SWF gui designer, but of all the designers I've seen so far, Qt's
Designer is the best I've ever used.  I don't ever use code generation
(GUIs should be created from the XML definitions), so integration with
an IDE is not a concern for me.

One issue about Qt is licensing, which could completely kill it for you.
 Although technically PyQt would insulate you from this issue to a
point, TrollTech will not license Qt for your use in a non-GPL project
if you began developing the project using the GPL version of Qt.


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


Python doc problem example: gzip module (reprise)

2008-06-21 Thread Byron Rios
 fileToCompress = open('finalcallejon.mb')
 fileToStr = fileToCompress.read()
 import gzip
 fileZipped = gzip.GzipFile('finalcallejon.mb.gz', 'wb', 9)
 fileZipped.write(fileToStr)
 fileZipped.close()

this may help you in 
http://mail.python.org/pipermail/python-list/2005-November/349718.html

have a nice day Emoticon1.gif--
http://mail.python.org/mailman/listinfo/python-list

Re: My n00bie brain hurts after Python setup.py install.

2008-06-21 Thread John Machin
On Jun 22, 9:05 am, [EMAIL PROTECTED] wrote:
 I downloaded Mark Pilgrims's feedparser.py in a zipfile to my Windows
 machine, unzipped it and tried to install it to no avail.

 Here is the result =

 C:\python c:\scripts\feedparser-4.1\setup.py install

The convention is to run setup.py from the current directory, unless
instructed otherwise; what did the package's readme say? Try:

cd \scripts\feedparser-4.1
python setup.py install

 running install
 running build
 running build_py
 file feedparser.py (for module feedparser) not found
 running install_lib
 warning: install_lib: 'build\lib' does not exist -- no Python modules
 to install
 running install_egg_info
 Writing C:\Python25\Lib\site-packages\feedparser-4.1-py2.5.egg-info

 WTF? The file feedparser.py did exist in the same place as setup.py.
 Even if it works, what exactly does this setup.py do for me? If I just
 manually place feedparser.py in my Python site-packages file it works
 fine.

In general, a setup.py install may do lots of things besides coping 1
file. Manually placing files in site-packages is not a good habit to
get into.

 As for that egg-info file, I googled python eggs and now I am
 really confused.

Eggs are part of a new experimental package distribution scheme. Don't
worry about it.

Cheers,
John

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


flock seems very unsafe, python fcntl bug?

2008-06-21 Thread xucs007
I ran following 2 programs (lock1, lock2) at almost same time,
to write either 123456, or 222 to file aaa at the same time.
But I often just got 222456 in aaa .

Is this a bug of python fcntl module ? See 2 programs I ran:



#!/usr/bin/env python
import fcntl, time
file = open('aaa', w)
fcntl.flock(file, fcntl.LOCK_EX)
file.write('123456')
time.sleep(10)
file.close()


#!/usr/bin/env python
import fcntl, time
file = open('aaa', w)
fcntl.flock(file, fcntl.LOCK_EX)
file.write('222')
time.sleep(10)
file.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unbuffered stdout/auto-flush

2008-06-21 Thread s0suk3
On Jun 21, 12:29 pm, Yang Zhang [EMAIL PROTECTED] wrote:
 Hi, is there any way to get unbuffered stdout/stderr without relying on
 the -u flag to python or calling .flush() on each print (including
 indirect hacks like replacing sys.stdout with a wrapper that succeeds
 each write() with a flush())?  Thanks in advance!


I think the only way is to reopen the stdout file descriptor:

import sys
import os

# reopen stdout file descriptor with write mode
# and 0 as the buffer size (unbuffered)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

print unbuffered text

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


Connecting a Desktop App to a Web App

2008-06-21 Thread Alex Bryan
Okay, this is my first post to this mailing list, so first off if I  
shouldn't be sending something here, PLEASE correct me. Okay, so I  
want to create an app that has a GUI (most likely Tkinter) and will  
prompt the user to choose files and such and then will upload those  
files, either regularly or one time, whatever. But I don't know how to  
go abou doing such a thing, that is creating a app that will  
automatically upload to a back-up website(online storage). So if  
anyone can help me out or point me in the right direction that would  
be great. Thanks!

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


Re: Connecting a Desktop App to a Web App

2008-06-21 Thread Daniel Fetchinson
 Okay, this is my first post to this mailing list, so first off if I
 shouldn't be sending something here, PLEASE correct me. Okay, so I
 want to create an app that has a GUI (most likely Tkinter) and will
 prompt the user to choose files and such and then will upload those
 files, either regularly or one time, whatever. But I don't know how to
 go abou doing such a thing, that is creating a app that will
 automatically upload to a back-up website(online storage). So if
 anyone can help me out or point me in the right direction that would
 be great. Thanks!

There are two cases: (1) you are in control of the web app (2) you are
not in control of the web app.

(1) So you need to make the web app yourself too. There are several
options for this the most popular ones are django and turbogears. For
more see http://wiki.python.org/moin/WebFrameworks Once you have your
web app up and running you can connect to it using some modules in the
stdlib: http://docs.python.org/lib/module-urllib2.html
http://docs.python.org/lib/module-httplib.html Basically you just
create http requests in your desktop app and send those just as a
browser would do.

(2) You need to figure out the API of the web app you want to connect
to. Once you have that use the stdlib modules to create the
appropriate http requests just as above.

HTH,
Daniel
-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Learning Python: Code critique please

2008-06-21 Thread macoovacany
http://macoovacany.wordpress.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Connecting a Desktop App to a Web App

2008-06-21 Thread Alex Bryan
Okay, well I wouldn't be creating the app, so, any hints on how to  
figure out the API of a web app I don't know super well?

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


Re: Buffer size when receiving data through a socket?

2008-06-21 Thread John Salerno

Dennis Lee Bieber wrote:

On Wed, 18 Jun 2008 09:56:29 -0400, John Salerno
[EMAIL PROTECTED] declaimed the following in comp.lang.python:

Interesting point. I'm not sure if it works that way though. I *think* I 
tried sending an empty string from the server back to the client, and as 
expected it exited the loop and closed the client, which doesn't make sense 
to me, since an empty string could be perfectly valid return data.



Okay... I suppose socket could consider a transmission with 0 data
bytes as valid data. The main key is that there had to be send of 0
data -- opposed to just not receiving anything..


No, I think you're right. I read elsewhere that when I send() call 
returns 0 bytes, the connection is automatically closed.

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


Re: Re: Connecting a Desktop App to a Web App

2008-06-21 Thread Daniel Fetchinson
 Okay, well I wouldn't be creating the app, so, any hints on how to
 figure out the API of a web app I don't know super well?

Is it something like google, youtube, facebook, etc? These have
publicly available API specifications.

If it's just a random website without a well maintained public API you
would look at the html source of the upload page and see what
name:value pairs are sent along with the file from the form that does
the upload. Then you would create such a POST request from python.

Cheers,
Daniel
-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ryhm�n sfnet.tietoliikenne.yhteydentarjoajat virallinen kuvaus

2008-06-21 Thread Atrophier Bigarr�s
MTV 3. 07.06.2008. Norjassa tuulivoima myötätuulessa. Norjan
energiatarpeista PUOLET voidaan kattaa tuulivoimalla, kun nykysuunnitelmat
toteutetaan! Kaiken kaikkiaan 130 tuulivoimalapuistohanketta on haettu
rakennuslupaa Norjan energiavirastolta. Jos kaikille halukkaille myönnetään
lupa energiantuotanto kasvaisi 56 terawatttitunnilla, mikä on noin puolet
maan nykytuotannosta. Näiden lisäksi 19 tuulihanketta on saanut
rakennusluvan, mutta rakentamista ei ole vielä alettu.

*Niin.. ..MYKISTÄVÄÄ! .. On jo päivän selvää, että Tanskan ja Saksan
uskaliaat uudisenergiairtiotot ovat saamassa arvoisensa triumfin. Maailman
energiajätit alkavat kääntyä ennennäkemättömän massiivisesti pois
ydinmenneisyydestä ja suuntaavat tuhdisti turpoaville
uudisenergiasektoreille. Erityisherkkuna on nimenomaan toimivimman
offshoremerituuliosuuden aukeaminen. Kun jopa Englannin kaltaiseen
pataydintaantumusvaltioon rakennetaan parhaillaan maailman masiivisinta
Loviisaluokan ofshoretuuloipuistoa, ydinalan korttipeli päättyi täyskaatoon.
Ja kohta sähköverkot myös kautta Pohjolan suorastaan notkuvat tuskin enää
kymmenesosaa ydinsähkökustannuksesta maksavaa 100% saasteetonta
bulkkiekoenergiaa. 100% säädettävät ja puolisen vuotta sitten Norjan
Trondheimissa mitatut käsittämättömän hyvät tuulivoiman ***99%
vuosipysyvyyshyötysuhteet  NELJÄ kertaa paremmat kuin
ydinreaktorirumiluksilla ajetut enemmän kuin vakuuttivat.***

Tässä on tulossa sellaiset energiantuotannon poistumat ydinvoiman
kaltaisista uudiskyvyttömistä vektoreista, että ydinvoiman mustapekka
sopeutumiskyvyttömälle Suomelle on varmentumassa. Tähän settiin kun Viro
julkaisee tuuliaikeensa ja saadaan ilman muuta Ruotsi mukaan, niin ydinsuomi
sotketaan mukavasti ydinsuohonsa, jopa omilla sähkömarkkinoillaan. KUKAAN EI
TARVITSE sikakallista säätökyvytöntä ja EU:ssa maineensa mokanutta
ydinvoimaa. Tulemme näkemään sellaisen ydinvastarinnan näemmä MYÖS
talousmiesten jaloin äänestyksin, ettei mitään jakoa. HIENOA!))
--
http://mail.python.org/mailman/listinfo/python-list

Re: How to convert a into a

2008-06-21 Thread Tim Roberts
dominique [EMAIL PROTECTED] wrote:

On Jun 21, 1:37 pm, John Machin [EMAIL PROTECTED] wrote:

 Look at the operator module. In your above example:

 return {
'': operator.gt,
'=': operator.eq,
'': operator.lt,
}[variable]

Thanks a lot John
Dominique

Yes, but you need to remember that what you are getting is not literally an
operator.  That is, if you store that return value in a variable called
op, you can't say this:

if x op y:


Instead, what you have is a function, so you'll have to write it:

if op( x, y ):
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


you can see lots of beautiful girl here, also you can see......

2008-06-21 Thread nokia
http://www.flixya.com/photo/360355/beautiful_
--
http://mail.python.org/mailman/listinfo/python-list


you can see lots of beautiful girls here, also you can see......

2008-06-21 Thread nokia
http://www.flixya.com/photo/360355/beautiful_
--
http://mail.python.org/mailman/listinfo/python-list


Earn 25 US$ in just 5 minutes . . .

2008-06-21 Thread Sushmeeta
Earn 25 US$ in just 5 minutes . . .

You can earn 25 US$ in just 5mins from now, please follow the simple
steps:
It's absolutely free to join.

Step 01

CLICK HERE (both, one by one)
http://www.awsurveys.com/HomeMain.cfm?RefID=sonub1001
http://www.AWSurveys.com/HomeMain.cfm?RefID=hello.sucho

A page will open

Step 02
Click on Create a Free Account

Step 03
Fill up the details and register.

Step 04
After registration, go to home. You will see - The Following Surveys
are Available:
A list of surveys is given under this heading. Just click on those
surveys and fill up the details by writing in few words, then submit
the both surveys. You will get paid.


Cut your mobile bills by Rs.900 by clicking the below blue link.
http://www.youmint.com/network-ranjan1001

For more interesting/earning  sites pl click here.
http://www.moneycosmos.com/?r=352706


For the above sites, first register yourself, then login it with the
same user name  password.
You may send this email to your friends also.

For More Details Plz contact me : [EMAIL PROTECTED]



Regards

Your's Sexy
--
http://mail.python.org/mailman/listinfo/python-list


[issue3008] Let bin() show floats

2008-06-21 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

Applied in r64438

--
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3158] Doctest fails to find doctests in extension modules

2008-06-21 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:

For me, a 'function' is written in Python, a 'builtin' is written in C. 

The fact that it is defined in an extension module is irrelevant, and
depends on the implementation: zlib is an extension module on Unix, but
is linked inside python26.dll on Windows.

maybe inspect.isroutine() is the correct test here.

--
nosy: +amaury.forgeotdarc

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3158
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3131] 2to3 can't find fixes_dir

2008-06-21 Thread Helmut Jarausch

Helmut Jarausch [EMAIL PROTECTED] added the comment:

This patch seems to work, but

when invoked it tries to write to /usr/local/lib/python3.0/lib2to3
( I get 
root: Writing failed:[Errno 13] Permission denied: '/usr/local/lib/
python3.0/lib2to3/PatternGrammar3.0.0.beta.1.pickle'
)

I hope this will be handled during install in future.

Furthermore, as a test, I copied refactor.py to xxx.py
and ran 2to3 on xxx.py

Here I get
RefactoringTool: Can't parse xxx.py: ParseError: bad input: type=22, 
value='=', context=('', (67, 71))

This error message is a bit terse for someone not knowing the details
of 2to3

Thanks for the patch,
Helmut.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3131
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3159] glob.py improvements

2008-06-21 Thread Aristotelis Mikropoulos

New submission from Aristotelis Mikropoulos [EMAIL PROTECTED]:

Simplified some of the code, improving performance and readability.

--
components: Library (Lib)
files: glob.py.patch
keywords: patch
messages: 68493
nosy: Indy
severity: normal
status: open
title: glob.py improvements
type: performance
versions: Python 2.5
Added file: http://bugs.python.org/file10680/glob.py.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3159
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3131] 2to3 can't find fixes_dir

2008-06-21 Thread Georgij Kondratjev

Georgij Kondratjev [EMAIL PROTECTED] added the comment:

 when invoked it tries to write to /usr/local/lib/python3.0/lib2to3

2to3 always worked like this. I always had to run it as root. Seems
weird for me too.

 Furthermore, as a test, I copied refactor.py to xxx.py
and ran 2to3 on xxx.py

It seems to be a bug with 2to3 processing refactor.py.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3131
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3131] 2to3 can't find fixes_dir

2008-06-21 Thread Giampaolo Rodola'

Changes by Giampaolo Rodola' [EMAIL PROTECTED]:


--
nosy: +giampaolo.rodola

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3131
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3101] global function _add_one_to_C

2008-06-21 Thread Ricardo Quesada

Ricardo Quesada [EMAIL PROTECTED] added the comment:

This seems to be fixed in r62348
http://svn.python.org/view?rev=62348view=rev

--
nosy: +riq

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3101
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3085] chapter 17.1.3.5 'Replacing os.popen*' in the Python library reference contains an error

2008-06-21 Thread Manuel Kaufmann

Manuel Kaufmann [EMAIL PROTECTED] added the comment:

I fixed this error, I attach the patch.

--
keywords: +patch
nosy: +humitos
Added file: http://bugs.python.org/file10681/libsubprocess.diff

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3085
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3043] Recursion bug in deepcopy

2008-06-21 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Two weeks passed, closing it manually (see
http://mail.python.org/pipermail/python-dev/2008-February/076992.html).

--
nosy: +facundobatista
status: pending - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3043
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3062] Turtle speed() function has no effect under Mac OS X

2008-06-21 Thread Ricardo Quesada

Ricardo Quesada [EMAIL PROTECTED] added the comment:

turtle.py was replaced by a new module in r63929 .
I can't reproduce this bug with this revision, so it seems to be fixed.
using: os/x 10.5.3 intel.

--
nosy: +riq

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3062
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3101] global function _add_one_to_C

2008-06-21 Thread Martin v. Löwis

Martin v. Löwis [EMAIL PROTECTED] added the comment:

Ok, so it's fixed for the trunk, but not Py3k. The trunk fix doesn't
port to 3k, since the functions are called inside memoryobject.c (so
making them static would break that module).

--
versions:  -Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3101
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3160] Building a Win32 binary installer crashes

2008-06-21 Thread Viktor Ferenczi

New submission from Viktor Ferenczi [EMAIL PROTECTED]:

Python 3.0b1, official MSI installer.

Checkout source code of this project:
http://code.google.com/p/anntools/

Enter into the root of your working copy and try to build a Win32 installer:

C:\Python30\python.exe setup.py bdist_wininst

NOTE: You might want to replace the path above with you Python
installation path. Please ensure, that Python 3.0 is used, since all
other versions from 2.4 to 2.6b1 works well.

You will get the following traceback during the build process:

Traceback (most recent call last):
  File setup.py, line 37, in module
anntools,
  File C:\python30\lib\distutils\core.py, line 149, in setup
dist.run_commands()
  File C:\python30\lib\distutils\dist.py, line 941, in run_commands
self.run_command(cmd)
  File C:\python30\lib\distutils\dist.py, line 961, in run_command
cmd_obj.run()
  File C:\python30\lib\distutils\command\bdist_wininst.py, line 177,
in run
self.create_exe(arcname, fullname, self.bitmap)
  File C:\python30\lib\distutils\command\bdist_wininst.py, line 263,
in create_exe
cfgdata = cfgdata + \0
TypeError: can't concat bytes to str

--
components: Distutils
messages: 68500
nosy: complex
severity: normal
status: open
title: Building a Win32 binary installer crashes
type: crash
versions: Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3160
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3160] Building a Win32 binary installer crashes

2008-06-21 Thread Viktor Ferenczi

Viktor Ferenczi [EMAIL PROTECTED] added the comment:

Fixed by appending the b (bytes) prefix to three string literals
concatenated to cfgdata in
C:\python30\lib\distutils\command\bdist_wininst.py:

Line #262:

# Append the pre-install script
cfgdata = cfgdata + b\0
if self.pre_install_script:
script_data = open(self.pre_install_script, r).read()
cfgdata = cfgdata + script_data + b\n\0
else:
# empty pre-install script
cfgdata = cfgdata + b\0
file.write(cfgdata)

Sorry for the source code fragment. I'll try to submit a patch instead
next time.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3160
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2701] csv.reader accepts string instead of file object (duck typing gone bad)

2008-06-21 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Skip is right, this is working ok.

--
nosy: +facundobatista
resolution:  - invalid
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2701
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com




[issue2732] curses.textpad loses characters at the end of lines

2008-06-21 Thread Anthony Lenton

Anthony Lenton [EMAIL PROTECTED] added the comment:

This doesn't happen to me with 2.6 compiled from HEAD, or with 2.5.2
shipped with Ubuntu Hardy.

In both cases the output is:

Contents of text box: '123456789\n123456789\n'

--
nosy: +elachuni

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2732
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3161] Missing import for sys in _abcoll

2008-06-21 Thread Simon Cross

New submission from Simon Cross [EMAIL PROTECTED]:

The _hash method of the Set ABC uses sys.maxsize but doesn't import sys.
The attached patch (against trunk) imports sys and adds a test to show
the problem. There are also still some other _abcoll.py cleanups waiting
in issue 2226.

--
components: Library (Lib), Tests
files: abcoll-hash.diff
keywords: patch
messages: 68504
nosy: hodgestar
severity: normal
status: open
title: Missing import for sys in _abcoll
versions: Python 2.6, Python 3.0
Added file: http://bugs.python.org/file10682/abcoll-hash.diff

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3161
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1817] module-cgi: handling GET and POST together

2008-06-21 Thread Nubis

Nubis [EMAIL PROTECTED] added the comment:

This was pretty much done when I got here. It broked the other cgi_test
(which tests some other corner cases).
Patch includes modifications to Lib/cgi.py and adds
Lib/test/test_cgi_post_qs.py to test the new features.

This should be closed by now, but since this is my first patch, just let
me know what else should I do to get it closed.

thanks!

--
keywords: +patch
nosy: +Nubis
versions: +Python 2.6
Added file: http://bugs.python.org/file10683/post_qs.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1817
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3161] Missing import for sys in _abcoll

2008-06-21 Thread Simon Cross

Simon Cross [EMAIL PROTECTED] added the comment:

One could also make a case for simply removing the _hash method since it
doesn't look like anything is using it? And anything that was using it
would already be broken?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3161
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3132] implement PEP 3118 struct changes

2008-06-21 Thread Jean Brouwers

Jean Brouwers [EMAIL PROTECTED] added the comment:

If the struct changes are made, add also 2 formats for C types ssize_t and 
size_t, perhaps 'z' resp. 'Z'.  In particular since on platforms 
sizeof(size_t) != sizeof(long).

--
nosy: +MrJean1

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3132
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1044479] docs for Py_UNICODE are wrong

2008-06-21 Thread Manuel Muradás

Manuel Muradás [EMAIL PROTECTED] added the comment:

This looks fixed to me. The current documentation is much more clear.
Look:
http://docs.python.org/api/unicodeObjects.html

--
nosy: +dieresys

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1044479
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2813] No float formatting in PyString_FromFormat

2008-06-21 Thread Ricardo Quesada

Ricardo Quesada [EMAIL PROTECTED] added the comment:

Do you expect to have support for float, double and long double ?
Also, do you expect to have support for precision-modifiers ?

--
nosy: +riq

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2813
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1044479] docs for Py_UNICODE are wrong

2008-06-21 Thread Manuel Muradás

Manuel Muradás [EMAIL PROTECTED] added the comment:

This is the link to the current py_unicode documentation:
http://docs.python.org/dev/c-api/unicode.html

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1044479
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3001] RLock's are SLOW

2008-06-21 Thread sebastian serrano

sebastian serrano [EMAIL PROTECTED] added the comment:

Running with python -O the timing gets a little closer between Lock and
RLock. This code won't be easy to improve in performance. 
The heaviest call is current_thread(), used at lines:
117:me = current_thread()
137:if self.__owner is not current_thread():

and only consist on:
788: def current_thread():
789: try:
790: return _active[_get_ident()]
791: except KeyError:
792: ##print current_thread(): no current thread for, _get_ident()
793: return _DummyThread()

Simple profiler dump:
$../python-trunk/python -O rlock.py 
time Lock 0.720541000366
time RLock 4.90231084824
 44 function calls in 0.982 CPU seconds

   Ordered by: internal time, call count

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   100.3040.0000.3900.000 threading.py:116(acquire)
   100.2780.0000.3600.000 threading.py:136(release)
10.2320.2320.9820.982 rlock.py:27(testRLock)
   200.1680.0000.1680.000
threading.py:788(current_thread)
10.0000.0000.0000.000 threading.py:103(__init__)
10.0000.0000.0000.000 threading.py:98(RLock)
10.0000.0000.0000.000 threading.py:76(__init__)
00.000 0.000  profile:0(profiler)

--
nosy: +sserrano

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3001
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1817] module-cgi: handling GET and POST together

2008-06-21 Thread Guido van Rossum

Guido van Rossum [EMAIL PROTECTED] added the comment:

Thanks for your contribution!

To get this commmitted, please draw the attention of someone else on
python-dev (or if you're an IRC person try #python-dev at freenote,
IIRC).  I'd recommend moving the tests into the existing test_cgi.py.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1817
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1491] BaseHTTPServer incorrectly implements response code 100

2008-06-21 Thread Neil Muller

Neil Muller [EMAIL PROTECTED] added the comment:

The attached patch is against recent svn (r64442), and adds samwyse's
refactoring of the class. The test for server responses is made less
restrictive when the request isn't HTTP/1.1.

--
nosy: +Neil Muller
Added file: http://bugs.python.org/file10684/BaseHTTPServer_continue_2.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1491
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2118] smtplib.SMTP() raises socket.error rather than SMTPConnectError

2008-06-21 Thread Rodolpho Eckhardt

Rodolpho Eckhardt [EMAIL PROTECTED] added the comment:

Verified Werneck's patch and it also works on 2.6 and 3.0.

However, the previous code used to present a friendly message about
non-numeric ports: socket.error: nonnumeric port and now it raises
ValueError: invalid literal for int() with base 10.

Should it be changed to inform that the exception is due to a
non-numeric port? (Just wrap int(port) with a try and change the raised
exception)

--
nosy: +rodolpho
versions: +Python 2.6, Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2118
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2776] urllib2.urlopen() gets confused with path with // in it

2008-06-21 Thread Adrianna Pinska

Adrianna Pinska [EMAIL PROTECTED] added the comment:

I have written a test to go with my patch.

Added file: http://bugs.python.org/file10685/doubleslash_test.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2776
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2683] subprocess.Popen.communicate takes bytes, not str

2008-06-21 Thread Martin v. Löwis

Changes by Martin v. Löwis [EMAIL PROTECTED]:


___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2683] subprocess.Popen.communicate takes bytes, not str

2008-06-21 Thread admin

admin [EMAIL PROTECTED] added the comment:

What is wrong? Documentation or method?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3162] ssl.SSLSocket implements methods that are overriden by socket.socket.__init__ and methods with incorrect names.

2008-06-21 Thread Simon Cross

New submission from Simon Cross [EMAIL PROTECTED]:

It appears that ssl.SSLSocket attempts to override some of the methods
socket.socket delegates to the underlying _socket.socket methods.
However, this overriding fails because socket.socket.__init__ replaces
all the methods mentioned in _delegate_methods.

These methods are: recv, recvfrom, recv_into, recvfrom_into, send and
sendto.

ssl.SSLSocket implements recv and send. Neither of these overrides will
actually work.  ssl.SSLSocket also implements recv_from and send_to
which seem to be attempts to override recvfrom and sendto.

In the Py3k branch it looks like the overriding done by
socket.socket.__init__ is gone so that these methods are now potentially
overridable. This could potentially be emulated in trunk by checking for
the methods using hasattr(...) before overriding them.

I'm happy to create patches which fix the method names and clean up the
methods on both branches and add tests. I just want to check that I have
an accurate picture of what's needed before starting on them.

--
components: Library (Lib)
messages: 68517
nosy: hodgestar
severity: normal
status: open
title: ssl.SSLSocket implements methods that are overriden by 
socket.socket.__init__ and methods with incorrect names.
versions: Python 2.6, Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3155] Python should expose a pthread_cond_timedwait API for threading

2008-06-21 Thread Adam Olsen

Changes by Adam Olsen [EMAIL PROTECTED]:


--
nosy: +Rhamphoryncus

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3155
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1044479] docs for Py_UNICODE are wrong

2008-06-21 Thread Facundo Batista

Facundo Batista [EMAIL PROTECTED] added the comment:

Thanks Thomas and Manuel!

--
nosy: +facundobatista
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1044479
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >