Re: non-blocking IO EAGAIN on write

2010-07-27 Thread Lawrence D'Oliveiro
In message roy-8a46b6.07250924072...@news.panix.com, Roy Smith wrote:

 Consider, for example, a write on a TCP connection.  You are sitting in
 a select(), when the other side closes the connection.  The select()
 should return, and the write should then immediately fail.

Remember that select can return 3 different sets of file objects. I’ve yet 
to see a use for the third one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are those features still the same?

2010-07-27 Thread Lawrence D'Oliveiro
In message i2gujh$sl...@news.eternal-september.org, francogrex wrote:

 By the way Peter Norvig is not biased, he works for Google research and is
 a supporter of programming in any language, especially in Python.

Bias doesn’t have to be a conscious thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python terminology on classes

2010-07-27 Thread Bruno Desthuilliers

Peng Yu a écrit :

Hi

I'm still kind of confused about the terminology on classes in python.

Could you please let me know what the equivalent terms for the
following C++ terms?


C++ and Python having very different semantics and object models, 
there's not necessarily a straight one to one mapping.




constructor


Python uses a smalltalk-like 2 phases instanciation / initialisation 
scheme. First the proper construction (__new__) is called with the 
class object as first argument, and it must return an unintialised 
instance of the class. Then the initialiser (__init__) is called on this 
instance.


Now one usually only implements the initialiser, as the default 
object.__new__ method does what you would expect, so you'll often see 
people qualifying __init__ as the constructor.



destructor


Python has no real destructor. You can implement a __del__ method that 
will _eventually_ be called before the instance gets garbage-collected, 
but you'd rather not rely on it. Also, implementing this method will 
prevent cycle detection.



member function


= method.

Note that Python's methods are really thin wrappers around function 
objects that are attributes of the class object. You'll find more on 
this here:


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


member variable


= Attribute


virtual member function


All Python's methods are virtual.


function


= function !-)

Note that in Python, functions and classes are objects.


I think that C++ function is equivalent to python function and C++
member function is equivalent to python method. But I couldn't
locate where the original definitions of the corresponding python
terms in the manual as these term appear many times. Could you please
point me where to look for the definition of these python
corresponding terms?


You just cannot directly translate C++ into Python, and while there are 
similarities trying to write C++ in Python will not get you very far.


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


Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Bruno Desthuilliers

Ethan Furman a écrit :

Bruno Desthuilliers wrote:

Duncan Booth a écrit :

(snip)

Or you could create the default as a class attribute 


from the OP:

I have a class (FuncDesigner oofun) that has no attribute size, but
it is overloaded in __getattr__, so if someone invokes
myObject.size, it is generated (as another oofun) and connected to
myObject as attribute.


so this solution won't obviously work in this case !-)

Also and FWIW, I wouldn't advocate this solution if the default 
class attribute is of a mutable type.


Well, it is Monday, so I may be missing something obvious, but what is 
the effective difference between these two solutions?



Now it's Tuesday !-)


Ok, let's see:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
 class Foo(object):
... whatever = Foo()
...
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 2, in Foo
NameError: name 'Foo' is not defined

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


Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Bruno Desthuilliers

Bruno Desthuilliers a écrit :

Ethan Furman a écrit :

Bruno Desthuilliers wrote:

Duncan Booth a écrit :

(snip)

Or you could create the default as a class attribute 


from the OP:

I have a class (FuncDesigner oofun) that has no attribute size, but
it is overloaded in __getattr__, so if someone invokes
myObject.size, it is generated (as another oofun) and connected to
myObject as attribute.


so this solution won't obviously work in this case !-)

Also and FWIW, I wouldn't advocate this solution if the default 
class attribute is of a mutable type.


Well, it is Monday, so I may be missing something obvious, but what is 
the effective difference between these two solutions?




If you meant what is the difference between creating the whatever 
attribute with a default value in the initializer and creating it on 
demand in the __getattr__ hook, the main difference is that in the 
first case, the instance is garanteed to have this attribute, so you get 
rid of hasattr checks (and the unwanted side effects) or, worse, 
direct check of the instance __dict__. Except for a couple of corner 
case, client code shouldn't have to worry about this kind of things - 
this breaks encapsulation.





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


Re: Personal archive tool, looking for suggestions on improving the code

2010-07-27 Thread Peter Otten
mo reina wrote:

 i've written a tool in python where you enter a title, content, then
 tags, and the entry is then saved in a pickle file. it was mainly
 designed for copy-paste functionality (you spot a piece of code you
 like on the net, copy it, and paste it into the program), not really
 for handwritten content, though it does that with no problem.
 
 i mainly did it because i'm always scanning through my pdf files,
 books, or the net for some coding example of solution that i'd already
 seen before, and it just seemed logical to have something where you
 could just put the content in, give it a title and tags, and just look
 it up whenever you needed to.
 
 i realize there are sites online that handle this ex.
 http://snippets.dzone.com, but i'm not always online when i code. i also
 admit that i didn't really look to see if anyone had written a desktop
 app, the project seemed like a fun thing to do so here i am.
 
 it wasn't designed with millions of entries in mind, so i just use a
 pickle file to serialize the data instead of one of the database APIs.
 the query is also very basic, only title and tags and no ranking based
 on the query.
 
 there is an issue that i can't figure out, when you are at the list of
 entries there's a try, except clause where it tries to catch a valid
 index (integer). if you enter an inavlid integer, it will ask you to
 enter a valid one, but it doesn't seem to be able to assign it to the
 variable. if you enter a valid integer straightaway, there are no
 problems and the entry will display.
 
 anyway let me know what you guys think. this is coded for python3.

 def choices(list_result):
 '''takes a list of objects and returns the index of the selected
 object'''
 os.system('clear')
 index = 0
 for entry in list_result:
 print('{}. {}'.format(index, entry.title))
 index += 1
 try:
 choice = int(input('\nEnter choice: '))
 return choice
 except:
 pause = input('\nplease enter a valid choice')
 choices(list_result)

When the exception is triggered you call choices() recursively but discard 
the result. Therefore you get Python's default, None, which is not a valid 
index. Change the last line to

return choices(list_result)

for a minimal fix. However, I suggest that you use a while loop instead of 
the recursion:

def choices(list_result):
while True:
os.system('clear')
for index, entry in enumerate(list_result):
print('{}. {}'.format(index, entry.title))
try:
choice = int(input('\nEnter choice: '))
if 0 = choice  len(list_result):
return choice
except ValueError:
pass
input('\nplease enter a valid choice')

I've also added a test for the integer range and replaced the bare except 
with a more specific one. I recommend that you never use bare excepts 
because they can hide unexpected exceptions and lead to nasty bugs.

You should also remove the recursive call of main(). Its only effect is that 
when you enter an invalid choice twice you will have to enter 5 twice to 
really exit your script.

Peter


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


Re: Checking that 2 pdf are identical (md5 a solution?)

2010-07-27 Thread Peter Otten
rlevesque wrote:

 On Jul 24, 1:34 pm, Peter Otten __pete...@web.de wrote:
 rlevesque wrote:
  Unfortunately there is an other pair of values that does not match and
  it is not obvious to me how to exclude it (as is done with the  /
  CreationDate pair).
  and the pdf document is created using reportLab.

 I dug into the reportlab source and in

 reportlab/rl_config.py

 found the line

 invariant=  0   #produces
 repeatable,identical PDFs with same timestamp info (for regression
 testing)

 I suggest that you edit that file or add

 from reportlab import rl_config
 rl_config.invariant = True

 to your code.

 Peter
 
 WOW!! You are good!
 Your suggested solution works perfectly.
 
 Given your expertise I will not be able to 'repay' you by helping on
 Python problems but if you ever need help with SPSS related problems I
 will be pleased to provide the assistance you need.
 (I am the author of SPSS Programming and Data Management published
 by SPSS Inc. (an IBM company))

Relax! Assistance on c.l.py is free as in beer ;) If you feel you have to 
give something back pick a question you can answer, doesn't matter who's 
asking. Given that I can't answer the majority of questions posted here 
chances are that I learn something from your response, too.

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


Re: Sorting a list created from a parsed xml message

2010-07-27 Thread kak...@gmail.com
On Jul 22, 12:56 pm, Thomas Jollans tho...@jollans.com wrote:
 On 07/21/2010 03:38 PM, kak...@gmail.com wrote:



  On Jul 21, 9:04 am, kak...@gmail.com kak...@gmail.com wrote:
  On Jul 21, 8:58 am, Stefan Behnel stefan...@behnel.de wrote:

  kak...@gmail.com, 21.07.2010 14:36:

  From the subject of my message it's clear that i get an xml message
  from a socket,

  Not at all, but now that you say it...

  i parse it and the result is a list like the one that
  follows:
  ID_Col
  4    Server        ak              ip      OFFLINE

  29      Server     and2    ip      OFFLINE

  5    Proxy         l34e         ip OFFLINE

  6            Proxy         barc            ip      ONLINE

  41           Proxy         proxy-2         ip      ONLINE

  53           Server        server-4        ip      ONLINE

  52           Server        server-3        ip      ONLINE

  Doesn't look like a Python list to me...

  What i want is to print this list sorted by ID_Col?
  Any Suggestions?

  Assuming that the above is supposed to represent a list of tuples, you can
  use the .sort() method on the list and pass operator.itemgetter(0) as 
  'key'
  argument (see the sort() method and the operator module).

  Stefan

  No it is not a Python list at all. This the way i print the parsed
  items 'like a list'.
  But i want them to be sorted.

  Well i did this:

  SortedServers = []

  for session in sessions:
      for IP in session.getElementsByTagName(ipAddress):
           for iphn in session.getElementsByTagName(hostName):
                tempTuple = session.getAttribute(id),
  session.getAttribute(type), iphn.childNodes[0].data,
  IP.childNodes[0].data, session.getAttribute(status)

 Please try to persuade your mail client to not mess up python code, if
 you could. It would make this *so* much easier to read



                SortedServers.append(tempTuple)

  Sorted = sorted(SortedServers, key=lambda id: SortedServers[0])

 Anyway, let's look at that key function of yours:

 key=lambda id: SortedServers[0]

 translated to traditional function syntax:

 def key(id):
     return SortedServers[0]

 No matter which item sorted() examines, the key it sorts by is always
 the same (the first item of the WHOLE LIST).
 You want something more like this:

 def key(row):
     return row[0]

 ergo, what you want, all in all, is either of these:

 Sorted = sorted(SortedServers, key=(lambda row: row[0])) # option 1
 SortedServers.sort(key=(lambda row: row[0]))             # option 2

 option 2, the in-place sort, might be faster.

 (and, as Stefan noted, as you probably want a numeric sort, you'll want
 your key to be an int)

  for item in Sorted:
       print item

  but the list is still unsorted and with u' in front of each item

  (u'4', u'Server', u'aika74', u'ip', u'OFFLINE')
  (u'29', u'Server', u'ando', u'ip2', u'OFFLINE')

  How do i remove the u'

  Antonis



Thank you so much for your detailed response!

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


parsing different xml messages

2010-07-27 Thread kak...@gmail.com
Hello,
I receive the following different Xml Messages from a socket:

p_control_message serverIP=server-2 xmlns=http://test.com/pt;

  cmdReply

sessionList

  session

id5a62ded/id

subscriberId101/subscriberId

subscriberNameAngie/subscriberName

presenceonline/presence

note/

ipAddressSome IP/ipAddress

/session

/sessionList

  /cmdReply

/p_control_message


p_control_message xmlns=http://test.com/pt;

  cmd

systemMessage serverId=50 type=CRITICAL

  messageServer server-1 is going down for redeploy!/message

/systemMessage

  /cmd

/pttv_control_message

Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?

Thanks

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


Re: How to capture all the environment variables from shell?

2010-07-27 Thread Nobody
On Mon, 26 Jul 2010 21:42:24 -0500, Tim Chase wrote:

 Please! Never export anything from your .bashrc unless you
 really know what you're doing. Almost all exports should be
 done in your .bash_profile
 
 Could you elaborate on your reasoning why (or why-not)?  I've 
 found that my .bash_profile doesn't get evaluated when I crank up 
 another terminal window, while my bashrc does.  Thus I tend to 
 put my exports in my ~/.bashrc so they actually take effect in my 
 shell...

Ideally, whichever program spawns the terminal window should have all of
the environment settings from your ~/.profile (although you may have
to explicitly source it from e.g. ~/.xsession), so it shouldn't be
necessary to export them again.

Using ~/.bashrc is a band-aid in case your desktop session doesn't already
have your environment settings. But it only works for shells (and only for
bash shells, and only for interactive bash shells), while your environment
settings should be available to everything, regardless of whether it was
spawned from an interactive bash shell or from some other program.

Also, if you update environment variables with e.g.:

export PATH=$PATH:/usr/local/bin

any nested shells end up getting multiple updates.

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


Re: Personal archive tool, looking for suggestions on improving the code

2010-07-27 Thread mo reina
On 27 Lug, 10:23, Peter Otten __pete...@web.de wrote:
 mo reina wrote:
  i've written a tool in python where you enter a title, content, then
  tags, and the entry is then saved in a pickle file. it was mainly
  designed for copy-paste functionality (you spot a piece of code you
  like on the net, copy it, and paste it into the program), not really
  for handwritten content, though it does that with no problem.

  i mainly did it because i'm always scanning through my pdf files,
  books, or the net for some coding example of solution that i'd already
  seen before, and it just seemed logical to have something where you
  could just put the content in, give it a title and tags, and just look
  it up whenever you needed to.

  i realize there are sites online that handle this ex.
 http://snippets.dzone.com, but i'm not always online when i code. i also
  admit that i didn't really look to see if anyone had written a desktop
  app, the project seemed like a fun thing to do so here i am.

  it wasn't designed with millions of entries in mind, so i just use a
  pickle file to serialize the data instead of one of the database APIs.
  the query is also very basic, only title and tags and no ranking based
  on the query.

  there is an issue that i can't figure out, when you are at the list of
  entries there's a try, except clause where it tries to catch a valid
  index (integer). if you enter an inavlid integer, it will ask you to
  enter a valid one, but it doesn't seem to be able to assign it to the
  variable. if you enter a valid integer straightaway, there are no
  problems and the entry will display.

  anyway let me know what you guys think. this is coded for python3.
  def choices(list_result):
      '''takes a list of objects and returns the index of the selected
  object'''
      os.system('clear')
      index = 0
      for entry in list_result:
          print('{}. {}'.format(index, entry.title))
          index += 1
      try:
          choice = int(input('\nEnter choice: '))
          return choice
      except:
          pause = input('\nplease enter a valid choice')
          choices(list_result)

 When the exception is triggered you call choices() recursively but discard
 the result. Therefore you get Python's default, None, which is not a valid
 index. Change the last line to

 return choices(list_result)

 for a minimal fix. However, I suggest that you use a while loop instead of
 the recursion:

 def choices(list_result):
     while True:
         os.system('clear')
         for index, entry in enumerate(list_result):
             print('{}. {}'.format(index, entry.title))
         try:
             choice = int(input('\nEnter choice: '))
             if 0 = choice  len(list_result):
                 return choice
         except ValueError:
             pass
         input('\nplease enter a valid choice')

 I've also added a test for the integer range and replaced the bare except
 with a more specific one. I recommend that you never use bare excepts
 because they can hide unexpected exceptions and lead to nasty bugs.

 You should also remove the recursive call of main(). Its only effect is that
 when you enter an invalid choice twice you will have to enter 5 twice to
 really exit your script.

 Peter

hi peter, i noticed the issue you mentioned but don't understand why
they happen.

for example, when the function is called in the case of an exception,
the variable choice is re-assigned to whatever the next input is, so
why is the default None assigned instead?  and what' s the difference
between just calling the function again (the variable list_result
remains unchanged) and using a return statement?

i also don' t understand what happens when main is called recursively,
the variable choice should be re-assigned to whatever the next input
is, and yet it seems that in the first call, after an invalid choice,
it doesn't assign the input to the variable.

thanks for taking the time to post and review the code by the way, i
really appreciate it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel

kak...@gmail.com, 27.07.2010 12:17:

I receive the following different Xml Messages from a socket:


From a bare socket? TCP? UDP? Or what else?



Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?


Use an application level protocol?

Stefan

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


Re: Accumulate function in python

2010-07-27 Thread geremy condra
On Wed, Jul 21, 2010 at 8:17 AM, John Nagle na...@animats.com wrote:
 On 7/19/2010 9:56 AM, dhruvbird wrote:

 On Jul 19, 9:12 pm, Brian Victorhomeusen...@brianhv.org  wrote:

 dhruvbird wrote:

 Having offered this, I don't recall ever seeing reduce used in real
 python code, and explicit iteration is almost always preferred.

 Yes, even I have noticed that reduce is a tad under-used function.

    Yes, I had a use case for it once, but it wasn't worth the trouble.
 map is often useful, but reduce, not so much.

    Python isn't really a functional language.  There's no bias toward
 functional solutions, lambdas aren't very general, and the performance
 isn't any better.  Nor is any concurrency provided by map or reduce.
 So there's no win in trying to develop cute one-liners.

Too bad about the lack of concurrency, would be many places where that
would be nice.

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


newb

2010-07-27 Thread whitey
hi all. am totally new to python and was wondering if there are any 
newsgroups that are there specifically for beginners. i have bought a 
book for $2 called learn to program using python by alan gauld. 
starting to read it but it was written in 2001. presuming that the 
commands and info would still be valid? any websites or books that are a 
must for beginners? any input would be much appreciated...cheers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accumulate function in python

2010-07-27 Thread Stefan Behnel

geremy condra, 27.07.2010 12:54:

On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote:

On 7/19/2010 9:56 AM, dhruvbird wrote:


On Jul 19, 9:12 pm, Brian Victor  wrote:


dhruvbird wrote:



Having offered this, I don't recall ever seeing reduce used in real
python code, and explicit iteration is almost always preferred.


Yes, even I have noticed that reduce is a tad under-used function.


Yes, I had a use case for it once, but it wasn't worth the trouble.
map is often useful, but reduce, not so much.

Python isn't really a functional language.  There's no bias toward
functional solutions, lambdas aren't very general, and the performance
isn't any better.  Nor is any concurrency provided by map or reduce.
So there's no win in trying to develop cute one-liners.


Too bad about the lack of concurrency, would be many places where that
would be nice.


Besides the many places where the current properties match just fine, there 
are some places where concurrency would be helpful. So I wouldn't call it 
lack of concurrency, as that seems to imply that it's a missing feature 
in what both builtins are targeted to provide. Just use one of the 
map-reduce frameworks that are out there if you need concurrency in one way 
or another. Special needs are not what builtins are there for.


Stefan

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


Re: newb

2010-07-27 Thread John Machin
On Jul 27, 9:07 pm, whitey m...@here.com wrote:
 hi all. am totally new to python and was wondering if there are any
 newsgroups that are there specifically for beginners. i have bought a
 book for $2 called learn to program using python by alan gauld.
 starting to read it but it was written in 2001. presuming that the
 commands and info would still be valid? any websites or books that are a
 must for beginners? any input would be much appreciated...cheers

2001 is rather old. Most of what you'll want is on the web. See
http://wiki.python.org/moin/BeginnersGuide
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python styles: why Use spaces around arithmetic operators?

2010-07-27 Thread Roy Smith
In article mailman.1193.1280198148.1673.python-l...@python.org,
 Stephen Hansen me+list/pyt...@ixokai.io wrote:

 PEP8 is a style guide. Parts of style guides are rational judgements and
 decisions based on experience and can certainly be explained or
 justified, but parts are just... personal taste. Style is part rational
 thought and part intuition, and in the latter -- people will disagree
 quite a bit. There's no right or wrong there. There isn't always a
 rationale.

I strongly suggest that ALL Python projects adopt PEP-8.  Here's why.

Style, at one level, doesn't really matter.  Yet, it's something people 
get worked up over.  If you add up all the time people have wasted 
arguing about stupid shit like indenting and where the braces go (in 
languages that have them) and how to spell variable names, we could have 
sent a man to Mars and had time left over to solve P = NP.

I don't agree with PEP-8 100%, but it's perfectly reasonable.  Avoiding 
all that time wasting arguing about trivia like variableName vs 
VariableName vs variable_name more than pays me back for any minor 
arguments I might have with the style.

If everybody in the entire world uses the same style, then as people and 
code move around from project to project, everybody benefits by fitting 
in better.

As the old-time press pythonistas would say, PEP-8 and be there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking that 2 pdf are identical (md5 a solution?)

2010-07-27 Thread Robin Becker

..

repeatable,identical PDFs with same timestamp info (for regression testing)

I suggest that you edit that file or add

from reportlab import rl_config
rl_config.invariant = True

to your code.

Peter


WOW!! You are good!
Your suggested solution works perfectly.

Given your expertise I will not be able to 'repay' you by helping on
Python problems but if you ever need help with SPSS related problems I
will be pleased to provide the assistance you need.
(I am the author of SPSS Programming and Data Management published
by SPSS Inc. (an IBM company))

Regards,

..
if you have any more reportlab related queries you can also get free advice on 
the reportlab mailing list at


http://two.pairlist.net/mailman/listinfo/reportlab-users
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


Re: parsing different xml messages

2010-07-27 Thread kak...@gmail.com
On Jul 27, 6:30 am, Stefan Behnel stefan...@behnel.de wrote:
 kak...@gmail.com, 27.07.2010 12:17:

  I receive the following different Xml Messages from a socket:

  From a bare socket? TCP? UDP? Or what else?

  Which is the best way to make a distinction between them so that every
  time my app receives the one or the other, parse them correctly?

 Use an application level protocol?

 Stefan

From a tcp socket using the twisted framework.
Application level protocol... Such as?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Personal archive tool, looking for suggestions on improving the code

2010-07-27 Thread Peter Otten
mo reina wrote:

 On 27 Lug, 10:23, Peter Otten __pete...@web.de wrote:
 mo reina wrote:
  i've written a tool in python where you enter a title, content, then
  tags, and the entry is then saved in a pickle file. it was mainly
  designed for copy-paste functionality (you spot a piece of code you
  like on the net, copy it, and paste it into the program), not really
  for handwritten content, though it does that with no problem.

  i mainly did it because i'm always scanning through my pdf files,
  books, or the net for some coding example of solution that i'd already
  seen before, and it just seemed logical to have something where you
  could just put the content in, give it a title and tags, and just look
  it up whenever you needed to.

  i realize there are sites online that handle this ex.
 http://snippets.dzone.com, but i'm not always online when i code. i also
  admit that i didn't really look to see if anyone had written a desktop
  app, the project seemed like a fun thing to do so here i am.

  it wasn't designed with millions of entries in mind, so i just use a
  pickle file to serialize the data instead of one of the database APIs.
  the query is also very basic, only title and tags and no ranking based
  on the query.

  there is an issue that i can't figure out, when you are at the list of
  entries there's a try, except clause where it tries to catch a valid
  index (integer). if you enter an inavlid integer, it will ask you to
  enter a valid one, but it doesn't seem to be able to assign it to the
  variable. if you enter a valid integer straightaway, there are no
  problems and the entry will display.

  anyway let me know what you guys think. this is coded for python3.
  def choices(list_result):
  '''takes a list of objects and returns the index of the selected
  object'''
  os.system('clear')
  index = 0
  for entry in list_result:
  print('{}. {}'.format(index, entry.title))
  index += 1
  try:
  choice = int(input('\nEnter choice: '))
  return choice
  except:
  pause = input('\nplease enter a valid choice')
  choices(list_result)

 When the exception is triggered you call choices() recursively but
 discard the result. Therefore you get Python's default, None, which is
 not a valid index. Change the last line to

 return choices(list_result)

 for a minimal fix. However, I suggest that you use a while loop instead
 of the recursion:

 def choices(list_result):
 while True:
 os.system('clear')
 for index, entry in enumerate(list_result):
 print('{}. {}'.format(index, entry.title))
 try:
 choice = int(input('\nEnter choice: '))
 if 0 = choice  len(list_result):
 return choice
 except ValueError:
 pass
 input('\nplease enter a valid choice')

 I've also added a test for the integer range and replaced the bare except
 with a more specific one. I recommend that you never use bare excepts
 because they can hide unexpected exceptions and lead to nasty bugs.

 You should also remove the recursive call of main(). Its only effect is
 that when you enter an invalid choice twice you will have to enter 5
 twice to really exit your script.

 Peter
 
 hi peter, i noticed the issue you mentioned but don't understand why
 they happen.
 
 for example, when the function is called in the case of an exception,
 the variable choice is re-assigned to whatever the next input is, so
 why is the default None assigned instead?  and what' s the difference
 between just calling the function again (the variable list_result
 remains unchanged) and using a return statement?

If you have a function

def f():
return 42

and just call it from another function

def g():
f()

the result of f() is evaluated but immediately discarded. If you want to use 
it inside g() you have to assign it to a variable

def g():
x = f()
y = x * x
print y

and if you want to use it outside g() you can return it. 

def g():
   return f()

For recursion the same rules apply, only with the same function as f and g.
Here's a simple example for you to work out the program flow:

 def r1(n):
... print entering level, n
... if n == 5:
... print limit reached
... print exiting level, n
... print returning 42
... return 42
... else:
... print recursing
... r1(n+1)
... print exiting level, n
... print (implicitly) returning None
...
 r1(0)
entering level 0
recursing
entering level 1
recursing
entering level 2
recursing
entering level 3
recursing
entering level 4
recursing
entering level 5
limit reached
exiting level 5
returning 42
exiting level 4
(implicitly) returning None
exiting level 3
(implicitly) returning None
exiting level 2
(implicitly) returning None
exiting level 1
(implicitly) returning None
exiting level 0
(implicitly) returning None

Try to change r1() to return the value from the innermost call (i. e. 42) to 
the outside world. Once you have understood what is going on you should be 
able to see what's wrong with your 

Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel

kak...@gmail.com, 27.07.2010 13:58:

On Jul 27, 6:30 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 12:17:


I receive the following different Xml Messages from a socket:


  From a bare socket? TCP? UDP? Or what else?


Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?


Use an application level protocol?

Stefan



From a tcp socket using the twisted framework.
Application level protocol... Such as?


Depends on what you *can* use. Do you control the sending side?

Note: giving better details helps others in giving better answers.

Stefan

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


Re: parsing different xml messages

2010-07-27 Thread kak...@gmail.com
On Jul 27, 8:14 am, Stefan Behnel stefan...@behnel.de wrote:
 kak...@gmail.com, 27.07.2010 13:58:



  On Jul 27, 6:30 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 12:17:

  I receive the following different Xml Messages from a socket:

    From a bare socket? TCP? UDP? Or what else?

  Which is the best way to make a distinction between them so that every
  time my app receives the one or the other, parse them correctly?

  Use an application level protocol?

  Stefan

  From a tcp socket using the twisted framework.
  Application level protocol... Such as?

 Depends on what you *can* use. Do you control the sending side?

 Note: giving better details helps others in giving better answers.

 Stefan

Well yes you are right!
I can't control the sending side.
The app i'm writing just accepts incoming xml messages. Like the ones
above.
When i receive a message I parse it and print the information.
I know how to parse both xml messages.
What i want is to distinguish them so that i can trigger the
appropriate parsing method.


A.K.

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


Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel

kak...@gmail.com, 27.07.2010 14:26:

On Jul 27, 8:14 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 13:58:


On Jul 27, 6:30 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 12:17:



I receive the following different Xml Messages from a socket:



   From a bare socket? TCP? UDP? Or what else?



Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?



Use an application level protocol?



 From a tcp socket using the twisted framework.
Application level protocol... Such as?


Depends on what you *can* use. Do you control the sending side?

Note: giving better details helps others in giving better answers.


Well yes you are right!
I can't control the sending side.
The app i'm writing just accepts incoming xml messages. Like the ones
above.
When i receive a message I parse it and print the information.
I know how to parse both xml messages.
What i want is to distinguish them so that i can trigger the
appropriate parsing method.


Do they come in concatenated or one per connection?

Stefan

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


Re: parsing different xml messages

2010-07-27 Thread kak...@gmail.com
On Jul 27, 8:41 am, Stefan Behnel stefan...@behnel.de wrote:
 kak...@gmail.com, 27.07.2010 14:26:



  On Jul 27, 8:14 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 13:58:

  On Jul 27, 6:30 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 12:17:

  I receive the following different Xml Messages from a socket:

     From a bare socket? TCP? UDP? Or what else?

  Which is the best way to make a distinction between them so that every
  time my app receives the one or the other, parse them correctly?

  Use an application level protocol?

   From a tcp socket using the twisted framework.
  Application level protocol... Such as?

  Depends on what you *can* use. Do you control the sending side?

  Note: giving better details helps others in giving better answers.

  Well yes you are right!
  I can't control the sending side.
  The app i'm writing just accepts incoming xml messages. Like the ones
  above.
  When i receive a message I parse it and print the information.
  I know how to parse both xml messages.
  What i want is to distinguish them so that i can trigger the
  appropriate parsing method.

 Do they come in concatenated or one per connection?

 Stefan

one per connection.
-- 
http://mail.python.org/mailman/listinfo/python-list


Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Daniel Fetchinson
Hi folks,

If I'm only interested in linux and windows I know I can do


import os
import platform

if platform.system( ) == 'Linux':
clear = 'clear'
else:
clear = 'cls'

os.system( clear )


or something equivalent using os.name and friends, but was wondering
why there is no platform independent way (i.e. the platform dependence
is taken care of by the python stdlib) of clearing a terminal. Sure,
there are many different terminals and many different operating
systems but in many areas python managed to hide all these
complexities behind a well defined API.

Why was clearing a terminal left out?

Cheers,
Daniel


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


Re: parsing different xml messages

2010-07-27 Thread Stefan Behnel

kak...@gmail.com, 27.07.2010 14:43:

On Jul 27, 8:41 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 14:26:


On Jul 27, 8:14 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 13:58:



On Jul 27, 6:30 am, Stefan Behnel wrote:

kak...@gmail.com, 27.07.2010 12:17:



I receive the following different Xml Messages from a socket:



From a bare socket? TCP? UDP? Or what else?



Which is the best way to make a distinction between them so that every
time my app receives the one or the other, parse them correctly?



Use an application level protocol?



  From a tcp socket using the twisted framework.
Application level protocol... Such as?



Depends on what you *can* use. Do you control the sending side?



Note: giving better details helps others in giving better answers.



Well yes you are right!
I can't control the sending side.
The app i'm writing just accepts incoming xml messages. Like the ones
above.
When i receive a message I parse it and print the information.
I know how to parse both xml messages.
What i want is to distinguish them so that i can trigger the
appropriate parsing method.


Do they come in concatenated or one per connection?

Stefan


one per connection.


Ah, ok, then just parse the message using (c)ElementTree and look at the 
name of the first child below the root node (assuming that both messages 
were supposed to have the same root node, as you may have wanted to 
indicate in your original posting). A dict dispatch to a function or method 
will do just fine.


Stefan

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


Re: parsing different xml messages

2010-07-27 Thread kak...@gmail.com
On Jul 27, 9:06 am, Stefan Behnel stefan...@behnel.de wrote:
 kak...@gmail.com, 27.07.2010 14:43:



  On Jul 27, 8:41 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 14:26:

  On Jul 27, 8:14 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 13:58:

  On Jul 27, 6:30 am, Stefan Behnel wrote:
  kak...@gmail.com, 27.07.2010 12:17:

  I receive the following different Xml Messages from a socket:

      From a bare socket? TCP? UDP? Or what else?

  Which is the best way to make a distinction between them so that every
  time my app receives the one or the other, parse them correctly?

  Use an application level protocol?

    From a tcp socket using the twisted framework.
  Application level protocol... Such as?

  Depends on what you *can* use. Do you control the sending side?

  Note: giving better details helps others in giving better answers.

  Well yes you are right!
  I can't control the sending side.
  The app i'm writing just accepts incoming xml messages. Like the ones
  above.
  When i receive a message I parse it and print the information.
  I know how to parse both xml messages.
  What i want is to distinguish them so that i can trigger the
  appropriate parsing method.

  Do they come in concatenated or one per connection?

  Stefan

  one per connection.

 Ah, ok, then just parse the message using (c)ElementTree and look at the
 name of the first child below the root node (assuming that both messages
 were supposed to have the same root node, as you may have wanted to
 indicate in your original posting). A dict dispatch to a function or method
 will do just fine.

 Stefan

ok that's great, thanks Stefan
i'll try it.

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


Re: newb

2010-07-27 Thread Dave Angel

whitey wrote:
hi all. am totally new to python and was wondering if there are any 
newsgroups that are there specifically for beginners. i have bought a 
book for $2 called learn to program using python by alan gauld. 
starting to read it but it was written in 2001. presuming that the 
commands and info would still be valid? any websites or books that are a 
must for beginners? any input would be much appreciated...cheers


  

Welcome to the forum,

Newsgroup:

Send Tutor mailing list submissions to
tu...@python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org



For an updated Alan Gauld tutorial:
the Learn to Program web site
http://www.alan-g.me.uk/

The python.org website is a wealth of information, and also contains 
links to many other python-oriented sites.


Before installing python, consider whether you want version 2.x or 3.x.  
The language changed a bit at 3.x, and while you're learning, you want a 
tutorial that matches the version you're running.


Easiest way to recognize a particular script as being one or the other 
is if it has a print statement.  print is a statement in version 1.x and 
2.x, and is a function in version 3.  Any recent tutorial will tell you 
which it's targeting, but since version 3 is only a year or so old, 
older tutorials or sample code  might well not mention it.


DaveA

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


Re: Accumulate function in python

2010-07-27 Thread sturlamolden
On 19 Jul, 13:18, dhruvbird dhruvb...@gmail.com wrote:
 Hello,
   I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
   And would like to compute the cumulative sum of all the integers
 from index zero into another array. So for the array above, I should
 get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
   What is the best way (or pythonic way) to get this.

At least for large arrays, this is the kind of task where NumPy will
help.

 import numpy as np
 np.cumsum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])
array([ 0,  1,  3,  4,  5,  5,  5,  7, 10])


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


string manipulation.

2010-07-27 Thread gerardob

I am trying to read an xml using minidom from python library xml.dom

This is the xml file:
-
rm_structure
resources
resource
AB
Capacity100/Capacity
NumberVirtualClasses
2
/NumberVirtualClasses
/resource
/resources
/rm_structure
--
This is the python code:

from xml.dom import minidom
doc= minidom.parse(example.xml)
resources_section = doc.getElementsByTagName('resources')
list_resources = resources_section[0].getElementsByTagName('resource')

for r in list_resources:
name = r.childNodes[0].nodeValue
print name
print len(name)
-
The problem is that the nodeValue stored in the variable 'name' is not AB
(what i want) but instead it is a string that has length of 8 and it seems
it include the tabs and/or other things.
How can i get the string AB without the other stuff?
Thanks.



-- 
View this message in context: 
http://old.nabble.com/string-manipulation.-tp29276755p29276755.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Urrlib2 IncompleteRead error

2010-07-27 Thread dirknbr
I am running urllib2.request and get this response when I do the read.
Any ideas what causes this?

return response.read()
  File C:\Python26\lib\socket.py, line 329, in read
data = self._sock.recv(rbufsize)
  File C:\Python26\lib\httplib.py, line 518, in read
return self._read_chunked(amt)
  File C:\Python26\lib\httplib.py, line 561, in _read_chunked
raise IncompleteRead(''.join(value))
IncompleteRead: IncompleteRead(3235 bytes read)

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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Bruno Desthuilliers

Daniel Fetchinson a écrit :

Hi folks,

If I'm only interested in linux and windows I know I can do


import os
import platform

if platform.system( ) == 'Linux':
clear = 'clear'
else:
clear = 'cls'

os.system( clear )


or something equivalent using os.name and friends, but was wondering
why there is no platform independent way (i.e. the platform dependence
is taken care of by the python stdlib) of clearing a terminal. Sure,
there are many different terminals and many different operating
systems but in many areas python managed to hide all these
complexities behind a well defined API.

Why was clearing a terminal left out?



What you're talking about is a shell, not a terminal (a terminal is a 
physical device). And the shell is not necessarily part of the OS itself 
(there's no shortage of shells for unices / linux systems), so it 
doesn't belong to the os or platform modules.


FWIW, I can't tell for sure since I never used any other shell than 
bash, but I'm not sure your above code is garanteed to work on each and 
any possible unix shell.

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


Check in interpreter if running a debug version of python

2010-07-27 Thread John Reid
Can I check in the interpreter if I am running a debug version of 
python? I don't mean if __debug__ is set, I want to know if python was 
compiled in debug mode.


Thanks,
John.

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


Re: string manipulation.

2010-07-27 Thread Neil Cerutti
On 2010-07-27, gerardob gberbeg...@gmail.com wrote:

 I am trying to read an xml using minidom from python library xml.dom

 This is the xml file:
 -
rm_structure
   resources
   resource
   AB
   Capacity100/Capacity
   NumberVirtualClasses
   2
   /NumberVirtualClasses
   /resource
   /resources
/rm_structure
 --
 This is the python code:
 
 from xml.dom import minidom
 doc= minidom.parse(example.xml)
 resources_section = doc.getElementsByTagName('resources')
 list_resources = resources_section[0].getElementsByTagName('resource')

 for r in list_resources:
   name = r.childNodes[0].nodeValue
 print name
   print len(name)
 -
 The problem is that the nodeValue stored in the variable 'name' is not AB
 (what i want) but instead it is a string that has length of 8 and it seems
 it include the tabs and/or other things.
 How can i get the string AB without the other stuff?

Check out the strip member function.

  name = r.childNodes[0].nodeValue.strip()

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


Re: Check in interpreter if running a debug version of python

2010-07-27 Thread Christian Heimes
 Can I check in the interpreter if I am running a debug version of 
 python? I don't mean if __debug__ is set, I want to know if python was 
 compiled in debug mode.

Python has multiple flavors of debug builds. hasattr(sys,
gettotalrefcount) is only available if Py_REF_DEBUG is enabled. This
should be sufficient to detect the most used debug variant.

Christian


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


Re: string manipulation.

2010-07-27 Thread Mark Tolonen


gerardob gberbeg...@gmail.com wrote in message 
news:29276755.p...@talk.nabble.com...


I am trying to read an xml using minidom from python library xml.dom

This is the xml file:
-
rm_structure
resources
resource
AB
Capacity100/Capacity
NumberVirtualClasses
2
/NumberVirtualClasses
/resource
/resources
/rm_structure
--
This is the python code:

from xml.dom import minidom
doc= minidom.parse(example.xml)
resources_section = doc.getElementsByTagName('resources')
list_resources = resources_section[0].getElementsByTagName('resource')

for r in list_resources:
name = r.childNodes[0].nodeValue
   print name
print len(name)
-
The problem is that the nodeValue stored in the variable 'name' is not 
AB

(what i want) but instead it is a string that has length of 8 and it seems
it include the tabs and/or other things.
How can i get the string AB without the other stuff?
Thanks.


Whitespace in XML is significant.  If the file was:

   rm_structure
   resources
   resourceABCapacity100/Capacity
   NumberVirtualClasses2/NumberVirtualClasses
   /resource
   /resources
   /rm_structure

You would just read 'AB'.  If you don't control the XML file, then:

   print name.strip()

will remove leading and trailing whitespace.

-Mark


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


Best practice way to open files in Python 2.6+?

2010-07-27 Thread python
What is the best practice way to open files in Python 2.6+

It looks like there are at least 3 different ways to open files:
- built-in open()
- io.open()
- codecs.open()
It seems like io.open() combines the best of the built-in open()
and the codecs open(). Am I missing any obvious drawbacks to
using io.open() except for backwards compatibility?

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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Grant Edwards
On 2010-07-27, Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 
wrote:
 Daniel Fetchinson a ?crit :
 Hi folks,
 
 If I'm only interested in linux and windows I know I can do
 
 
 import os
 import platform
 
 if platform.system( ) == 'Linux':
 clear = 'clear'
 else:
 clear = 'cls'
 
 os.system( clear )
 
 
 or something equivalent using os.name and friends, but was wondering
 why there is no platform independent way (i.e. the platform dependence
 is taken care of by the python stdlib) of clearing a terminal. Sure,
 there are many different terminals and many different operating
 systems but in many areas python managed to hide all these
 complexities behind a well defined API.
 
 Why was clearing a terminal left out?
 

 What you're talking about is a shell, not a terminal (a terminal is a 
 physical device).

No, what he's talking about is clearing a terminal (or a terminal
emulator).  They both work the same, the only difference is whether
the terminal software is running on dedicated hardware or on
general-purpose hardware.

 And the shell is not necessarily part of the OS itself 
 (there's no shortage of shells for unices / linux systems), so it 
 doesn't belong to the os or platform modules.

True, but clearing a terminal or terminal emulator has nothing to do
with the shell.  It's done using an in-band control/escape sequence
that's indepedent of the shell being used. His example accomplishes
this using an executable named 'clear' which knows how to use
terminfo/termcap (I forget which one) to send the proper escape
sequence to the terminal.

 FWIW, I can't tell for sure since I never used any other shell than 
 bash, but I'm not sure your above code is garanteed to work on each
 and any possible unix shell.

Again, the shell is irrelevent.

-- 
Grant Edwards   grant.b.edwardsYow! Zippy's brain cells
  at   are straining to bridge
  gmail.comsynapses ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread python
Windows: How can I detect whether a Python app/script is running
in console/GUI mode? By app I mean a script compiled to an exe
via py2exe or similar.

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


Re: Check in interpreter if running a debug version of python

2010-07-27 Thread Brian Curtin
On Tue, Jul 27, 2010 at 09:06, John Reid j.r...@mail.cryst.bbk.ac.ukwrote:

 Can I check in the interpreter if I am running a debug version of python? I
 don't mean if __debug__ is set, I want to know if python was compiled in
 debug mode.

 Thanks,
 John.


Starting with Python 2.7 and 3.2 you can do this:

 sysconfig.get_config_var(Py_DEBUG)
1

(returns None if the var doesn't exist)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Bruno Desthuilliers

Grant Edwards a écrit :

On 2010-07-27, Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 
wrote:

Daniel Fetchinson a ?crit :

(snip)

Why was clearing a terminal left out?

What you're talking about is a shell, not a terminal (a terminal is a 
physical device).


No, what he's talking about is clearing a terminal (or a terminal
emulator).  They both work the same, the only difference is whether
the terminal software is running on dedicated hardware or on
general-purpose hardware.


(snip)

I stand corrected.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Phil Thompson
On Tue, 27 Jul 2010 16:02:23 +0200, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:
 Daniel Fetchinson a écrit :
 Hi folks,
 
 If I'm only interested in linux and windows I know I can do
 
 
 import os
 import platform
 
 if platform.system( ) == 'Linux':
 clear = 'clear'
 else:
 clear = 'cls'
 
 os.system( clear )
 
 
 or something equivalent using os.name and friends, but was wondering
 why there is no platform independent way (i.e. the platform dependence
 is taken care of by the python stdlib) of clearing a terminal. Sure,
 there are many different terminals and many different operating
 systems but in many areas python managed to hide all these
 complexities behind a well defined API.
 
 Why was clearing a terminal left out?
 
 
 What you're talking about is a shell, not a terminal (a terminal is a 
 physical device). And the shell is not necessarily part of the OS itself

 (there's no shortage of shells for unices / linux systems), so it 
 doesn't belong to the os or platform modules.
 
 FWIW, I can't tell for sure since I never used any other shell than 
 bash, but I'm not sure your above code is garanteed to work on each and 
 any possible unix shell.

Sorry, but that is completely wrong - the shell is irrelevant.

clear is just a normal command line program that queries the
termcap/terminfo database (possibly via the curses library) for the
terminal specific sequence of characters that will clear the screen. It
then writes those characters to stdout. The terminal, or (more usually
these days) terminal emulator, then interprets those characters and takes
the appropriate action.

I'm not sure what the POSIX status of the clear command is, but I'd be
surprised if it wasn't present on a UNIX/Linux system of any vintage.

Phil

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


Re: Personal archive tool, looking for suggestions on improving the code

2010-07-27 Thread mo reina
On Jul 27, 2:06 pm, Peter Otten __pete...@web.de wrote:
 mo reina wrote:
  On 27 Lug, 10:23, Peter Otten __pete...@web.de wrote:
  mo reina wrote:
   i've written a tool in python where you enter a title, content, then
   tags, and the entry is then saved in a pickle file. it was mainly
   designed for copy-paste functionality (you spot a piece of code you
   like on the net, copy it, and paste it into the program), not really
   for handwritten content, though it does that with no problem.

   i mainly did it because i'm always scanning through my pdf files,
   books, or the net for some coding example of solution that i'd already
   seen before, and it just seemed logical to have something where you
   could just put the content in, give it a title and tags, and just look
   it up whenever you needed to.

   i realize there are sites online that handle this ex.
  http://snippets.dzone.com, but i'm not always online when i code. i also
   admit that i didn't really look to see if anyone had written a desktop
   app, the project seemed like a fun thing to do so here i am.

   it wasn't designed with millions of entries in mind, so i just use a
   pickle file to serialize the data instead of one of the database APIs.
   the query is also very basic, only title and tags and no ranking based
   on the query.

   there is an issue that i can't figure out, when you are at the list of
   entries there's a try, except clause where it tries to catch a valid
   index (integer). if you enter an inavlid integer, it will ask you to
   enter a valid one, but it doesn't seem to be able to assign it to the
   variable. if you enter a valid integer straightaway, there are no
   problems and the entry will display.

   anyway let me know what you guys think. this is coded for python3.
   def choices(list_result):
   '''takes a list of objects and returns the index of the selected
   object'''
   os.system('clear')
   index = 0
   for entry in list_result:
   print('{}. {}'.format(index, entry.title))
   index += 1
   try:
   choice = int(input('\nEnter choice: '))
   return choice
   except:
   pause = input('\nplease enter a valid choice')
   choices(list_result)

  When the exception is triggered you call choices() recursively but
  discard the result. Therefore you get Python's default, None, which is
  not a valid index. Change the last line to

  return choices(list_result)

  for a minimal fix. However, I suggest that you use a while loop instead
  of the recursion:

  def choices(list_result):
  while True:
  os.system('clear')
  for index, entry in enumerate(list_result):
  print('{}. {}'.format(index, entry.title))
  try:
  choice = int(input('\nEnter choice: '))
  if 0 = choice  len(list_result):
  return choice
  except ValueError:
  pass
  input('\nplease enter a valid choice')

  I've also added a test for the integer range and replaced the bare except
  with a more specific one. I recommend that you never use bare excepts
  because they can hide unexpected exceptions and lead to nasty bugs.

  You should also remove the recursive call of main(). Its only effect is
  that when you enter an invalid choice twice you will have to enter 5
  twice to really exit your script.

  Peter

  hi peter, i noticed the issue you mentioned but don't understand why
  they happen.

  for example, when the function is called in the case of an exception,
  the variable choice is re-assigned to whatever the next input is, so
  why is the default None assigned instead?  and what' s the difference
  between just calling the function again (the variable list_result
  remains unchanged) and using a return statement?

 If you have a function

 def f():
     return 42

 and just call it from another function

 def g():
     f()

 the result of f() is evaluated but immediately discarded. If you want to use
 it inside g() you have to assign it to a variable

 def g():
     x = f()
     y = x * x
     print y

 and if you want to use it outside g() you can return it.

 def g():
    return f()

 For recursion the same rules apply, only with the same function as f and g.
 Here's a simple example for you to work out the program flow:

  def r1(n):

 ...     print entering level, n
 ...     if n == 5:
 ...             print limit reached
 ...             print exiting level, n
 ...             print returning 42
 ...             return 42
 ...     else:
 ...             print recursing
 ...             r1(n+1)
 ...     print exiting level, n
 ...     print (implicitly) returning None
 ... r1(0)

 entering level 0
 recursing
 entering level 1
 recursing
 entering level 2
 recursing
 entering level 3
 recursing
 entering level 4
 recursing
 entering level 5
 limit reached
 exiting level 5
 returning 42
 exiting level 4
 (implicitly) returning None
 exiting level 3
 (implicitly) returning None
 exiting level 2
 (implicitly) returning None
 exiting level 1
 (implicitly) returning None
 exiting level 0
 (implicitly) returning None

 Try to change 

Re: Best practice way to open files in Python 2.6+?

2010-07-27 Thread Brian Curtin
On Tue, Jul 27, 2010 at 09:33, pyt...@bdurham.com wrote:

 What is the best practice way to open files in Python 2.6+

 It looks like there are at least 3 different ways to open files:
 - built-in open()
 - io.open()
 - codecs.open()

 It seems like io.open() combines the best of the built-in open() and the
 codecs open(). Am I missing any obvious drawbacks to using io.open() except
 for backwards compatibility?

 Thank you,
 Malcolm


As an FYI, the builtin open() uses io.open() on at least 3.1 (maybe also
3.0, don't know). I don't know your use cases or what you get or don't get
from any of those options, but the future is io.open.

 io.open is open
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best practice way to open files in Python 2.6+?

2010-07-27 Thread Antoine Pitrou
On Tue, 27 Jul 2010 10:33:06 -0400
pyt...@bdurham.com wrote:
 What is the best practice way to open files in Python 2.6+
 
 It looks like there are at least 3 different ways to open files:
 - built-in open()
 - io.open()
 - codecs.open()
 It seems like io.open() combines the best of the built-in open()
 and the codecs open(). Am I missing any obvious drawbacks to
 using io.open() except for backwards compatibility?

io.open() is quite slow in 2.6, although the performance issues are
fixed in 2.7 (and in 3.1).

io.open() is much stricter in what types it accepts and emits. Files
opened in text mode, for example, will return unicode strings when
reading and will only accept unicode strings for write().
(similarly, files opened in binary mode will only accept bytestrings
for write())

Regards

Antoine.


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


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Brian Curtin
On Tue, Jul 27, 2010 at 09:36, pyt...@bdurham.com wrote:

 Windows: How can I detect whether a Python app/script is running in
 console/GUI mode? By app I mean a script compiled to an exe via py2exe or
 similar.

 Thank you,
 Malcolm


I don't remember much about py2exe, but you could check if
``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs)
or just python.exe (regular console).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best practice way to open files in Python 2.6+?

2010-07-27 Thread python
Brian,

 As an FYI, the builtin open() uses io.open() on at least 3.1
(maybe also 3.0, don't know). I don't know your use cases or 
what you get or don't get from any of those options, but the
future is io.open.

  io.open is open
 True

Under Python 2.6.4 (Windows), io.open is open returns False.
Retrieving help() on io.open and open() reinforces that these are
2 different implementations of open.

My use case is reading and writing UTF-8 text files with
universal newline support. I believe that the following io.open()
parameter list is what I should be using:

# mode set to 'rt' (read) or 'wt' (write)
io.open( file, mode, encoding='utf-8', errors='ignore',
newline=None )

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


Re: Best practice way to open files in Python 2.6+?

2010-07-27 Thread Brian Curtin
On Tue, Jul 27, 2010 at 09:59, pyt...@bdurham.com wrote:

 Brian,

  Under Python 2.6.4 (Windows), io.open is open returns False. Retrieving
 help() on io.open and open() reinforces that these are 2 different
 implementations of open.

 My use case is reading and writing UTF-8 text files with universal newline
 support. I believe that the following io.open() parameter list is what I
 should be using:

 # mode set to 'rt' (read) or 'wt' (write)
 io.open( file, mode, encoding='utf-8', errors='ignore', newline=None )

 Malcolm


Precisely. I was just showing that in 3.x they are the same because one uses
the other, and that reason might be enough for you to consider io.open.

Your usage of io.open looks fine to me. If it works for you, keep doing it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Check in interpreter if running a debug version of python

2010-07-27 Thread Christian Heimes
 Starting with Python 2.7 and 3.2 you can do this:
 
 sysconfig.get_config_var(Py_DEBUG)
 1
 
 (returns None if the var doesn't exist)

IIRC sysconfig.get_config_var() still depends on parsing the pyconfig.h
file. This won't work on Windows because we are using project and config
settings of VisualStudio.

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


multicpu bzip2 using os.system or queue using python script

2010-07-27 Thread harijay
I want to quickly bzip2 compress several hundred gigabytes of data
using my 8 core , 16 GB ram workstation.
Currently I am using a simple python script to compress a whole
directory tree using bzip2 and a system call coupled to an os.walk
call.

I see that the bzip2 only uses a single cpu while the other cpus
remain relatively idle.

I am a newbie in queue and threaded processes . But I am wondering how
I can implement this such that I can have four bzip2 running threads
(actually I guess os.system threads ), each using probably their own
cpu , that deplete files from a queue as they bzip them.


Thanks for your suggestions in advance

hari


My single thread script is pasted here .

import os
import sys


for roots, dirlist , filelist in os.walk(os.curdir):
for file in [os.path.join(roots,filegot) for filegot in filelist]:
if bz2 not in file:
print Compressing %s % (file)
os.system(bzip2 %s % file)
print :DONE


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


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Tim Golden

On 27/07/2010 15:58, Brian Curtin wrote:

On Tue, Jul 27, 2010 at 09:36,pyt...@bdurham.com  wrote:


Windows: How can I detect whether a Python app/script is running in
console/GUI mode? By app I mean a script compiled to an exe via py2exe or
similar.

Thank you,
Malcolm



I don't remember much about py2exe, but you could check if
``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs)
or just python.exe (regular console).


Don't know whether it's foolproof, but I suspect that
checking whether win32console.GetConsoleWindow ()
returns zero is probably not a bad approach.

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


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread Emile van Sebille

On 7/27/2010 7:36 AM pyt...@bdurham.com said...

Windows: How can I detect whether a Python app/script is running
in console/GUI mode? By app I mean a script compiled to an exe
via py2exe or similar.



Once you've got an exe, you'll need to know the name you're looking for. 
 There are several utilities available -- I use pslist from 
sysinternals, but there are others out there like process explorer, WMIC 
or tasklist.  You could translate the VB found at 
http://support.microsoft.com/kb/187913 and use win32.  You could program 
a pid file into your exe and check that.


One cheap trick is to create a file and keep it open while your process 
runs.  From the outside, if the file is missing or you can erase the 
file, you're process isn't active.  This relies on windows requiring 
exclusive access to delete a file which it does, and doesn't rely on the 
presence of a particular windows version or installation of a third 
party utility.


HTH,

Emile


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


Re: Personal archive tool, looking for suggestions on improving the code

2010-07-27 Thread John Bokma
mo reina urban.yoga.journ...@gmail.com writes:

 i mainly did it because i'm always scanning through my pdf files,
 books, or the net for some coding example of solution that i'd already
 seen before, and it just seemed logical to have something where you
 could just put the content in, give it a title and tags, and just look
 it up whenever you needed to.

Ages ago I wrote something like this in Perl, but now I use a local
install of MediaWiki to keep notes, interesting links, code snippets,
etc. One of the advantages is that I can reach it from each computer
connected to my LAN, even virtual ones.

-- 
John Bokma   j3b

Hacking  Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl  Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Urrlib2 IncompleteRead error

2010-07-27 Thread Nitin Pawar
Hi,

Check if the webpage you are trying to access is redirecting the page to
some other page?
or the timeout is too less for the request to finish


Thanks,
Nitin

On Tue, Jul 27, 2010 at 7:30 PM, dirknbr dirk...@gmail.com wrote:

 I am running urllib2.request and get this response when I do the read.
 Any ideas what causes this?

 return response.read()
  File C:\Python26\lib\socket.py, line 329, in read
data = self._sock.recv(rbufsize)
  File C:\Python26\lib\httplib.py, line 518, in read
return self._read_chunked(amt)
  File C:\Python26\lib\httplib.py, line 561, in _read_chunked
raise IncompleteRead(''.join(value))
 IncompleteRead: IncompleteRead(3235 bytes read)

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




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


Re: Urrlib2 IncompleteRead error

2010-07-27 Thread Dirk Nachbar
Thanks, I don't think it's redirecting, how can I increase the timeout?

On 27 July 2010 16:56, Nitin Pawar nitinpawar...@gmail.com wrote:

 Hi,

 Check if the webpage you are trying to access is redirecting the page to
 some other page?
 or the timeout is too less for the request to finish


 Thanks,
 Nitin

 On Tue, Jul 27, 2010 at 7:30 PM, dirknbr dirk...@gmail.com wrote:

 I am running urllib2.request and get this response when I do the read.
 Any ideas what causes this?

 return response.read()
  File C:\Python26\lib\socket.py, line 329, in read
data = self._sock.recv(rbufsize)
  File C:\Python26\lib\httplib.py, line 518, in read
return self._read_chunked(amt)
  File C:\Python26\lib\httplib.py, line 561, in _read_chunked
raise IncompleteRead(''.join(value))
 IncompleteRead: IncompleteRead(3235 bytes read)

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




 --
 Nitin Pawar




-- 
http://twitter.com/dirknbr
http://maximum-likely.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Urrlib2 IncompleteRead error

2010-07-27 Thread Nitin Pawar
import socket
# timeout in seconds
timeout = 10
socket.setdefaulttimeout(timeout)



On Tue, Jul 27, 2010 at 10:09 PM, Dirk Nachbar dirk...@gmail.com wrote:

 Thanks, I don't think it's redirecting, how can I increase the timeout?


 On 27 July 2010 16:56, Nitin Pawar nitinpawar...@gmail.com wrote:

 Hi,

 Check if the webpage you are trying to access is redirecting the page to
 some other page?
 or the timeout is too less for the request to finish


 Thanks,
 Nitin

 On Tue, Jul 27, 2010 at 7:30 PM, dirknbr dirk...@gmail.com wrote:

 I am running urllib2.request and get this response when I do the read.
 Any ideas what causes this?

 return response.read()
  File C:\Python26\lib\socket.py, line 329, in read
data = self._sock.recv(rbufsize)
  File C:\Python26\lib\httplib.py, line 518, in read
return self._read_chunked(amt)
  File C:\Python26\lib\httplib.py, line 561, in _read_chunked
raise IncompleteRead(''.join(value))
 IncompleteRead: IncompleteRead(3235 bytes read)

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




 --
 Nitin Pawar




 --
 http://twitter.com/dirknbr
 http://maximum-likely.blogspot.com




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


Re: Orange County, California Python User Group

2010-07-27 Thread Calhoon, Tom
Dan:

I am an instructor at Cal State Fullerton, and we are looking for a
few industry leaders that would be willing to server on an advisory
board for a Python programming class series.  If you have a minute to
talk or know of someone who is interested, please give me a call.

 

 

Thanks

Tom Calhoon

(714) 834-6632

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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Daniel Fetchinson
 Hi folks,

 If I'm only interested in linux and windows I know I can do

 
 import os
 import platform

 if platform.system( ) == 'Linux':
 clear = 'clear'
 else:
 clear = 'cls'

 os.system( clear )
 

 or something equivalent using os.name and friends, but was wondering
 why there is no platform independent way (i.e. the platform dependence
 is taken care of by the python stdlib) of clearing a terminal. Sure,
 there are many different terminals and many different operating
 systems but in many areas python managed to hide all these
 complexities behind a well defined API.

 Why was clearing a terminal left out?


 What you're talking about is a shell, not a terminal (a terminal is a
 physical device). And the shell is not necessarily part of the OS itself

 (there's no shortage of shells for unices / linux systems), so it
 doesn't belong to the os or platform modules.

 FWIW, I can't tell for sure since I never used any other shell than
 bash, but I'm not sure your above code is garanteed to work on each and
 any possible unix shell.

 Sorry, but that is completely wrong - the shell is irrelevant.

 clear is just a normal command line program that queries the
 termcap/terminfo database (possibly via the curses library) for the
 terminal specific sequence of characters that will clear the screen. It
 then writes those characters to stdout. The terminal, or (more usually
 these days) terminal emulator, then interprets those characters and takes
 the appropriate action.

 I'm not sure what the POSIX status of the clear command is, but I'd be
 surprised if it wasn't present on a UNIX/Linux system of any vintage.


After getting the technicalities out of the way, maybe I should have asked:

Is it only me or others would find a platform independent python API
to clear the terminal useful?

Cheers,
Daniel


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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread John Nagle

On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote:

Grant Edwards a écrit :

On 2010-07-27, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:

Daniel Fetchinson a ?crit :

(snip)

Why was clearing a terminal left out?


What you're talking about is a shell, not a terminal (a terminal is a
physical device).


No, what he's talking about is clearing a terminal (or a terminal
emulator). They both work the same, the only difference is whether
the terminal software is running on dedicated hardware or on
general-purpose hardware.


(snip)

I stand corrected.


I immediately thought of using the curses module, but that's
UNIX-only, or at least it's not in the ActiveState Python distro.

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


Re: hasattr + __getattr__: I think this is Python bug

2010-07-27 Thread Ethan Furman

Bruno Desthuilliers wrote:

Bruno Desthuilliers a écrit :

Ethan Furman a écrit :

Bruno Desthuilliers wrote:

Duncan Booth a écrit :

(snip)

Or you could create the default as a class attribute 


from the OP:

I have a class (FuncDesigner oofun) that has no attribute size, but
it is overloaded in __getattr__, so if someone invokes
myObject.size, it is generated (as another oofun) and connected to
myObject as attribute.


so this solution won't obviously work in this case !-)

Also and FWIW, I wouldn't advocate this solution if the default 
class attribute is of a mutable type.


Well, it is Monday, so I may be missing something obvious, but what 
is the effective difference between these two solutions?




If you meant what is the difference between creating the whatever 
attribute with a default value in the initializer and creating it on 
demand in the __getattr__ hook, the main difference is that in the 
first case, the instance is garanteed to have this attribute, so you get 
rid of hasattr checks (and the unwanted side effects) or, worse, 
direct check of the instance __dict__. Except for a couple of corner 
case, client code shouldn't have to worry about this kind of things - 
this breaks encapsulation.


Yay Tuesday!  :D

What I meant was what is the difference between:

[Bruno Desthuilliers]
 DEFAULT_WHATEVER = Whathever()
 class MyClass(object):
  def __init__(self, x, y):
  self.size = DEFAULT_WHATEVER

and

[Duncan Booth]
 class MyClass(object):
 size = Whatever()
 def __init__(self, x, y):
 ...

in both cases the object ends up with a size attribute and no further 
need of __getattr__. Of course, the warning about having a mutable 
object as a class attribute stands.


To phrase it another way, why does your solution (Bruno) work, but 
Duncan's obviously won't?


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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Grant Edwards
On 2010-07-27, Daniel Fetchinson fetchin...@googlemail.com wrote:

 After getting the technicalities out of the way, maybe I should have asked:

 Is it only me or others would find a platform independent python API
 to clear the terminal useful?

I write a lot of command-line programs, and I can't remember the last
time time I wanted to clear a terminal.  But then again, pretty much
all of my programs are designed so that they can be used as filters.

About 10 years ago I did need to do a text-mode UI (menus, popups,
text-entry, etc.), and I used newt.

-- 
Grant Edwards   grant.b.edwardsYow! Is a tattoo real, like
  at   a curb or a battleship?
  gmail.comOr are we suffering in
   Safeway?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multicpu bzip2 using os.system or queue using python script

2010-07-27 Thread MRAB

harijay wrote:

I want to quickly bzip2 compress several hundred gigabytes of data
using my 8 core , 16 GB ram workstation.
Currently I am using a simple python script to compress a whole
directory tree using bzip2 and a system call coupled to an os.walk
call.

I see that the bzip2 only uses a single cpu while the other cpus
remain relatively idle.

I am a newbie in queue and threaded processes . But I am wondering how
I can implement this such that I can have four bzip2 running threads
(actually I guess os.system threads ), each using probably their own
cpu , that deplete files from a queue as they bzip them.


Thanks for your suggestions in advance


[snip]
Try this:

import os
import sys
from threading import Thread, Lock
from Queue import Queue

def report(message):
mutex.acquire()
print message
sys.stdout.flush()
mutex.release()

class Compressor(Thread):
def __init__(self, in_queue, out_queue):
Thread.__init__(self)
self.in_queue = in_queue
self.out_queue = out_queue
def run(self):
while True:
path = self.in_queue.get()
sys.stdout.flush()
if path is None:
break
report(Compressing %s % path)
os.system(bzip2 %s % path)
report(Done %s %  path)
self.out_queue.put(path)

in_queue = Queue()
out_queue = Queue()
mutex = Lock()

THREAD_COUNT = 4

worker_list = []
for i in range(THREAD_COUNT):
worker = Compressor(in_queue, out_queue)
worker.start()
worker_list.append(worker)

for roots, dirlist, filelist in os.walk(os.curdir):
for file in [os.path.join(roots, filegot) for filegot in filelist]:
if bz2 not in file:
in_queue.put(file)

for i in range(THREAD_COUNT):
in_queue.put(None)

for worker in worker_list:
worker.join()
--
http://mail.python.org/mailman/listinfo/python-list


Re: python terminology on classes

2010-07-27 Thread John Nagle

On 7/27/2010 12:17 AM, Bruno Desthuilliers wrote:


destructor


Python has no real destructor. You can implement a __del__ method that
will _eventually_ be called before the instance gets garbage-collected,
but you'd rather not rely on it. Also, implementing this method will
prevent cycle detection.


   That's not correct.  The Python language reference is at
http://docs.python.org/reference/datamodel.html;.  In CPython,
either __del__ will be called when the reference count goes to
zero, or it won't be called at all.  The garbage collector that
backs up the reference counting system doesn't delete objects with
__del__ methods, because of the usual problems with deletion from
a garbage collector.  The defined semantics are that loop-free
structures are deleted properly, but loops with one object that
has a __del__ hang around forever.  You can use weak pointers to
avoid loops.

   IronPython and ShedSkin are garbage-collected implementations which
have quite different __del__ semantics.  That's considered non-standard.

   In C++, the RAII approach is popular and recommended.
In C++, it's routine to create local objects which, when they go out
of scope, close a file, unlock a lock, or close a window.
It's also widely used in Python, but it's now somewhat deprecated.

   Python 2.6 has a recently added with clause, borrowed from
LISP, for associating actions with scopes.  This is supported for
files and locks, but setting your own object up for with
requires adding special methods to the object.  with is less
convenient and more limited than RAII, but that's the direction
Python is going.  This may be in preparation for a move to a real
garbage collector.

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


Re: Updating path.py

2010-07-27 Thread Michael Hoffman

Robert Kern wrote:

On 7/26/10 5:16 PM, Michael Hoffman wrote:
I have been using Jason Orendorff's path.py module for a long time. It 
is very

useful. The only problem is that Python 2.6 deprecates the md5 module it
imports, so I (and others using my software) now get this warning 
whenever they

start, which is a little annoying.

/homes/hoffman/arch/Linux-x86_64/lib/python2.6/path-2.2-py2.6.egg/path.py:32: 


DeprecationWarning: the md5 module is deprecated; use hashlib instead

The original web page is gone, and e-mails to the author have gone 
unanswered.
It has a public domain license so I could easily fork it and make 
this small
change. The question is what is the best way to do that and ensure 
continuity
with the previous versions. Can I (or someone else) take over the PyPI 
entry in

question? Other suggestions?


You cannot take over a project on PyPI. You can only fork the project 
with a new name. In fact, this has already been done:


  http://pypi.python.org/pypi/forked-path/0.1


Great, I'll start by trying that, I was hoping someone already had a 
solution.


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


suitable py2app.

2010-07-27 Thread ata.jaf
Hi,
I'm looking for a suitable tutorial for py2app. I googled it but
couldn't find anything.
Can you help me please?
Thanks
Ata
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suitable py2app.

2010-07-27 Thread Nitin Pawar
see if this helps

http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html

On Tue, Jul 27, 2010 at 11:06 PM, ata.jaf a.j.romani...@gmail.com wrote:

 Hi,
 I'm looking for a suitable tutorial for py2app. I googled it but
 couldn't find anything.
 Can you help me please?
 Thanks
 Ata
 --
 http://mail.python.org/mailman/listinfo/python-list




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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Terry Reedy

On 7/27/2010 12:58 PM, Daniel Fetchinson wrote:


After getting the technicalities out of the way, maybe I should have asked:

Is it only me or others would find a platform independent python API
to clear the terminal useful?


One problem is, Where would you put it? The OS module is for system 
calls, mostly based on posix. The system call involved in clearing a 
terminal is a write string call. *nix puts terminal control in a 
separate library.


Another is, what next? clear_line? Pretty soon, we are back to curses.

Still another problem is that most of us do not have terminals; we have 
screens and use them as such. OS-independent full-screen graphics/game 
libraries have clear screen commands. Similary, GUI systems have means 
of clearing text and canvas widgets, but should not be able to clear the 
whole screen. The turtle module has a clear command for its canvas, 
which would be the same regardless of underlying gui. So we already have 
several OS independent clear commands.


On Windows, the DOS clr command only works withing a text-mode command 
window (once called a dos window). The same thing (os.system('clr') 
within an IDLE shell uselessly flashes a blank command window, which 
then disappears. Yeah, it is too bad windows did not use the obvious 
'clear' like everyone? else. If command windows still imitate or can be 
set to imitate ansi terminals, then I would think curses is your best bet.


--
Terry Jan Reedy

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


pyodbc problem

2010-07-27 Thread Martin Gregorie
I have a small problem: I can't get pyodbc to connect to a PostgreSQL 
database. All it does is spit out a malformed error message. When I run 
this:

==
import pyodbc

dsn = pyodbc.dataSources()
print Data sources:%s % dsn

conn = pyodbc.connect(dsn=marchive)
print ODBC connection: %s % conn
==

I get this:

==
[k...@zappa python]$ python dsncheck.py
Data sources:{'ma': 'PostgreSQL', 'marchive': 'PostgreSQL'}
Traceback (most recent call last):
  File dsncheck.py, line 6, in module
conn = pyodbc.connect(dsn=marchive)
pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)')
==

so the data source exists and is evidently found by connect(), whiuch 
seems unable to make sense of it.

The pgsql module works well, but I would prefer to use ODBC because its 
not so closely bound to a single RDBMS. unixODBC, which I understand 
underlies pyodbc, works OK too:

==
[k...@zappa python]$ isql marchive marchive n/a
+---+
| Connected!|
|   |
| sql-statement |
| help [tablename]  |
| quit  |
|   |
+---+
SQL select count(*) from address;
+-+
| count   |
+-+
| 32  |
+-+
SQLRowCount returns 1
1 rows fetched
SQL quit
==

Questions:
- Why does pyodbc blow up when its apparently trying to talk to unixODBC?
- What does this mean:
pyodbc.Error: ('0', '[0] [unixODBC]c (0) (SQLDriverConnectW)')

I'm new to Python, though not to Linux, PostgreSQL, ODBC, C or Java. 
My rig and software:

Linux:  Fedora 12 Where I'm running Python and ODBC,
  Lenovo Thinkpad R61i: Core Duo.
Fedora 10 Where PostgreSQL is installed,
  IBM NetVista: Pentium III. 
PostgreSQL: 8.3.8
Python: 2.6.2
pyodbc  2.1.5-3.fc12 ) By yum from RH repository
unixODBC2.2.14-11.fc12   )


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org   |
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multicpu bzip2 using os.system or queue using python script

2010-07-27 Thread harijay
Thanks a tonne..That code works perfectly and also shows me how to
think of using queue and threads in my python programs

Hari

On Jul 27, 1:26 pm, MRAB pyt...@mrabarnett.plus.com wrote:
 harijay wrote:
  I want to quickly bzip2 compress several hundred gigabytes of data
  using my 8 core , 16 GB ram workstation.
  Currently I am using a simple python script to compress a whole
  directory tree using bzip2 and a system call coupled to an os.walk
  call.

  I see that the bzip2 only uses a single cpu while the other cpus
  remain relatively idle.

  I am a newbie in queue and threaded processes . But I am wondering how
  I can implement this such that I can have four bzip2 running threads
  (actually I guess os.system threads ), each using probably their own
  cpu , that deplete files from a queue as they bzip them.

  Thanks for your suggestions in advance

 [snip]
 Try this:

 import os
 import sys
 from threading import Thread, Lock
 from Queue import Queue

 def report(message):
      mutex.acquire()
      print message
      sys.stdout.flush()
      mutex.release()

 class Compressor(Thread):
      def __init__(self, in_queue, out_queue):
          Thread.__init__(self)
          self.in_queue = in_queue
          self.out_queue = out_queue
      def run(self):
          while True:
              path = self.in_queue.get()
              sys.stdout.flush()
              if path is None:
                  break
              report(Compressing %s % path)
              os.system(bzip2 %s % path)
              report(Done %s %  path)
              self.out_queue.put(path)

 in_queue = Queue()
 out_queue = Queue()
 mutex = Lock()

 THREAD_COUNT = 4

 worker_list = []
 for i in range(THREAD_COUNT):
      worker = Compressor(in_queue, out_queue)
      worker.start()
      worker_list.append(worker)

 for roots, dirlist, filelist in os.walk(os.curdir):
      for file in [os.path.join(roots, filegot) for filegot in filelist]:
          if bz2 not in file:
              in_queue.put(file)

 for i in range(THREAD_COUNT):
      in_queue.put(None)

 for worker in worker_list:
      worker.join()

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


Re: Why are String Formatted Queries Considered So Magical? (Spammer analysis)

2010-07-27 Thread John Nagle

On 7/26/2010 4:19 PM, Justin Smith wrote:

Seeking industry expert candidates

I’m Justin Smith, Director of Tech Recruiting at Express Seattle.  I
am currently seeking candidates to fill Tech Positions for multiple A-
List Clients:


   Spammer detected.
   Injection-Info: r27g2000yqb.googlegroups.com;
posting-host=63.170.35.94;
posting-account=XlBkJgkAAAC7JNUw8ZEYCvz12vv6mGCK
   Reverse DNS: franchisevpn.expresspersonnel.com
   Site analysis: Domain www.expresspersonnel.com
redirected to different domain www.expresspros.com
   Site analysis:
From Secure certificate (Secure certificate, high confidence)
Express Personnel Services, Inc.
Oklahoma City, OK
UNITED STATES
   Oklahoma corporation search:
EXPRESS SERVICES, INC.
Filing Number: 2400436307
Name Type: Legal Name
Status: In Existence
Corp type: Foreign For Profit Business Corporation
Jurisdiction: COLORADO
Formation Date: 28 Aug 1985
Colorado corporation search:
ID: 19871524232
Name:   EXPRESS SERVICES, INC.
Principal Street Address: 8516 NW Expressway,
Oklahoma City, OK 73162, United States
Target coordinates:
35.56973,-97.668001
Corporate class: Franchiser
--
http://mail.python.org/mailman/listinfo/python-list


Which multiprocessing methods use shared memory?

2010-07-27 Thread Kevin Ar18

I'm not sure my previous message went through (I wasn't subscribe), so I'm 
gonna try again.

The multiprocessing module has 4 methods for sharing data between processes:
Queues
Pipes
Shared Memory Map
Server Process
 
Which of these use shared memory?
 
I understand that the 3rd (Shared Memory Map) does, but what about Queues?
 
Thanks,
Kevin

  
_
Hotmail is redefining busy with tools for the New Busy. Get more from your 
inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which multiprocessing methods use shared memory?

2010-07-27 Thread MRAB

Kevin Ar18 wrote:

I'm not sure my previous message went through (I wasn't subscribe), so I'm 
gonna try again.

The multiprocessing module has 4 methods for sharing data between processes:
Queues
Pipes
Shared Memory Map
Server Process
 
Which of these use shared memory?
 
I understand that the 3rd (Shared Memory Map) does, but what about Queues?
 

The documentation says:

class multiprocessing.Queue([maxsize])
Returns a process shared queue implemented using a pipe and a few 
locks/semaphores. When a process first puts an item on the queue a 
feeder thread is started which transfers objects from a buffer into the 
pipe.

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


tkinter unicode question

2010-07-27 Thread jyoung79
Just curious if anyone could shed some light on this?  I'm using 
tkinter, but I can't seem to get certain unicode characters to 
show in the label for Python 3.  

In my test, the label and button will contain the same 3 
characters - a Greek Alpha, a Greek Omega with a circumflex and 
soft breathing accent, and then a Greek Alpha with a soft 
breathing accent.

For Python 2.6, this works great:

# -*- coding: utf-8 -*-
from Tkinter import *
root = Tk()
Label(root, text=u'\u03B1 \u1F66 \u1F00').pack()
Button(root, text=u'\u03B1 \u1F66 \u1F00').pack()
root.mainloop()

However, for Python 3.1.2, the button gets the correct characters, 
but the label only displays the first Greek Alpha character.  
The other 2 characters look like Chinese characters followed by 
an empty box.  Here's the code for Python 3:

# -*- coding: utf-8 -*-
from tkinter import *
root = Tk()
Label(root, text='\u03B1 \u1F66 \u1F00').pack()
Button(root, text='\u03B1 \u1F66 \u1F00').pack()
root.mainloop()

I've done some research and am wondering if it is 
because Python 2.6 comes with tk version 8.5, while Python 3.1.2 
comes with tk version 8.4?  I'm running this on OS X 10.6.4.

Here's a link I found that mentions this same problem:
http://www.mofeel.net/871-comp-lang-python/5879.aspx

If I need to upgrade tk to 8.5, is it best to upgrade it or just
install 'tiles'?  From my readings it looks like upgrading to
8.5 can be a pain due to OS X still pointing back to 8.4.  I
haven't tried it yet in case someone might have an easier
solution.

Thanks for looking at my question.

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


Re: Why are String Formatted Queries Considered So Magical? (Spammer analysis)

2010-07-27 Thread John Bokma
John Nagle na...@animats.com writes:

 On 7/26/2010 4:19 PM, Justin Smith wrote:
 Seeking industry expert candidates

 I’m Justin Smith, Director of Tech Recruiting at Express Seattle.  I
 am currently seeking candidates to fill Tech Positions for multiple A-
 List Clients:

Spammer detected.

But did you report it? (If so, it helps if you state so).


Injection-Info: r27g2000yqb.googlegroups.com;
   posting-host=63.170.35.94;

http://www.spamcop.net/sc?track=63.170.35.94 - looks like abuse goes to
the spammer... A whois gives sprint.net, so you could contact abuse at
sprint.net (see: http://whois.domaintools.com/63.170.35.94 )

[snip address etc.]
Spammers don't care about that. Best course of action, based on my
experience, is to contact abuse at googlegroups.com (now and then it
actually works), and sprint.net.

-- 
John Bokma   j3b

Hacking  Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl  Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows: How to detect whether a Python app/script is running in console/GUI mode?

2010-07-27 Thread MrJean1
On Jul 27, 8:36 am, Tim Golden m...@timgolden.me.uk wrote:
 On 27/07/2010 15:58, Brian Curtin wrote:

  On Tue, Jul 27, 2010 at 09:36,pyt...@bdurham.com  wrote:

  Windows: How can I detect whether a Python app/script is running in
  console/GUI mode? By app I mean a script compiled to an exe via py2exe or
  similar.

  Thank you,
  Malcolm

  I don't remember much about py2exe, but you could check if
  ``os.path.split(sys.executable)[1]`` equals pythonw.exe (typical for GUIs)
  or just python.exe (regular console).

 Don't know whether it's foolproof, but I suspect that
 checking whether win32console.GetConsoleWindow ()
 returns zero is probably not a bad approach.

 TJG    

Executables built with py2exe have an attribute sys.frozen and its
value is 'console_exe' for console applications or 'windows_exe' for
GUI applications.  See for example http://www.py2exe.org/index.cgi/
Py2exeEnvironment.

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


Re: Why is there no platform independent way of clearing a terminal?

2010-07-27 Thread Tim Harig
On 2010-07-27, John Nagle na...@animats.com wrote:
 On 7/27/2010 7:44 AM, Bruno Desthuilliers wrote:
 Grant Edwards a écrit :
 On 2010-07-27, Bruno Desthuilliers
 bruno.42.desthuilli...@websiteburo.invalid wrote:
 Daniel Fetchinson a ?crit :
 (snip)
 Why was clearing a terminal left out?

 What you're talking about is a shell, not a terminal (a terminal is a
 physical device).

 No, what he's talking about is clearing a terminal (or a terminal
 emulator). They both work the same, the only difference is whether
 the terminal software is running on dedicated hardware or on
 general-purpose hardware.

 (snip)

 I stand corrected.

  I immediately thought of using the curses module, but that's
 UNIX-only, or at least it's not in the ActiveState Python distro.

pdcurses:

http://pdcurses.sourceforge.net/

is a cross platform curses implementation that is available for Windows.
I wonder how difficult it would be to embed into the Python curses module
as a backup for systems where curses is not natively available.  This would
allow Python to provide cross platform charactor mode manipulation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter unicode question

2010-07-27 Thread Ned Deily
In article 20100727204532.r7gmz.27213.r...@cdptpa-web20-z02,
 jyoun...@kc.rr.com wrote:
 Just curious if anyone could shed some light on this?  I'm using 
 tkinter, but I can't seem to get certain unicode characters to 
 show in the label for Python 3.  
 
 In my test, the label and button will contain the same 3 
 characters - a Greek Alpha, a Greek Omega with a circumflex and 
 soft breathing accent, and then a Greek Alpha with a soft 
 breathing accent.
 
 For Python 2.6, this works great:
 
 # -*- coding: utf-8 -*-
 from Tkinter import *
 root = Tk()
 Label(root, text=u'\u03B1 \u1F66 \u1F00').pack()
 Button(root, text=u'\u03B1 \u1F66 \u1F00').pack()
 root.mainloop()
 
 However, for Python 3.1.2, the button gets the correct characters, 
 but the label only displays the first Greek Alpha character.  
 The other 2 characters look like Chinese characters followed by 
 an empty box.  Here's the code for Python 3:
 
 # -*- coding: utf-8 -*-
 from tkinter import *
 root = Tk()
 Label(root, text='\u03B1 \u1F66 \u1F00').pack()
 Button(root, text='\u03B1 \u1F66 \u1F00').pack()
 root.mainloop()
 
 I've done some research and am wondering if it is 
 because Python 2.6 comes with tk version 8.5, while Python 3.1.2 
 comes with tk version 8.4?  I'm running this on OS X 10.6.4.

Most likely.  Apparently you're using the Apple-supplied Python 2.6 
which, as you say, uses Tk 8.5.  If you had installed the python.org 
2.6, it would likely fail for you in the same way as 3.1, since both use 
Tk 8.4.  (They both fail for me.)

 If I need to upgrade tk to 8.5, is it best to upgrade it or just
 install 'tiles'?  From my readings it looks like upgrading to
 8.5 can be a pain due to OS X still pointing back to 8.4.  I
 haven't tried it yet in case someone might have an easier
 solution.

OS X 10.6 comes with both Tk 8.4 and 8.5.  The problem is that the 
Python Tkinter(2.6) or tkinter(3.1) is linked at build time, not install 
time, to one or the other.   You would need to at least rebuild and 
relink tkinter for 3.1 to use Tk 8.5, which means downloading and 
building Python from source.  New releases of python.org installers are 
now coming in two varieties: the second will be only for 10.6 or later 
and will link with Tk 8.5.  The next new release of Python 3 is likely 
months away, though.  In the meantime, a simpler solution might be to 
download and install the ActiveState Python 3.1 for OS X which does use 
Tk 8.5.  And your test case works for me with it.

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

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


urllib timeout

2010-07-27 Thread kBob


 I created a script to access weather satellite imagery fron NOAA's
ADDS.

 It worked fine until recently with Python 2.6.

 The company changed the Internet LAN connections to Accept Automatic
settings and Use automatic configuration script

 How do you get urllib.urlopen to use the the automatic script
configuration?

 This code worked recently, until the company implemented these LAN
connections...

SAT_URL = http://adds.aviationweather.gov/data/satellite/
latest_BWI_vis.jpg
satpic = urllib.urlopen(SAT_URL, proxies=0 )
satimg = satpic.read()


Kelly Dean
Fort Collins, CO
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binary compatibility across Python versions?

2010-07-27 Thread Philip Semanchuk


On Jul 26, 2010, at 5:19 PM, Ned Deily wrote:


In article i2kok1$kr...@dough.gmane.org,
Christian Heimes li...@cheimes.de wrote:

[Philip Semanchuk wrote:]

Specifically, I'm concerned with binaries created by SWIG for a C++
library that our project uses. We'd like to ship precompiled  
binaries
for Linux, OS X and Windows for Python 2.5 and 2.6. I'm hoping  
that it
is sufficient to create binaries for each Python for each platform  
(3

* 2 == 6 total precompiled binaries).

For each platforms you have to provide binaries for the major CPU
architectures (X86 and X64_86), too. Users or distributions may  
compile

Python with UCS-2 or UCS-4 unicode width. That makes eight different
binaries for Linux (two version * two archs * UCS2/4). Although most
distributions follow the LSB standards, binaries aren't necessary ABI
compatible. C++ binaries tend to break more often than C binaries.


And, on OS X, there are various Python binary distributions in common
use: the Apple-supplied Pythons (2.5 for OS X 10.5, 2.6  2.5 for  
10.6),

the python.org OS X installers for 10.5 and 10.6, plus the ActiveState
and EPD ones.  It would likely be difficult to ship one binary  
extension

that would easily work, if at all, with the most common ones.  For
instance, the Apple-supplied Python 2.6 is built with gcc 4.2, uses  
the
10.6 ABI (SDK deployment target), and x86_64 / i386 / ppc  
architectures
(default 64-bit on capable machines).  The python.org 2.6 uses gcc  
4.0,

the 10.4u ABI, and is 32-bit only (i386 / ppc)


Thanks to all who replied on this topic. A little more background --  
these binaries are just a convenience for our users and we don't have  
to cover every possible permutation of Python, only the ones we think  
will be most common in our user base. That said, thanks to the things  
you pointed out, I'm beginning to think that our users might be such a  
varied group that precompiled binaries might not be worth the trouble.


Ned, I'm on Mac and I was under the impression that the deployment  
target compiler option would control how the resulting binary (in this  
case, Python) called OS X but it wouldn't have any affect on how other  
code (like our library) called Python. Is that not the case?



Thanks
Philip









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


Re: newb

2010-07-27 Thread Lie Ryan

On Tue, 27 Jul 2010 11:07:09 GMT, whitey m...@here.com wrote:
hi all. am totally new to python and was wondering if there are any 
newsgroups that are there specifically for beginners. 


Yes, Python Tutor list is specifically aimed for beginners. You can 
access it by subscribing to either tu...@python.org or 
gmane.comp.python.tutor


would still be valid? 


Mostly yes. However I'd recommend getting a more updated book 
especially if you're a beginner.


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


Re: urllib timeout

2010-07-27 Thread MRAB

kBob wrote:


 I created a script to access weather satellite imagery fron NOAA's
ADDS.

 It worked fine until recently with Python 2.6.

 The company changed the Internet LAN connections to Accept Automatic
settings and Use automatic configuration script

 How do you get urllib.urlopen to use the the automatic script
configuration?

 This code worked recently, until the company implemented these LAN
connections...

SAT_URL = http://adds.aviationweather.gov/data/satellite/
latest_BWI_vis.jpg
satpic = urllib.urlopen(SAT_URL, proxies=0 )
satimg = satpic.read()


For the record, I got:

 import urllib
 SAT_URL = 
http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg;

 satpic = urllib.urlopen(SAT_URL, proxies=0 )
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\urllib.py, line 79, in urlopen
opener = FancyURLopener(proxies=proxies)
  File C:\Python26\lib\urllib.py, line 617, in __init__
URLopener.__init__(self, *args, **kwargs)
  File C:\Python26\lib\urllib.py, line 129, in __init__
assert hasattr(proxies, 'has_key'), proxies must be a mapping
AssertionError: proxies must be a mapping

However, urllib.urlretrieve(...) works.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Binary compatibility across Python versions?

2010-07-27 Thread Ned Deily
In article 0a4c9b21-6eff-461a-b15c-415d1408d...@semanchuk.com,
 Philip Semanchuk phi...@semanchuk.com wrote:
[...]
 Thanks to all who replied on this topic. A little more background --  
 these binaries are just a convenience for our users and we don't have  
 to cover every possible permutation of Python, only the ones we think  
 will be most common in our user base. That said, thanks to the things  
 you pointed out, I'm beginning to think that our users might be such a  
 varied group that precompiled binaries might not be worth the trouble.
 
 Ned, I'm on Mac and I was under the impression that the deployment  
 target compiler option would control how the resulting binary (in this  
 case, Python) called OS X but it wouldn't have any affect on how other  
 code (like our library) called Python. Is that not the case?

Even if your extension modules and libraries don't make a lot of system 
calls, I think it's a bit of a crap shoot since there are no guarantees 
of compatibility among the various popular distributions and there are 
the gcc-4.0 vs -4.2 and the arch differences.  You'd have to try the 
various combinations and/or limit the configurations you support. The 
bottom line is that many (most?) package developers have given up on 
trying to supply binary distributions for OS X.  Since Apple supplies 
the necessary developer tools for free with recent OS X releases and in 
most cases Distutils does the right thing, the burden on end users isn't 
particularly onerous (see, for example, 
http://appscript.sourceforge.net/py-appscript/install.html).

Now, adding SWIG and C++ to the mix may result in a different answer.  I 
don't have any practical experience with them to have an opnion.  Good 
luck!

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

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


Re: urllib timeout

2010-07-27 Thread kBob
On Jul 27, 4:23 pm, MRAB pyt...@mrabarnett.plus.com wrote:
 kBob wrote:

   I created a script to access weather satellite imagery fron NOAA's
  ADDS.

   It worked fine until recently with Python 2.6.

   The company changed the Internet LAN connections to Accept Automatic
  settings and Use automatic configuration script

   How do you get urllib.urlopen to use the the automatic script
  configuration?

   This code worked recently, until the company implemented these LAN
  connections...

      SAT_URL = http://adds.aviationweather.gov/data/satellite/
  latest_BWI_vis.jpg
      satpic = urllib.urlopen(SAT_URL, proxies=0 )
      satimg = satpic.read()

 For the record, I got:

   import urllib
   SAT_URL =
 http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg;
   satpic = urllib.urlopen(SAT_URL, proxies=0 )
 Traceback (most recent call last):
    File stdin, line 1, in module
    File C:\Python26\lib\urllib.py, line 79, in urlopen
      opener = FancyURLopener(proxies=proxies)
    File C:\Python26\lib\urllib.py, line 617, in __init__
      URLopener.__init__(self, *args, **kwargs)
    File C:\Python26\lib\urllib.py, line 129, in __init__
      assert hasattr(proxies, 'has_key'), proxies must be a mapping
 AssertionError: proxies must be a mapping

 However, urllib.urlretrieve(...) works.- Hide quoted text -

 - Show quoted text -

I saw that, but I still get the same error time out error ...

 import urllib
 SAT_URL = http://adds.aviationweather.gov/data/satellite/;
 SAT_FILE = latest_BWI_vis.jpg
 satimg = urllib.urlretrieve( SAT_URL, SAT_FILE )
Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\python26\lib\urllib.py, line 93, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
  File c:\python26\lib\urllib.py, line 237, in retrieve
fp = self.open(url, data)
  File c:\python26\lib\urllib.py, line 205, in open
return getattr(self, name)(url)
  File c:\python26\lib\urllib.py, line 344, in open_http
h.endheaders()
  File c:\python26\lib\httplib.py, line 904, in endheaders
self._send_output()
  File c:\python26\lib\httplib.py, line 776, in _send_output
self.send(msg)
  File c:\python26\lib\httplib.py, line 735, in send
self.connect()
  File c:\python26\lib\httplib.py, line 716, in connect
self.timeout)
  File c:\python26\lib\socket.py, line 514, in create_connection
raise error, msg
IOError: [Errno socket error] [Errno 10060] A connection attempt
failed because
the connected party did not properly respond after a period of time,
or establis
hed connection failed because connected host has failed to respond

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


Re: urllib timeout

2010-07-27 Thread MRAB

kBob wrote:

On Jul 27, 4:23 pm, MRAB pyt...@mrabarnett.plus.com wrote:

kBob wrote:


 I created a script to access weather satellite imagery fron NOAA's
ADDS.
 It worked fine until recently with Python 2.6.
 The company changed the Internet LAN connections to Accept Automatic
settings and Use automatic configuration script
 How do you get urllib.urlopen to use the the automatic script
configuration?
 This code worked recently, until the company implemented these LAN
connections...
SAT_URL = http://adds.aviationweather.gov/data/satellite/
latest_BWI_vis.jpg
satpic = urllib.urlopen(SAT_URL, proxies=0 )
satimg = satpic.read()

For the record, I got:

  import urllib
  SAT_URL =
http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg;
  satpic = urllib.urlopen(SAT_URL, proxies=0 )
Traceback (most recent call last):
   File stdin, line 1, in module
   File C:\Python26\lib\urllib.py, line 79, in urlopen
 opener = FancyURLopener(proxies=proxies)
   File C:\Python26\lib\urllib.py, line 617, in __init__
 URLopener.__init__(self, *args, **kwargs)
   File C:\Python26\lib\urllib.py, line 129, in __init__
 assert hasattr(proxies, 'has_key'), proxies must be a mapping
AssertionError: proxies must be a mapping

However, urllib.urlretrieve(...) works.- Hide quoted text -

- Show quoted text -


I saw that, but I still get the same error time out error ...


import urllib
SAT_URL = http://adds.aviationweather.gov/data/satellite/;
SAT_FILE = latest_BWI_vis.jpg
satimg = urllib.urlretrieve( SAT_URL, SAT_FILE )

Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\python26\lib\urllib.py, line 93, in urlretrieve
return _urlopener.retrieve(url, filename, reporthook, data)
  File c:\python26\lib\urllib.py, line 237, in retrieve
fp = self.open(url, data)
  File c:\python26\lib\urllib.py, line 205, in open
return getattr(self, name)(url)
  File c:\python26\lib\urllib.py, line 344, in open_http
h.endheaders()
  File c:\python26\lib\httplib.py, line 904, in endheaders
self._send_output()
  File c:\python26\lib\httplib.py, line 776, in _send_output
self.send(msg)
  File c:\python26\lib\httplib.py, line 735, in send
self.connect()
  File c:\python26\lib\httplib.py, line 716, in connect
self.timeout)
  File c:\python26\lib\socket.py, line 514, in create_connection
raise error, msg
IOError: [Errno socket error] [Errno 10060] A connection attempt
failed because
the connected party did not properly respond after a period of time,
or establis
hed connection failed because connected host has failed to respond


It should be like this:

SAT_URL = 
http://adds.aviationweather.gov/data/satellite/latest_BWI_vis.jpg;

SAT_FILE = rC:\latest_BWI_vis.jpg
urllib.urlretrieve(SAT_URL, SAT_FILE)

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


subprocess module under python 2.7

2010-07-27 Thread Timothy W. Grove
I am using the following code to hide the console window when launching 
a subprocess under Windows.


   startupinfo = subprocess.STARTUPINFO()
   startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
   startupinfo.wShowWindow = subprocess.SW_HIDE

   self.mplayer = Popen(args,
bufsize=0, #unbufferred
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
close_fds=False,
universal_newlines=True,
startupinfo=startupinfo
)

This worked okay in using the subprocess module under python 2.6, but 
under python 2.7 I get the error:


Exception in thread Thread-1:
Traceback (most recent call last):
 File threading.pyo, line 530, in __bootstrap_inner
 File gui\mplayer_ctrl.pyo, line 93, in run
AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

Anything changed between python versions to account for this?

Best regards,
Tim




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


Re: subprocess module under python 2.7

2010-07-27 Thread Chris Rebert
On Tue, Jul 27, 2010 at 4:12 PM, Timothy W. Grove tim_gr...@sil.org wrote:
 I am using the following code to hide the console window when launching a
 subprocess under Windows.

       startupinfo = subprocess.STARTUPINFO()
       startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
       startupinfo.wShowWindow = subprocess.SW_HIDE

       self.mplayer = Popen(args,
                            bufsize=0, #unbufferred
                            stdin=PIPE,
                            stdout=PIPE,
                            stderr=PIPE,
                            close_fds=False,
                            universal_newlines=True,
                            startupinfo=startupinfo
                            )

 This worked okay in using the subprocess module under python 2.6, but under
 python 2.7 I get the error:

 Exception in thread Thread-1:
 Traceback (most recent call last):
  File threading.pyo, line 530, in __bootstrap_inner
  File gui\mplayer_ctrl.pyo, line 93, in run
 AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

 Anything changed between python versions to account for this?

Yes, apparently the code importing that stuff got removed:
http://svn.python.org/view/python/tags/r27/Lib/subprocess.py?r1=79064r2=82504

FWIW, STARTUPINFO(), STARTF_USESHOWWINDOW, and SW_HIDE were/are
undocumented in both Python versions and thus shouldn't be relied
upon. They can be accessed via Python's win32-specific modules instead
(see diff).

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


Re: Are those features still the same?

2010-07-27 Thread Thomas Jollans
On 07/25/2010 11:02 AM, francogrex wrote:
 Terry Reedy wrote:
 As other have said, mostly, but I would change the following...
 
 Thanks for all those who replied. I know these are not all the features but 
 some of them and again this is not a comparison but a little taste of what 
 python offers today, and the replies were very informative. By the way Peter 
 Norvig is not biased, he works for Google research and is a supporter of 
 programming in any language, especially in Python.
 

Had I known the table was headed with Python for Lisp programmers, I
would have responded differently - but you chose to hide that ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newb

2010-07-27 Thread Monte Milanuk

On 7/27/10 4:07 AM, whitey wrote:

hi all. am totally new to python and was wondering if there are any
newsgroups that are there specifically for beginners. i have bought a
book for $2 called learn to program using python by alan gauld.
starting to read it but it was written in 2001. presuming that the
commands and info would still be valid? any websites or books that are a
must for beginners? any input would be much appreciated...cheers


Alan Gauld posts fairly regularly over on the python-tutor mailing list, 
as well as here.  He has newer material on his website @ 
http://www.alan-g.me.uk/, and if you google 'python tutorial' you'll 
probably find more material than you can shake a stick at - from web 
pages to books (both online and dead-tree) to You-Tube videos.


One book that helps me out quite a bit is John Zelle's Python 
Programming: An Introduction to Computer Science.  Just be aware there 
is a first edition (covers python 2.x) and a newer second edition 
(python 3.x) - both available from Amazon.


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


Re: newb

2010-07-27 Thread Mithrandir
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 07/27/2010 04:07 AM, whitey wrote:
 hi all. am totally new to python and was wondering if there are any 
 newsgroups that are there specifically for beginners. i have bought a 
 book for $2 called learn to program using python by alan gauld. 
 starting to read it but it was written in 2001. presuming that the 
 commands and info would still be valid? any websites or books that are a 
 must for beginners? any input would be much appreciated...cheers

It may also depend on which version of Python you wish to use. Since
you're a newb, I'd probably suggest starting off with Python 3. The
version in your book is probably version 2.*. The difference is minor,
but, when you're starting off (I assume with computer languages in
general?) the difference in syntax can kick you where it hurts. Programs
that work with Python 2.*, may not work with Python 3. However, I
suggest Python 3 since it seems to be the code of tomorrow.

It may also depend on what you wish to do with your knowledge of Python
(applications, games, web frameworks, etc.) If you want to make games, I
suggest also learning about pyGame.

As for book versus website, I started off with, as others have
mentioned, learning online. Not only is it free, but the boundary
between page and screen is broken. Note though that some off-sites
(Wikibooks for instance) may not be complete in their writing.
Python.org has a wealth of knowledge about almost everything involving
Python. However, *some* of the documentation there may not be suitable
for absolute beginners. There are several links there to other good
websites for those with no experience in coding, all the way up to a
ridiculously complicated level. I highly suggest poking around there.

If you wish to read a book instead, try:
http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002/
Or go to your local library and poke there. :)

Good luck!

- -- 
People should read more.
https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain
All that is gold does not glitter,
not all those who wander are lost;
the old that is strong does not wither,
deep roots are not reached by the frost.
- From the ashes a fire shall be woken,
a light from the shadows shall spring;
renewed shall be blade that was broken,
the crownless again shall be king.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMT5PPAAoJEKo37V1xH7gTct0IAJrhBXLD5snWBBnrvpr4G3KI
7NV+yxZAphuqXXIj/F97+TKXVgld5PaWkguFjIb5CbBcYZxBP6lk+9c014422BnH
yKjmdzC0eJhg0D3FL6Vdnrw3fn2UGZNzbFRp6FDv+calxyIJS3u/hWf8nW4HiHim
Q4Xe+Df5tP5OrkiuHAs34xwco/ln5g2x5lJJRZD5eyxHKi70p9ipQZ5p5f5XB/Jw
pIvBNIC54Xm9PZUHAeEQIeF/cPeIvE8CEvf7xrbf1LbboB6LqwIqKqpeF7Ae7sq2
x0duNq4H7Llrl5iOMKBPEyYO23VF8T6heVbDCVH6yT4uSc6qnt+6StNVmnRrI8E=
=cEZW
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are those features still the same?

2010-07-27 Thread Mithrandir
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 07/26/2010 11:58 PM, Lawrence D'Oliveiro wrote:
 In message i2gujh$sl...@news.eternal-september.org, francogrex wrote:
 
 By the way Peter Norvig is not biased, he works for Google research and is
 a supporter of programming in any language, especially in Python.
 
 Bias doesn’t have to be a conscious thing.

Correct. It just has to have a rainbow logo and own half the internet. :)

- -- 
People should read more.
https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain
All that is gold does not glitter,
not all those who wander are lost;
the old that is strong does not wither,
deep roots are not reached by the frost.
- From the ashes a fire shall be woken,
a light from the shadows shall spring;
renewed shall be blade that was broken,
the crownless again shall be king.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMT5VTAAoJEKo37V1xH7gTobAH/1QY0SN6BulkNO3QUFrzg5cO
OkeDTbTmI4BJ1M/hmkECU+T76KfnkQ13NobLroWt/UJU8YA4lOQ6KsJU/EsR/27n
TFrUxs3gDVeWyiKdSbWtVSZ7b7BJ8Tr41hMPkA1wyK85qJW5mA19h0hndqs/BRtg
j2GWPLNv9wx7+v0gQnv7ZgSQJHSlRvp8oi016QVl3W7OcO6B0rgwWx4i1hxz/oij
Wd1jF5wwhtgw/0durTFFVt7mR31l3/6zz2WrwvC9fQkSKNQ0oaNgKXZOtctWVdcV
XNm+W9I9Sx70F1qO+VfFrHIRJ+kzjCf6/48bumaygol4MnbLIJ3lJ1BNIESIFAg=
=iv9B
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


The Miracle and Challenge of the Quran

2010-07-27 Thread nais-saudi
The Miracle and Challenge of the Quran
---­---

http://www.youtube.com/watch?v=m3A8R...layer_embedded


http://www.youtube.com/watch?v=m3A8R...layer_embedded
---­---


Do you know Islam ? Try


VISIT THESE SITES


ISLAM RELIGION


http://www.islamreligion.com/


SCIENE ISLAM


http://www.islamreligion.com/


YOUTUBE ISLAM


http://youtubeislam.com/


BIBLE ISLAM


http://www.bibleislam.com/


MINISTRY OF AWKAF


http://www.islamic-council.org/


ISLAM WORD


http://islamworld.net/


ISLAM HOUSE


http://www.islamhouse.com/


SUNNAH ONLINE


http://www.sunnahonline.com/ilm/dawah/index.htm


---­--
The Miracle and Challenge of the Quran


 With an introduction by Magdy Abd Al-SHafy
The Holy Quran is a miracle that beggars de**ion , words fail to
describe this miracle , it is a miracle in the full sense of the
term . Different specialists , according to the branch of science
they
are specialized in , find it miraculous . Prophet Mohummed said
commenting on the Holy Quran saying  it unfolds the secrets of the
nations that preceded you , and secrets of the future treasured in it
 It is the Holy Book that Jinnee , on hearing to it , did not leave
their place till they believed in it . It is the book which
unbelievers gave positive witness to .
Dr. Keith L. Moore is a Professor of Anatomy and Cell Biology,
University of Toronto, Toronto, Canada. He is a world renowned
scientist and a distinguished researcher in the fields of anatomy and
embryology, he has published more than 150 research articles,
chapters
and books in this field. He is the author of several medical
books, such as the widely used and acclaimed The Developing
Human: Clinically oriented Embryology (now in it's fifth edition,
and
translated into eight different languages), Before We Are Born and
Clinically Oriented Anatomy. He has also recently co-authored
Qur'an and Modern Science, Correlation Studies. Dr. Moore is the
recipient of numerous awards and honors, including, in 1984, the
J.C.B. Grant Award, which is the highest honor granted by the
Canadian
Association of Anatomists. He has served in many academic and
administrative positions, including the President of the Canadian
Association of Anatomists, 1968-1970. Let us see what Dr. Moore's
opinion is on the scientific statements regarding embryology to be
found in the Qur'an:
Dr. Moore was contacted by a Muslim scholar by the name of Abdul-
Majeed Azzindani. He was asked to participate in a three-year study
of
around twenty-five verses of the Qur'an and the Sunnah (sayings of
Muhammad, pbuh) which speak about embryology, and to determine the
their correspondence to modern scientific discoveries. Dr. Moore's
conclusion regarding this matter was:
For the past three years, I have worked with the Embryology
Committee
of King Abdulaziz University in Jeddah, Saudi Arabia, helping them to
interpret the many statements in the Qur'an and the Sunnah referring
to human reproduction and prenatal development. At first I was
astonished by the accuracy of the statements that were recorded in
the
seventh century AD, before the science of embryology was established.
Although I was aware of the glorious history of Muslim scientists in
the 10th century AD, and of some of their contributions to Medicine,
I
knew nothing about the religious facts and beliefs contained in the
Qur'an and Sunnah. It is important for Islamic and other students to
understand the meaning of these Qur'anic statements about human
development, based on current scientific knowledge. The
interpretations of the verses in the Qur'an and the Sunnah,
translated by Shaikh Azzindani, are to the best of my knowledge
accurate.
From the forward of The Developing Human: Clinically oriented
Embryology, third edition, by Dr. Keith L. Moore.
The Qur'an and the Sunnah of the prophet Muhammad (Sallalahu Alayhi
Wa
Salam) provide a very detailed de**ion of the microscopic
development of the human embryo from a mere sperm drop up to the
stage
of a completely formed human being. It is well known that microscopes
were not developed until the sixteenth century AD, and even at that
were very crude in design. Zacharias Janssen is credited with having
invented the compound microscope in about 1590. With it, remarkable
scientific discoveries were made in the 17th and 18th centuries. The
Dutch naturalist Anthony van Leeuwenhoek produced lenses powerful
enough to prove that many tiny creatures are not spontaneously
generated but come from eggs.
Before this period, theories on human reproduction ran rampant. Some
scientist believed that the menstrual blood itself developed into the
fetus. Later on, a new theory was developed wherein the sperm drop
was
popularly believed to 

Where is the help page for re.MatchObject?

2010-07-27 Thread Peng Yu
I know the library reference webpage for re.MatchObject is at
http://docs.python.org/library/re.html#re.MatchObject

But I don't find such a help page in python help(). Does anybody know
how to get it in help()?

 help(re.MatchObject)
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'module' object has no attribute 'MatchObject'

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


Re: How to capture all the environment variables from shell?

2010-07-27 Thread Steven W. Orr
On 07/26/10 22:42, quoth Tim Chase:
 On 07/26/10 21:26, Steven W. Orr wrote:
 Please! Never export anything from your .bashrc unless you
 really know what you're doing. Almost all exports should be
 done in your .bash_profile
 
 Could you elaborate on your reasoning why (or why-not)?  I've found that
 my .bash_profile doesn't get evaluated when I crank up another terminal
 window, while my bashrc does.  Thus I tend to put my exports in my
 ~/.bashrc so they actually take effect in my shell...
 
 -tkc
 
 

I'm happy to elaborate, but people should feel free to stop me if they're not
interested. The topic is bash:

When you log in you get your .bash_profile and not the .bashrc. Subshells get
the .bashrc and not the .bash_profile. If you set your envvars in your
.bash_profile then you don't need to reset them in subshells because they all
get inherited. (Inheritance of envvars is, after all, the reason that they are
envvars and not just local variables.)

The way you get your .bashrc to happen at login time is that you have to make
it happen yourself. In your .bash_profile, just say this:

. ~/.bashrc

The one time that you should set an envvar in your .bashrc is when you are not
an interactive shell. In that case you can set your PATH var in your .bashrc
by first testing to see if you're interactive: In your .bashrc just say:

[[ -z $PS1 ]]  set_PATH_cmds
# Of course, note that set_PATH_cmds is not a subprocess. It has to
# be either a PATH= or function that accomplishes the same thing.

This solves the problem of things like

ssh somemachine cmd
where cmd is something that you would only find on your PATH if you properly
logged in.

As far as X goes, I am starting from the premise that your X session will be
set up to cause your .bash_profile to happen at login time.

One last note: If you say something like

export PATH=$PATH:/usr/local/bin

then re-sourcing your .bash_profile will cause your PATH value to double up.
That's why I set my PATH variable explicitly.

After that, I encourage people to set up their PATH variables so that they are
broken into four distinct sections in the following order. (The idea is to
make your stuff override the system supplied stuff.) (The stuff below is just
an example.)

USERPERSONAL=~/bin:~/share/bin
MACHINESPECIALS=/usr/local/bin:/usr/local/share/bin
OPTIONALADDONS=/opt/Adobe/Reader9/bin:/opt/openoffice.org3/program
VENDORPATHS=/bin:/usr/bin:/usr/X11R6/bin
PATH=${USERPERSONAL}:${MACHINESPECIALS}:${OPTIONALADDONS}:${VENDORPATHS}

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which multiprocessing methods use shared memory?

2010-07-27 Thread John Nagle

On 7/27/2010 12:30 PM, MRAB wrote:

Kevin Ar18 wrote:

I'm not sure my previous message went through (I wasn't subscribe), so
I'm gonna try again.

The multiprocessing module has 4 methods for sharing data between
processes:
Queues
Pipes
Shared Memory Map
Server Process

Which of these use shared memory?

I understand that the 3rd (Shared Memory Map) does, but what about
Queues?


The documentation says:

class multiprocessing.Queue([maxsize])
Returns a process shared queue implemented using a pipe and a few
locks/semaphores. When a process first puts an item on the queue a
feeder thread is started which transfers objects from a buffer into the
pipe.


   Python's shared memory between processes is un-Pythonic.  You
can't share Python object, only C objects.  The locking mechanisms
are very limited, and slow; locking actually takes place via
messages over pipes.  There's no dynamic allocation in the shared area.

   Realistically, if you're using Python, you're not that concerned
about compute speed.  So don't bother with shared memory, which is
a performance optimization.

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


[issue9205] Parent process hanging in multiprocessing if children terminate unexpectedly

2010-07-27 Thread Greg Brockman

Greg Brockman g...@ksplice.com added the comment:

 You can't have a sensible default timeout, because the worker may be
 processing something important...
In my case, the jobs are either functional or idempotent anyway, so aborting 
halfway through isn't a problem.  In general though, I'm not sure what kinds of 
use cases would tolerate silently-dropped jobs.  And for example, if an OOM 
kill has just occurred, then you're already in a state where a job was 
unexpectedly terminated... you wouldn't be violating any more contracts by 
aborting.

In general, I can't help but feel that the approach of ignore errors and keep 
going leads to rather unexpected bugs (and in this case, it leads to infinite 
hangs).  But even in languages where errors are ignored by default (e.g. sh), 
there are mechanisms for turning on abort-on-error handlers (e.g. set -e).

So my response is yes, you're right that there's no great default here.  
However, I think it'd be worth (at least) letting the user specify if 
something goes wrong, then abort.  Keep in mind that this will only happen in 
very exceptional circumstances anyway.

 Not everything can be simple.
Sure, but given the choice between a simple solution and a complex one, all 
else being equal the simple one is desirable.  And in this case, the more 
complicated mechanism seems to introduce subtle race conditions and failures 
modes.

Anyway, Jesse, it's been a while since we've heard anything from you... do you 
have thoughts on these issues?  It would probably be useful to get a fresh 
opinion :).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9205
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9334] argparse does not accept options taking arguments beginning with dash (regression from optparse)

2010-07-27 Thread Steven Bethard

Steven Bethard steven.beth...@gmail.com added the comment:

It *would* be a backwards incompatible change. Currently, if I have a parser 
with both a --foo and a --bar option, and my user types --foo --bar, they 
get an error saying that they were missing the argument to --foo. Under your 
proposal, the --foo option will now silently consume the --bar option 
without an error. I know this is good from your perspective, but it would 
definitely break some of my scripts, and I imagine it would break other 
people's scripts as well.

As I keep saying, I'm happy to add your alternative parsing as an option 
(assuming you provide a patch), but I really don't think it's the right thing 
to do by default. Most command line programs don't have options that take other 
option-like things as arguments (which is the source of your problem), so in 
most command line programs, people want an error when they get an option they 
don't recognize or an option that's missing its argument. Under your proposal, 
more such errors will pass silently and will have to be caught by additional 
code in the script.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9334
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9387] Make python -m tkinter run tkinter demo

2010-07-27 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

The note seems fine to me. I’d used a semicolon, not a period, but that’s just 
me.

You want to use `` to mark up code, not `.

Aside: I’ve been told before not to do wrapping or whitespace changes unrelated 
to the object of my patch, to ease review.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9387
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1682942] ConfigParser support for alt delimiters

2010-07-27 Thread Łukasz Langa

Changes by Łukasz Langa luk...@langa.pl:


Removed file: http://bugs.python.org/file18216/issue1682942.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1682942
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1682942] ConfigParser support for alt delimiters

2010-07-27 Thread Łukasz Langa

Łukasz Langa luk...@langa.pl added the comment:

Updated the patch after review by Brian Curtin and Alexander Belopolsky. All 
remarks addressed, I think it's ready for inclusion.

--
Added file: http://bugs.python.org/file18219/issue1682942.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1682942
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7198] csv.writer

2010-07-27 Thread Andreas Balogh

Andreas Balogh balo...@gmail.com added the comment:

I encountered the same problem. It is unclear that using binary mode for the 
file is solving the problem. I suggest to add a hint to the documentation.

--
nosy: +baloan

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7198
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >