Python-URL! - weekly Python news and links (Dec 15)

2009-12-16 Thread Gabriel Genellina
QOTW:  Plus, it's not something that's never foolproof. - Carl Banks,
daring negater
http://groups.google.com/group/comp.lang.python/msg/e8f3adbf2cc31514


Several graph libraries are available; which one is the best? maybe they
should be merged?
http://groups.google.com/group/comp.lang.python/t/785d100681f7d101/
http://groups.google.com/group/comp.lang.python/t/7e65ca66cd7b511/

list(generator) and the equivalent list comprehension are not always
equivalent:
http://groups.google.com/group/comp.lang.python/t/ae70dfa12677c1d5/

A succint way to parse a string of name=value pairs:
http://groups.google.com/group/comp.lang.python/t/dc725717e63d6295/

Keep only unique elements in a list - and the perils of wrongly defining
__hash__:
http://groups.google.com/group/comp.lang.python/t/80491b9bc2f45547/

Python does not have a switch statement - how to overcome that?
http://groups.google.com/group/comp.lang.python/t/9af90ddc7652beb0/

What are the advantages of an explicit self?
http://groups.google.com/group/comp.lang.python/t/17a3369aef70fd38/

A new guy in the neighborhood, recently moved from PHP:
http://groups.google.com/group/comp.lang.python/t/6e91d87a9a3a3edb/
http://groups.google.com/group/comp.lang.python4c295a7ca96f65c3101/

Another convert, this time coming from Perl-land:
http://groups.google.com/group/comp.lang.python/t/22edc1c7eef569d5/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all
The old Python To-Do List now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470group_id=5470func=browse
http://www.python.org/dev/peps/pep-0042/

del.icio.us presents an intriguing approach to reference commentary.
It already aggregates quite a bit of Python intelligence.
http://del.icio.us/tag/python

Enjoy the *Python Magazine*.
http://pymag.phparch.com/

*Py: the Journal of the Python Language*
http://www.pyzine.com

CodeInvestigator 0.20.0

2009-12-16 Thread hans moleman
CodeInvestigator 0.20.0 was released on December 16.

Changes: UI changes.


You need Python 2.6 and Firefox for CodeInvestigator.

CodeInvestigator is a tracing tool for Python programs.

Running a program through CodeInvestigator creates a recording.
Program flow, function calls, variable values and conditions are all
stored for every line the program executes.
The recording is then viewed with an interface consisting of the
code. The code can be clicked: A clicked variable displays its
value,
a clicked loop displays its iterations.
You read code, and have at your disposal all the run time details of
that code. A computerized desk check tool and another way to learn
about your program.

http://sourceforge.net/project/showfiles.php?group_id=183942
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[ANN] OpenOpt 0.27 (optimization), FuncDesigner 0.17 (auto differentiation)

2009-12-16 Thread dmitrey
Hi all,
I'm glad to inform you about release of OpenOpt 0.27 (numerical
optimization framework), FuncDesigner 0.17 (CAS with automatic
differentiation, convenient modelling of linear/nonlinear functions,
can use convenient modelling for some OpenOpt optimization problems
and systems of linear/nonlinear equations, possibly sparse or
overdetermined), DerApproximator 0.17 (finite-differences derivatives
approximation, get or check user-supplied).

These packages are written in Python language + NumPy; license BSD
allows to use it in both free and closed-code soft

See changelog for details: http://openopt.org/Changelog

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

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


Python Concurrency Workshop, January 14-15, 2010

2009-12-16 Thread David Beazley

   Python Concurrency Workshop, 2nd Edition
   with David Beazley, author Python Essential Reference
 January 14-15, 2010
  Chicago, Illinois
http://www.dabeaz.com/chicago

Last June, you might have caught my mindblowing talk on the Python
GIL (http://www.dabeaz.com/python/GIL.pdf).  However, did you see the
other eight hours of material on threads, multiprocessing, distributed
computing, coroutines, and more?  Probably not unless you were at my
Concurrency Workshop the month before.

I'm pleased to announce that that the Concurrency Workshop is back for
another round and is better than ever.  If you have been programming
Python for awhile and want to take your skills up a notch, I think
this may be of interest.  Basically, we're going to take a in-depth
look at concurrent programming idioms and library modules.  Topics
will include such things as threads, message passing, the
multiprocessing library, distributed computing idioms, coroutines,
asynchronous I/O, and other matters with an eye towards writing
programs that can run on multiple CPU cores or clusters.  A major
theme of the workshop is to explore and understand different
programming techniques, their associated performance properties, and
other tradeoffs.  You'll definitely walk away with new insight and a
better understanding of how different parts of Python work under the
covers.  Likewise, I'm hoping to gain new knowledge from your
experience.

The workshop is strictly limited to six attendees.  More details are
available at the above URL.

Please feel free to contact me with further questions.

Cheers,
Dave Beazley
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Where is PyMethod_GET_CLASS in Python 3?

2009-12-16 Thread Infinity77
Hi,

On Dec 15, 9:22 pm, Terry Reedy wrote:
 On 12/15/2009 11:08 AM, Infinity77 wrote:

  Hi All,

       When building C extensions In Python 2.X, there was a magical
  PyMethod_GET_CLASS implemented like this:

  #define PyMethod_GET_CLASS(meth) \
     (((PyMethodObject *)meth) -  im_class)

  It looks like Python 3 has wiped out the im_class attribute.

 For bound methods, renamed to __class__ to be consistent with other
 objects. Unbound methods were eliminated as extra cruft.

First of all, thank you for your answer. However, being a complete
newbie in writing C extension, I couldn't seem to find a way to do
what I asked in the first place:

Try 1:

# define PyMethod_GET_CLASS(meth) \
 (((PyMethodObject *)meth) - __class__)

error C2039: '__class__' : is not a member of 'PyMethodObject'

Try 2:

PyObject * magicClass = method - __class__

error C2039: '__class__' : is not a member of '_object'


I know I am doing something stupid, please be patient :-D . Any
suggestion is more than welcome.

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


Re: AttributeError: logging module bug ?

2009-12-16 Thread Peter Otten
Peter wrote:

 What's the problem ?
  
 Please provide the config file logging.cfg to ease debugging.

 Peter

 Here it is, thanks for having a look
 Peter

Unfortunately I still can't reproduce your problem. With a minimal file

./of/logger.py

from logging import Formatter

class RootFormatter(Formatter):
pass
class ModuleFormatter(Formatter):
pass
class ClassFormatter(Formatter):
pass
class DataFormatter(Formatter):
pass

(and an empty ./of/__init__.py) your initial script runs without error. If 
you want external help please 

(1) make sure that you provide all necessary files needed to reproduce the 
error

(2) remove as much of the code as possible that does not contribute to the 
problem. (This is also an effective debugging technique)

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


Storing a Value in a Cookie

2009-12-16 Thread Victor Subervi
Hi;
From what I've studied and gotten working about cookies, it seems one can
store only a certain few pieces of information--expiration, path, comment,
domain, max-age, version and last visit--but how is it useful if one can't
also store, say, the name of a temporary MySQL table where pertinent
customer data, such as shopping cart data, is stored? I guess I could put
that into the comment field, but I suspect there's a better way of doing it.
Please advise.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] OpenOpt 0.27 (optimization), FuncDesigner 0.17 (auto differentiation)

2009-12-16 Thread dmitrey
Hi all,
I'm glad to inform you about release of OpenOpt 0.27 (numerical
optimization framework), FuncDesigner 0.17 (CAS with automatic
differentiation, convenient modelling of linear/nonlinear functions,
can use convenient modelling for some OpenOpt optimization problems
and systems of linear/nonlinear equations, possibly sparse or
overdetermined), DerApproximator 0.17 (finite-differences derivatives
approximation, get or check user-supplied).

These packages are written in Python language + NumPy; license BSD
allows to use it in both free and closed-code soft

See changelog for details: http://openopt.org/Changelog

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


Re: Storing a Value in a Cookie

2009-12-16 Thread Chris Rebert
On Wed, Dec 16, 2009 at 1:13 AM, Victor Subervi victorsube...@gmail.com wrote:
 Hi;
 From what I've studied and gotten working about cookies, it seems one can
 store only a certain few pieces of information--expiration, path, comment,
 domain, max-age, version and last visit--but how is it useful if one can't
 also store, say, the name of a temporary MySQL table where pertinent
 customer data, such as shopping cart data, is stored? I guess I could put
 that into the comment field, but I suspect there's a better way of doing it.
 Please advise.

Besides the metadata you mentioned, a cookie can also store one
key-value pair, which is sent as the first part of the Cookie HTTP
header when setting the cookie (Cookie: name=value); this is
typically used to store a session ID.
It is inadvisable to store much data other than a session ID in a
cookie because as a rule, in order to avoid security risks, clients
should not be trusted. In the example you give of storing the name of
an SQL table, someone could guess the name of another user's SQL table
and alter their cookie to masquerade as that user, thus compromising
the other customer's shopping cart, and depending on the contents of
the SQL table, potentially their credit card.
Most web frameworks, like Django, will handle low-level details like
setting and getting cookies for you and provide a higher-level API for
dealing with sessions and/or users.

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


Spot Metals Prices (slightly OT)

2009-12-16 Thread Victor Subervi
Hi;
I need to update a client's site with spot metals prices. I could build a
scraper to grab them off someone else' site (they only need to be accurate
within 24 hours), but is there a better *free* source?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping paper, anyone ?

2009-12-16 Thread Peter Otten
simon wrote:

Nice :)

--- stars.py2009-12-16 10:52:49.553505036 +0100
+++ stars_fixed.py  2009-12-16 10:53:32.545786454 +0100
@@ -48,7 +48,9 @@
 def __init__(self):
 self.calls = []

-__getattr__ = ScribeCall
+def __getattr__(self, name):
+return ScribeCall(self, name)
+
 def run(self, ctx):
 for call in self.calls:
 #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in 
call.args))

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


Re: strptime not strict enough

2009-12-16 Thread Lie Ryan

On 12/15/2009 10:30 AM, Tobias Weber wrote:

Hi,
despite the directives for leading zero stime.strptime('09121',
'%y%m%d') returns the first of December. Shouldn't it raise ValueError?

Where do I get strict date parsing?


A bit hackish perhaps, but maybe you can check for the date's length:

date = '09121'
if len(date) == 6 and time.strptime(date, format):
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Storing a Value in a Cookie

2009-12-16 Thread Victor Subervi
On Wed, Dec 16, 2009 at 4:42 AM, Chris Rebert c...@rebertia.com wrote:

 On Wed, Dec 16, 2009 at 1:13 AM, Victor Subervi victorsube...@gmail.com
 wrote:
  Hi;
  From what I've studied and gotten working about cookies, it seems one can
  store only a certain few pieces of information--expiration, path,
 comment,
  domain, max-age, version and last visit--but how is it useful if one
 can't
  also store, say, the name of a temporary MySQL table where pertinent
  customer data, such as shopping cart data, is stored? I guess I could put
  that into the comment field, but I suspect there's a better way of doing
 it.
  Please advise.

 Besides the metadata you mentioned, a cookie can also store one
 key-value pair, which is sent as the first part of the Cookie HTTP
 header when setting the cookie (Cookie: name=value); this is
 typically used to store a session ID.
 It is inadvisable to store much data other than a session ID in a
 cookie because as a rule, in order to avoid security risks, clients
 should not be trusted. In the example you give of storing the name of
 an SQL table, someone could guess the name of another user's SQL table
 and alter their cookie to masquerade as that user, thus compromising
 the other customer's shopping cart, and depending on the contents of
 the SQL table, potentially their credit card.
 Most web frameworks, like Django, will handle low-level details like
 setting and getting cookies for you and provide a higher-level API for
 dealing with sessions and/or users.


Well, I'm not using a web framework like Django and this shopping cart is
almost completely written, so I'm not about to switch. So, how do I use the
session ID to correlate with the user's temp MySQL table?
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Cookie Values

2009-12-16 Thread Victor Subervi
On Tue, Dec 15, 2009 at 4:01 PM, Grant Edwards inva...@invalid.invalidwrote:

  On Tue, Dec 15, 2009 at 2:36 PM, MRAB pyt...@mrabarnett.plus.com
  mailto:pyt...@mrabarnett.plus.com wrote:
 
  You've just created a cookie, but are trying to get a value without
  having set it first!
 
 
  LOL! Rewrote code thus:
 
cookie = os.environ.get('HTTP_COOKIE')
if not cookie:
  cookie = Cookie.SimpleCookie()
  cExpires, cPath, cComment, cDomain, cMaxAge, cVersion = myCookie()
  cookie['lastvisit'] = str(time.time())

 cookie['lastvisit'] is a string.

  cookie['lastvisit']['expires'] = cExpires

 Here you're using the string 'expires' as an index into the
 string returned by str(time.time()).  You can only index into
 strings using integers.

 What do you expect the following statement to do?

'1260910829.18'['expires'] = whatever

  cookie['lastvisit']['path'] = cPath
  cookie['lastvisit']['comment'] = cComment
  cookie['lastvisit']['domain'] = cDomain
  cookie['lastvisit']['max-age'] = cMaxAge
  cookie['lastvisit']['version'] = cVersion
  cookieFlag = 'new'
else:
  cookieFlag = 'old'
  print cookie['lastvisit']['expires'].value
 
  Got this error:
 
   /var/www/html/angrynates.com/cart/cart.py
  http://angrynates.com/cart/cart.py
191 /html
192 '''
193
194 cart()
195
  cart = function cart
   /var/www/html/angrynates.com/cart/cart.py
  http://angrynates.com/cart/cart.py in cart()
 31   else:
 32 cookieFlag = 'old'
 33 print cookie['lastvisit']['expires'].value
 34 #  Don't know what to do with this. It's for when client won't
  accept cookies
 35 #  sessionDir = os.environ['DOCUMENT_ROOT'] + '/tmp/.session'
  cookie = 'lastvisit=1260898013.65; lastvisit=1260898315.01', ].value
  undefined
 
  TypeError: string indices must be integers
args = ('string indices must be integers',)

 You took the string returned by str(time.time()) and tried to
 use 'expires' as an index into that time string.  You can't use
 a string to index into a string.  You can only use integers.
 That's what is mean't by the error message:

TypeError: string indices must be integers


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


Re: Dangerous behavior of list(generator)

2009-12-16 Thread Michele Simionato
On Dec 14, 11:05 pm, Carl Banks pavlovevide...@gmail.com wrote:
 But to answer your question, I think simple is better than complex
 rules the day.  Right now StopIteration stops an iteration, simple as
 that.  Any fix would add complexity.

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


Dec 20 Global Python All Free SW HW Culture meeting - BerkeleyTIP

2009-12-16 Thread john_re
A great December Solstice to you  yours. :)

JOIN the Global All Free SW, HW, Culture meeting via VOIP
Dec 20 Sunday, 12N-3PM (Pacific = UTC-8) = 3P-6P Eastern = 8P-11P UTC
[Jan 2009 meetings: 2nd, 17th - mark your calendar]
http://sites.google.com/site/berkeleytip/schedule


==  WATCH some VIDEOS:
Mark Shuttleworth Interview - 10.04 Lucid Larynx
Learning from Code History , Andreas Zeller
Why does my program fail? Your version history might have the answer.
Audio Hardware Enablement Session,  UbuntuDevelopersSummit in Dallas
Distributed Development,  UDS in Dallas
Splunk,  Jeremy Thurgood  CLUG
Upstart,  Stefano Rivera  CLUG
Interfacing with the real world,  Mark Ter Morshuizen, Marc Welz CLUG
Accelerating Graphics;  Camp KDE 2009
http://sites.google.com/site/berkeleytip/talk-videos


== Join the MAILING LIST  tell us which videos you will watch  why:
http://groups.google.com/group/BerkTIPGlobal


==  JOIN the meeting via IRC  VOIP:
Come discuss any  everything,  work on your individual or group
projects.

HOT TOPICS: Ub or KUb 9.10?, Ubuntu 10.04 plans, Android, Python3000 in
2010?

Start on the #berkeleytip irc.freenode.net channel,  we'll help you get
your VOIP system up  working.  For VOIP SW,  connection info, see:
http://sites.google.com/site/berkeleytip/remote-attendance

Berkeley meeting LOCATION:  Watch the website  mail list for latest
details,  perhaps at the Berkeley Public Library, or a cafe, due to Free
Speech Cafe closed for winter break.
http://sites.google.com/site/berkeleytip/


==  OPPORTUNITIES to VOLUNTEER or learn new JOB SKILLS for 2010:
Help set up our: Mailing list, FreeSwitch VOIP server, website
http://sites.google.com/site/berkeleytip/opportunities
Inquire  discuss at the meeting.


==  For Forwarding - You are invited to forward this announcement
wherever it would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterators and views of lists

2009-12-16 Thread Bearophile
Brendan Miller:
 Currently people slice and dice with well... slices, but those are
 copying, so if you want to operate over part of a range you make a
 copy, perform the operation, then copy the results back in.

 I was thinking you'd want something like random access iterators in
 c++, or pointers in c, to write typical in place algorithmic code. To
 me, something like non-copying slices (maybe you'd call it a list
 view?) would seem functionally similar and maybe more pythonic.

There are surely ways to modify the current situation, introducing
views, and other kind of iterators (C++ design in this regard can be
improved, see the last works of Andrei Alexandrescu about D).

This can lead to a certain increase of the performance of Python
programs, but it also surely makes writing programs harder and
introduces new bug sources.

Modern languages are now doing something kinda different from what you
ask for, introducing more immutable data (that in theory lead to more
copying, but in practice allow for more data sharing too, because
there's less need to actually copy data when the data is immutable),
see Clojure. An hypothetical Python language designed today probably
copies more stuff from Haskell and Clojure.

Python is kept intentionally simple, because it's designed to be
usable by people that are not just professional programmers, but for
example a biologist that needs to perform some computations and
doesn't want to use all the time learning how to use the language
itself (think about C++ again). So Python programmers live with a less
performing language. When performance of the code is not enough (even
with the future Unladen Swallow), they use another language (often to
write extensions used from Python code).

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


Re: iterators and views of lists

2009-12-16 Thread Steven D'Aprano
On Tue, 15 Dec 2009 23:48:04 -0800, Brendan Miller wrote:

 On Tue, Dec 15, 2009 at 9:09 PM, Terry Reedy tjre...@udel.edu wrote:
 On 12/15/2009 10:39 PM, Brendan Miller wrote:
 I'm wondering if anyone has done work towards creating more powerful
 iterators for python, or creating some more pythonic equivalent.

 For sequences, integer indexes let you do anything you want that the
 container supports.
 
 No, that's what I'm getting at... Most of the existing mutating
 algorithms in python (sort, reverse) operate over entire collections,
 not partial collections delimited by indexes... which would be really
 awkward anyway.

I'm sympathetic to your request for list views. I've often wanted some 
way to cleanly and neatly do this:

for item in seq[1:]:
process(item)

without making an unnecessary copy of almost all of seq.

None of the alternatives are very nice. They all obscure the simplicity 
of the algorithm and add unnecessary effort:


for i, item in seq:
if i != 0:
process(item)


it = iter(seq)
try:
it.next()  # throw the first value away
except StopIteration:
pass
for item in it:
process(item)


if not isinstance(seq, basestring):
raise TypeError(this only works on strings)
for item in buffer(seq, 1):
process(item)


Although that last one is the least horrible, particularly if you are 
prepared to drop the explicit type-check.



 Currently people slice and dice with well... slices, but those are
 copying, so if you want to operate over part of a range you make a copy,
 perform the operation, then copy the results back in.
 
 I was thinking you'd want something like random access iterators in c++,
 or pointers in c, to write typical in place algorithmic code. To me,
 something like non-copying slices (maybe you'd call it a list view?)
 would seem functionally similar and maybe more pythonic.


Unless you have a really huge amount of data in your list, chances are 
that the cost of making a temporary copy will be relatively small. After 
all, under the hood you're just copying pointers (at least for CPython), 
not the entire data object. So most of the time the extra complexity of 
in-place algorithms is just premature optimization.

But not always.



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


Re: iterators and views of lists

2009-12-16 Thread Paul Rudin
Steven D'Aprano st...@remove-this-cybersource.com.au writes:


 I'm sympathetic to your request for list views. I've often wanted some 
 way to cleanly and neatly do this:

 for item in seq[1:]:
 process(item)

 without making an unnecessary copy of almost all of seq.


I don't know how it's implemented - but presumably itertools.islice
could provide what you're asking for?
-- 
http://mail.python.org/mailman/listinfo/python-list


platform module problem when frozen?

2009-12-16 Thread Gabriel Rossetti

Hello everyone,

I am having problems with the platform module when being run from a 
frozen program (py2exe). It imports it fine, but it gives me the 
following error :


'module' object does not contain attribute 'platform' when I do this :

platform.platfom()

Does platform have a problem with being called when in a frozen program 
or does it do some stuff behind the scenes that py2exe doesn't pickup?


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


Re: ftplib retrlines timeout

2009-12-16 Thread Brendan
On Dec 15, 6:17 pm, Jennifer owenzhang.chic...@gmail.com wrote:
 I am writing a program that has a requirement for  a timeout of
 retrlines after the connection established. I just wonder if timeout
 of ftplib.FTP('.xxx.com',username,password,timeout) will work for
 retrlines method after the connection established. Or
 socket.setdefaulttimeout will work in this case. Please let me know.

 What exception will be throwed if ftp.retrlines timed out.

 Many Thanks!

 - Jennifer

I asked a similar question on here a few days ago and got no response,
however I tried a large download which timed out with the following:
Traceback (most recent call last):
  File ./download_r1_neodf.py, line 167, in module
result = ftp.quit()
  File /usr/local/lib/python2.6/ftplib.py, line 566, in quit
resp = self.voidcmd('QUIT')
  File /usr/local/lib/python2.6/ftplib.py, line 248, in voidcmd
return self.voidresp()
  File /usr/local/lib/python2.6/ftplib.py, line 223, in voidresp
resp = self.getresp()
  File /usr/local/lib/python2.6/ftplib.py, line 209, in getresp
resp = self.getmultiline()
  File /usr/local/lib/python2.6/ftplib.py, line 195, in getmultiline
line = self.getline()
  File /usr/local/lib/python2.6/ftplib.py, line 182, in getline
line = self.file.readline()
  File /usr/local/lib/python2.6/socket.py, line 406, in readline
data = self._sock.recv(self._rbufsize)
socket.error: [Errno 110] Connection timed out


BTW, if you want to use the timeout paramter, you must also use the
account parameter. Set it to ''.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyZui - anyone know about this?

2009-12-16 Thread Daniel Fetchinson
 PyZUI 0.1 has been released:

 http://da.vidr.cc/projects/pyzui/

Cool, thanks very much!

I'm using python 2.6 these days and noticed that you use the sha
module which makes py2.6 spit out a deprecation warning:

/home/fetchinson/pyzui/pyzui/tilestore.py:22: DeprecationWarning: the
sha module is deprecated; use the hashlib module instead
  import sha

It's no big deal but if you want to be future proof maybe you can
switch to hashlib for py2.6 and stay with sha for py2.5 and before (a
try/except block would suffice).

Cheers,
Daniel


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


Re: iterators and views of lists

2009-12-16 Thread Anh Hai Trinh
On Dec 16, 10:39 am, Brendan Miller catph...@catphive.net wrote:
 I was trying to reimplement some of the c++ library of generic
 algorithms in c++ in python, but I was finding that this is
 problematic to do this in a generic way because there isn't any
 equivalent of c++'s forward iterators, random access iterators, etc.
 i.e. all python iterators are just input iterators that can't mutate
 the sequence they iterate over nor move backwards or by an arbitrary
 offset.

You might be interested in this library http://pypi.python.org/pypi/
stream.

You can easily create arbitrary slice, for example

  i = mylist  takei(primes())

will return an iterator over the items of mylist with a prime number
index, given that primes() return an iterator over prime numbers.

I'm not familiar with forward/random-access/bidirectional iterators.
-- 
http://mail.python.org/mailman/listinfo/python-list


py3.x urllib.request - HTTPCookieProcessor and header adding

2009-12-16 Thread gervaz
Hi all, I need to fetch some html pages and it is required to have
cookies enabled. So, I'm using

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor
())
urllib.request.install_opener(opener)

as a global instance. Is there a way to always use a default header
like:

{User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.1.5) Gecko/20091102 Firefox/3.5.5}

instead of always creating urllib.request.Request(my_url, None,
headers) and call different urls with the same
cookies?

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


Re: (OT) Where Are Cookies Stored?

2009-12-16 Thread Victor Subervi
On Tue, Dec 15, 2009 at 6:57 PM, r0g aioe@technicalbloke.com wrote:

 Gabriel Genellina wrote:
  En Tue, 15 Dec 2009 12:30:23 -0300, Victor Subervi
  victorsube...@gmail.com escribió:
 
  I've googled, found where cookies are supposed to be, the folders and
  files
  don't exist. I've opened my latest and greatest FF and seen cookies in
  there, but when I search for the name of the cookie in the C: dir,
  it's not
  there...anywhere. I've made sure no folders/files are hidden and I still
  can't find them. In as administrator. What up? XP OS I need to get in
  so I
  can learn how to program with cookies.
 
  How the browser stores its cookies should be irrelevant. Whenever a
  server response contains a Set-Cookie header, the browser saves the
  cookie. When the client issues a request that matches a saved cookie, it
  adds a Cookie header with the cookie. From the server POV, you don't
  care how the cookie is stored.
 


 Cookies in FF for Windows are stored in an sqlite database in here...

 ~\Application Data\Mozilla\Firefox\Profiles\%XYZ%\firefox_profile\


Man, I searched C drive (the only drive) on this computer where I'm working
(Internet cafe) for Application Data and nuttin.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Where Are Cookies Stored?

2009-12-16 Thread Victor Subervi
On Tue, Dec 15, 2009 at 6:29 PM, Steven D'Aprano 
st...@remove-this-cybersource.com.au wrote:

 On Tue, 15 Dec 2009 13:03:07 -0300, Gabriel Genellina wrote:

  En Tue, 15 Dec 2009 12:30:23 -0300, Victor Subervi
  victorsube...@gmail.com escribió:
 
  I've googled, found where cookies are supposed to be, the folders and
  files don't exist.
 [...]
  How the browser stores its cookies should be irrelevant. Whenever a
  server response contains a Set-Cookie header, the browser saves the
  cookie. When the client issues a request that matches a saved cookie, it
  adds a Cookie header with the cookie. From the server POV, you don't
  care how the cookie is stored.

 But you do care if you're writing a cookie manager, or if you need to
 grab an existing cookie from disk and do something with it (as wget
 allows you to do, for example).

 Victor, have you got Firefox set to delete all cookies when you log out?


No. I can see the *$^@ cookies in Tools/Options but I can't find 'em!
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyZui - anyone know about this?

2009-12-16 Thread r0g
David Roberts wrote:
 PyZUI 0.1 has been released:
 
 http://da.vidr.cc/projects/pyzui/
 

Cool, thanks :)

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


Re: iterators and views of lists

2009-12-16 Thread Peter Otten
Paul Rudin wrote:

 Steven D'Aprano st...@remove-this-cybersource.com.au writes:
 
 
 I'm sympathetic to your request for list views. I've often wanted some
 way to cleanly and neatly do this:

 for item in seq[1:]:
 process(item)

 without making an unnecessary copy of almost all of seq.

 
 I don't know how it's implemented - but presumably itertools.islice
 could provide what you're asking for?

For skipping just a few items islice() is perfect, for big offsets its O(N) 
behaviour may get annoying:

$ python -m timeit -sfrom itertools import islice; N=10**5; r = range(N) 
for i in islice(r, N, N): pass
100 loops, best of 3: 1.93 msec per loop

$ python -m timeit -sfrom itertools import islice; N=10**6; r = range(N) 
for i in islice(r, N, N): pass
10 loops, best of 3: 18.9 msec per loop

$ python -m timeit -sfrom itertools import islice; N=10**7; r = range(N) 
for i in islice(r, N, N): pass
10 loops, best of 3: 188 msec per loop

islice() could be changed to special-case lists and tuples, but that feels a 
bit unclean.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping paper, anyone ?

2009-12-16 Thread r0g
Peter Otten wrote:
 simon wrote:
 
 Nice :)
 
 --- stars.py2009-12-16 10:52:49.553505036 +0100
 +++ stars_fixed.py  2009-12-16 10:53:32.545786454 +0100
 @@ -48,7 +48,9 @@
  def __init__(self):
  self.calls = []
 
 -__getattr__ = ScribeCall
 +def __getattr__(self, name):
 +return ScribeCall(self, name)
 +
  def run(self, ctx):
  for call in self.calls:
  #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in 
 call.args))
 
 Peter


Nice :) Now all I need is an A0 printer, maybe Santa will bring me one!

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


Raw string substitution problem

2009-12-16 Thread Ed Keith
I am having a problem when substituting a raw string. When I do the following:

re.sub('abc', r'a\nb\nc', '123abcdefg')

I get


123a
b
cdefg


what I want is 

r'123a\nb\ncdefg'

How do I get what I want?

Thanks,

-EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com


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


Re: iterators and views of lists

2009-12-16 Thread Carl Banks
On Dec 15, 11:48 pm, Brendan Miller catph...@catphive.net wrote:
 I was thinking you'd want something like random access iterators in
 c++, or pointers in c, to write typical in place algorithmic code. To
 me, something like non-copying slices (maybe you'd call it a list
 view?) would seem functionally similar and maybe more pythonic.


My general answer to the question, Has anyone done any work in Python
to get a certain feature that we have in C++?, is, There's little
demand for many features of C++ because they are actually workarounds
for the language's poor expressibility.  I'd say that's kind of the
case here.

C++ is poorly expressive (container operations are often an excercise
in line-noise-management), and values fine-tuned optimization.  So it
makes sense to offer things like mutator views that reduce the number
of container operations needed, and avoids copying.

Python expresses container operations succinctly and clearly, and
doesn't value performance as much.  Copying and replacing is good
enough most of the time, so there's less demand for things like
mutator views.


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


Re: iterators and views of lists

2009-12-16 Thread Daniel Stutzbach
On Wed, Dec 16, 2009 at 7:33 AM, Peter Otten __pete...@web.de wrote:

 islice() could be changed to special-case lists and tuples, but that feels
 a
 bit unclean.


How about special-casing objects that implement collections.Sequence?

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC http://stutzbachenterprises.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterators and views of lists

2009-12-16 Thread Daniel Stutzbach
On Wed, Dec 16, 2009 at 5:39 AM, Steven D'Aprano 
st...@remove-this-cybersource.com.au wrote:

 for item in seq[1:]:
process(item)

 without making an unnecessary copy of almost all of seq.


I use the following idiom:
for i in range(1, len(seq)):
process(seq[i])

Alternately, if I'm using the blist extension type that I wrote, then
seq[1:] is O(log n).
http://pypi.python.org/pypi/blist/

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC http://stutzbachenterprises.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with gettext and msgfmt

2009-12-16 Thread JKPeck
On Dec 15, 9:12 pm, JKPeck jkp...@gmail.com wrote:
 I'm using Python 2.6 on Windows and having trouble with the charset in
 gettext.  It seems to be so broken that I must be missing something.

 When I run msgfmt.py, as far as I can see it writes no charset
 information into the mo file.  The actual po files are in utf-8 in
 this case and have a charset declaration.

 Then when ,_parse in gettext loads the messages, it does no conversion
 to Unicode, because it has no charset information.  So the message
 dictionary is actually in utf-8 despite the comment in the code
 # Note: we unconditionally convert both msgids and msgstrs to
             # Unicode using the character encoding specified in the
 charset
             # parameter of the Content-Type header.

 Then ugettext tries to just return the translated message, which is
 not in Unicode, or to convert to Unicode, which fails because the
 unicode call is not specifying any encoding.

 The _parse code seems to expect to produce a Unicode translation
 dictionary, and gettext expects to encode Unicode into the current
 code page, but the message dictionary never gets mapped to Unicode in
 the first place.

 What I want is simply to use utf-8 po files and get translations in
 Unicode.

 TIA for any suggestions.

 -Jon Peck

Never mind.  I figured this out.  The problem is that a line such as
_()
in the source that is scanned causes all the meta information to be
lost in the mo file.  Once I changed that code, I get the expected
result.

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


Re: Object Relational Mappers are evil (a meditation)

2009-12-16 Thread J Kenneth King
Steven D'Aprano st...@remove-this-cybersource.com.au writes:

 On Fri, 11 Dec 2009 19:20:21 -0500, Steve Holden wrote:

 Simon Forman wrote:
 [...]
 As far as the OP rant goes, my $0.02:  bad programmers will write bad
 code in any language, with any tool or system or environment they're
 given.  If you want to avoid bad code there's (apparently) no
 substitute for smrt programmers who are familiar with the tools they're
 using, not just the syntax but the underlying conceptual models as
 well.
 
 Hear, hear!

 That's all very well, but some languages and techniques encourage the 
 programmer to write bad code.

That's just BS.

Bad code doesn't just write itself.  Programmers write bad code.  And
ignorance is not an excuse.

Just because a language allows a programmer to write sloppy code doesn't
put the language at fault for the bad code programmers write with it.
Any half-way decent programmer should be cognisant of when they're
writing bad code and when they're writing good code.  They should be
able to admit that they don't know enough about a language to be writing
programs for money in it.  They should be able to see anti-patterns and
areas of their code that should be re-factored or re-written.

The real underlying problem is the human characteristic that allows us
to let ourselves believe that we're better than everyone else or more
simply, better than we really are.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Raw string substitution problem

2009-12-16 Thread Gabriel Genellina

En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith e_...@yahoo.com escribió:

I am having a problem when substituting a raw string. When I do the  
following:


re.sub('abc', r'a\nb\nc', '123abcdefg')

I get


123a
b
cdefg


what I want is

r'123a\nb\ncdefg'


From http://docs.python.org/library/re.html#re.sub

re.sub(pattern, repl, string[, count])

...repl can be a string or a function; if
it is a string, any backslash escapes in
it are processed. That is, \n is converted
to a single newline character, \r is
converted to a linefeed, and so forth.

So you'll have to double your backslashes:

py re.sub('abc', r'a\\nb\\nc', '123abcdefg')
'123a\\nb\\ncdefg'

--
Gabriel Genellina

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


Re: Raw string substitution problem

2009-12-16 Thread Chris Hulan
On Dec 16, 9:09 am, Ed Keith e_...@yahoo.com wrote:
 I am having a problem when substituting a raw string. When I do the following:

 re.sub('abc', r'a\nb\nc', '123abcdefg')

 I get

 
 123a
 b
 cdefg
 

 what I want is

 r'123a\nb\ncdefg'

 How do I get what I want?

 Thanks,

     -EdK

 Ed Keith
 e_...@yahoo.com

 Blog: edkeith.blogspot.com

Looks like raw strings lets you avoid having to escape slashes when
specifying the literal, but doesn't preserve it during operations.
changing your replacement string to r'a\\nb\\nc' seems to give the
desired output

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


Re: power of explicit self?

2009-12-16 Thread Gabriel Genellina
Fire Crow m...@firecrow.com:

  Nowhere, I'd say. An *implicit* self would have to be implemented
  somewhere in the compiler -- but an explicit self doesn't. It's
  homogeneous, always name-dot-attribute; the name 'self' is not special at
  all.

 This is I find very interesting, If I understand your comment
 correctly,
 one of the advantages of implicit self is that it does not need

 any special treatment, it's handled like any other name-dot-attribute.


Yes.

-- 
Gabriel Genellina


  Yahoo! Cocina

Encontra las mejores recetas con Yahoo! Cocina.


http://ar.mujer.yahoo.com/cocina/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping paper, anyone ?

2009-12-16 Thread simon
On Dec 16, 9:00 pm, Peter Otten __pete...@web.de wrote:
 simon wrote:

 Nice :)

 --- stars.py    2009-12-16 10:52:49.553505036 +0100
 +++ stars_fixed.py      2009-12-16 10:53:32.545786454 +0100
 @@ -48,7 +48,9 @@
      def __init__(self):
          self.calls = []

 -    __getattr__ = ScribeCall
 +    def __getattr__(self, name):
 +        return ScribeCall(self, name)
 +
      def run(self, ctx):
          for call in self.calls:
              #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in
 call.args))

 Peter

Oh.. I'm on py2.5.. does this not work for you ?

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


Re: Wrapping paper, anyone ?

2009-12-16 Thread simon
On Dec 17, 12:36 am, r0g aioe@technicalbloke.com wrote:
 Peter Otten wrote:
  simon wrote:

  Nice :)

  --- stars.py    2009-12-16 10:52:49.553505036 +0100
  +++ stars_fixed.py      2009-12-16 10:53:32.545786454 +0100
  @@ -48,7 +48,9 @@
       def __init__(self):
           self.calls = []

  -    __getattr__ = ScribeCall
  +    def __getattr__(self, name):
  +        return ScribeCall(self, name)
  +
       def run(self, ctx):
           for call in self.calls:
               #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in
  call.args))

  Peter

 Nice :) Now all I need is an A0 printer, maybe Santa will bring me one!

 Roger.

I found I could wrap a CD in A4 paper... for bigger things, i might
stick some A4 paper together.

Wow. Who is getting the A0 gift ?


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


Re: power of explicit self?

2009-12-16 Thread Grant Edwards
On 2009-12-16, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
 Fire Crow m...@firecrow.com:

  Nowhere, I'd say. An *implicit* self would have to be implemented
  somewhere in the compiler -- but an explicit self doesn't. It's
  homogeneous, always name-dot-attribute; the name 'self' is not special at
  all.

 This is I find very interesting, If I understand your comment
 correctly, one of the advantages of implicit self is that it
 does not need any special treatment, it's handled like any
 other name-dot-attribute.

 Yes.

I presume you both meant that is an advantage of explicit self
not implicit?

-- 
Grant Edwards   grante Yow! What's the MATTER
  at   Sid? ... Is your BEVERAGE
   visi.comunsatisfactory?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: platform module problem when frozen?

2009-12-16 Thread Dave Angel



Gabriel Rossetti wrote:
div class=moz-text-flowed style=font-family: -moz-fixedHello 
everyone,


I am having problems with the platform module when being run from a 
frozen program (py2exe). It imports it fine, but it gives me the 
following error :


'module' object does not contain attribute 'platform' when I do this :

platform.platfom()

Does platform have a problem with being called when in a frozen 
program or does it do some stuff behind the scenes that py2exe doesn't 
pickup?


Thank you,
Gabriel

/div

Chances are that there is another module platform which is being 
picked up instead of the one in the library.  Have you tried printing  
platform.__file__  ??


If it's getting the wrong one, you probably have a search-order problem.

DaveA

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


basic grammer error..

2009-12-16 Thread codefly
class codefly:

 def WaitFreecatz(self, hours):
 hours = self.hours
 i = 1
 while i  hours:
  print 'i wait %s hours' %(i)
  i = i+1
 if i == hours:
  print '\nhe never comes'


run error// what's wrong??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapping paper, anyone ?

2009-12-16 Thread Peter Otten
simon wrote:

 On Dec 16, 9:00 pm, Peter Otten __pete...@web.de wrote:
 simon wrote:

 Nice :)

 --- stars.py2009-12-16 10:52:49.553505036 +0100
 +++ stars_fixed.py  2009-12-16 10:53:32.545786454 +0100
 @@ -48,7 +48,9 @@
 def __init__(self):
 self.calls = []

 -__getattr__ = ScribeCall
 +def __getattr__(self, name):
 +return ScribeCall(self, name)
 +
 def run(self, ctx):
 for call in self.calls:
 #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in
 call.args))

 Peter
 
 Oh.. I'm on py2.5.. does this not work for you ?

You mean 2.4? Here's a little demo:

$ cat scribecall.py
class ScribeCall(object):
def __init__(self, scribe, name):
print init, scribe, name
def __call__(self, *args, **kw):
print call, args, kw

class Scribe(object):
__getattr__ = ScribeCall

if __name__ == __main__:
scribe = Scribe()
scribe.yadda(42)

$ python2.4 scribecall.py
init __main__.Scribe object at 0x7fc87b9a1450 yadda
call (42,) {}

$ python2.5 scribecall.py
Traceback (most recent call last):
  File scribecall.py, line 12, in module
scribe.yadda(42)
TypeError: __init__() takes exactly 3 arguments (2 given)

$ python2.5 -V
Python 2.5.4

$ python2.6 scribecall.py
Traceback (most recent call last):
  File scribecall.py, line 12, in module
scribe.yadda(42)
TypeError: __init__() takes exactly 3 arguments (2 given)

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


Re: basic grammer error..

2009-12-16 Thread Diez B. Roggisch
codefly wrote:

 class codefly:
 
  def WaitFreecatz(self, hours):
  hours = self.hours
  i = 1
  while i  hours:
   print 'i wait %s hours' %(i)
   i = i+1
  if i == hours:
   print '\nhe never comes'
 
 
 run error// what's wrong??

Next time, be so kind to tell us what the actual error *is*, will you?

Because there is none for me after c'n'p-ing that code into a source-file...

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


Re: Object Relational Mappers are evil (a meditation)

2009-12-16 Thread r0g
J Kenneth King wrote:
 Steven D'Aprano st...@remove-this-cybersource.com.au writes:
 
 On Fri, 11 Dec 2009 19:20:21 -0500, Steve Holden wrote:

snip

 Hear, hear!
 That's all very well, but some languages and techniques encourage the 
 programmer to write bad code.
 
 That's just BS.
 
 Bad code doesn't just write itself.  Programmers write bad code.  And
 ignorance is not an excuse.
 
 Just because a language allows a programmer to write sloppy code doesn't
 put the language at fault for the bad code programmers write with it.



Okay, as long as you realize the corollary of your argument is:

It is impossible for a language to encourage programmers to write good
code and promote good programming practices by design.

I'm not sure that's entirely true either.

I think python's one way to do something design philosophy goes some
way toward that, as does Smalltalk's enforced message passing. I think
PHP's superglobals and namespacing encourage bad practices (or used to
back in the day), as do Basic's GOTO and Ecmascript's prototype overriding.

Surely a language CAN be said to encourage kludges and sloppiness if it
allows a good way and a bad way and makes the bad way much easier to
implement or understand for noobs.

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


Re: Wrapping paper, anyone ?

2009-12-16 Thread r0g
simon wrote:
 On Dec 17, 12:36 am, r0g aioe@technicalbloke.com wrote:
 Peter Otten wrote:
 simon wrote:
 Nice :)
 --- stars.py2009-12-16 10:52:49.553505036 +0100
 +++ stars_fixed.py  2009-12-16 10:53:32.545786454 +0100
 @@ -48,7 +48,9 @@
  def __init__(self):
  self.calls = []
 -__getattr__ = ScribeCall
 +def __getattr__(self, name):
 +return ScribeCall(self, name)
 +
  def run(self, ctx):
  for call in self.calls:
  #print ctx.%s(%s) % (call.name, ', '.join(str(x) for x in
 call.args))
 Peter
 Nice :) Now all I need is an A0 printer, maybe Santa will bring me one!

 Roger.
 
 I found I could wrap a CD in A4 paper... for bigger things, i might
 stick some A4 paper together.
 
 Wow. Who is getting the A0 gift ?
 
 



I was thinking of selling it, this is BSD licensed right! ;D

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


Re: (OT) Where Are Cookies Stored?

2009-12-16 Thread Dave Angel



Victor Subervi wrote:

On Tue, Dec 15, 2009 at 6:57 PM, r0g aioe@technicalbloke.com wrote:

snip

Cookies in FF for Windows are stored in an sqlite database in here...

~\Application Data\Mozilla\Firefox\Profiles\%XYZ%\firefox_profile\




Man, I searched C drive (the only drive) on this computer where I'm working
(Internet cafe) for Application Data and nuttin.
V

  
How are you searching?  Microsoft is so sure we don't want to see the 
gory details that they hide all sorts of things, by default.  And 
especially on a public computer, you shouldn't even look with Explorer.  
As for searching with Explorer, there are not only design problems, but 
bugs as well.  Get a command line, and do something like:


dir  /s  c:\Firefox

if you search directly for Application Data, you have to be sure to 
properly use quotes.  You also need to add the /ah switch, since it's a 
hidden directory.  So I cheat by searching for a subdirectory under it.


You can also find the appdata directory by looking at the environment 
variable USERPROFILE, switching to that directory, and descending 
directly into application data by using the tab key.


C:\set USERPROFILE
USERPROFILE=C:\Documents and Settings\davea

C:\cd Documents and Settings\davea

C:\Documents and Settings\daveacd Application Data

I got the last line by typingcd app   then pressing the tab key 
(this adds the quotes and spaces for me)


Anyway, once you're in the Firefox directory, do:

C:\Documents and Settings\davea\Application Data\Mozilla\Firefoxdir /s 
cook*


and you'll see the actual file.

You can also search for it from the root, but I have 13 files 
cookies.*   and 8  cookies.sqlite


Incidentally, lots of interesting stuff is in the USERPROFILE directory, 
so it's a good thing to know how to quickly find.  Different versions of 
Windows put it different places, but it ends with the logged-in user 
name.  So user-specific data is typically stored there.  Some versions 
of Python even include a directory under it in the sys.path directory list.


DaveA

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


Re: basic grammer error..

2009-12-16 Thread codefly
On 12월17일, 오전12시23분, Diez B. Roggisch de...@nospam.web.de wrote:
 codefly wrote:
  class codefly:

   def WaitFreecatz(self, hours):
   hours = self.hours
   i = 1
   while i  hours:
print 'i wait %s hours' %(i)
i = i+1
   if i == hours:
print '\nhe never comes'

  run error// what's wrong??

 Next time, be so kind to tell us what the actual error *is*, will you?

 Because there is none for me after c'n'p-ing that code into a source-file...

 Diez

Thank you Sir.^^
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: power of explicit self?

2009-12-16 Thread Gabriel Genellina
En Wed, 16 Dec 2009 11:56:17 -0300, Grant Edwards  
inva...@invalid.invalid escribió:

On 2009-12-16, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:

Fire Crow m...@firecrow.com:


 Nowhere, I'd say. An *implicit* self would have to be implemented
 somewhere in the compiler -- but an explicit self doesn't. It's
 homogeneous, always name-dot-attribute; the name 'self' is not  
special at

 all.



This is I find very interesting, If I understand your comment
correctly, one of the advantages of implicit self is that it
does not need any special treatment, it's handled like any
other name-dot-attribute.


Yes.


I presume you both meant that is an advantage of explicit self
not implicit?


Yes, sorry, the advantage of an *explicit* self is being homogeneous.

--
Gabriel Genellina

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


i re-write it

2009-12-16 Thread codefly
error message is here..
when i type import code2

Traceback (most recent call last):
  File stdin, line 1, in module
  File code2.py, line 11
~
   ^
SyntaxError: invalid syntax


and source code is here
class codefly:
  def WaitFreecatz(self, hours):
  hours = self.hours
  i =1
  while i  hours:
print ' i wait for %s hours' %(i)
i = i+1
  if i ==hours:
print 'he never comes'


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


Re: Subclassing RegexObject

2009-12-16 Thread Peter Otten
Tobias Weber wrote:

 how do I subclass or at least add a method to something returned by
 re.compile()?

Let's see:

 import re
 r = re.compile(yadda)
 class S(type(r)): pass
...
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: Error when calling the metaclass bases
type '_sre.SRE_Pattern' is not an acceptable base type

So I'm afraid you can't subclass...

 def hello(self): print hello
...
 type(r).hello = hello
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can't set attributes of built-in/extension type 
'_sre.SRE_Pattern'
 r.hello = hello
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: '_sre.SRE_Pattern' object has no attribute 'hello'

...nor add a method...

 class W(object):
... def __init__(self, match):
... self._match = match
... def __getattr__(self, name):
... return getattr(self._match, name)
... hello = hello
...
 def my_compile(*args, **kw):
... m = original_compile(*args, **kw)
... if m is not None:
... return W(m)
...
 original_compile = re.compile
 re.compile = my_compile
 re.compile(yadda).hello()
hello

...but alter the meaning of something returned by re.compile() you can. 
Now who would want to do that? And why?

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


Re: i re-write it

2009-12-16 Thread Diez B. Roggisch
codefly wrote:

 error message is here..
 when i type import code2
 
 Traceback (most recent call last):
   File stdin, line 1, in module
   File code2.py, line 11
 ~
^
 SyntaxError: invalid syntax
 
 
 and source code is here

No, it isn't. The above error says line 11, but the code you show doesn't
have 11 lines.

From the above error, it looks as if you have a stray tilde-character on
the last or so line in code.py. Remove it.

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


Re: i re-write it

2009-12-16 Thread codefly
On Dec 17, 12:43 am, Diez B. Roggisch de...@nospam.web.de wrote:
 codefly wrote:
  error message is here..
  when i type import code2

  Traceback (most recent call last):
    File stdin, line 1, in module
    File code2.py, line 11
      ~
                         ^
  SyntaxError: invalid syntax

  and source code is here

 No, it isn't. The above error says line 11, but the code you show doesn't
 have 11 lines.

 From the above error, it looks as if you have a stray tilde-character on
 the last or so line in code.py. Remove it.

 Diez

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


Re: (OT) Where Are Cookies Stored?

2009-12-16 Thread David Robinow
On Wed, Dec 16, 2009 at 10:33 AM, Dave Angel da...@ieee.org wrote:
 You can also find the appdata directory by looking at the environment
 variable USERPROFILE, switching to that directory, and descending directly
 into application data by using the tab key.
 ...
Lots of good advice. I'd just point out that there's an APPDATA
environment variable, which is usually but not necessarily the
Application Data directory under USERPROFILE.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (OT) Where Are Cookies Stored?

2009-12-16 Thread Victor Subervi
On Wed, Dec 16, 2009 at 11:33 AM, Dave Angel da...@ieee.org wrote:



 Victor Subervi wrote:

 On Tue, Dec 15, 2009 at 6:57 PM, r0g aioe@technicalbloke.com wrote:

 snip

  Cookies in FF for Windows are stored in an sqlite database in here...

 ~\Application Data\Mozilla\Firefox\Profiles\%XYZ%\firefox_profile\




 Man, I searched C drive (the only drive) on this computer where I'm
 working
 (Internet cafe) for Application Data and nuttin.
 V



 How are you searching?  Microsoft is so sure we don't want to see the gory
 details that they hide all sorts of things, by default.  And especially on a
 public computer, you shouldn't even look with Explorer.  As for searching
 with Explorer, there are not only design problems, but bugs as well.  Get a
 command line, and do something like:

dir  /s  c:\Firefox

 if you search directly for Application Data, you have to be sure to
 properly use quotes.  You also need to add the /ah switch, since it's a
 hidden directory.  So I cheat by searching for a subdirectory under it.

 You can also find the appdata directory by looking at the environment
 variable USERPROFILE, switching to that directory, and descending directly
 into application data by using the tab key.

 C:\set USERPROFILE
 USERPROFILE=C:\Documents and Settings\davea

 C:\cd Documents and Settings\davea

 C:\Documents and Settings\daveacd Application Data

 I got the last line by typingcd app   then pressing the tab key (this
 adds the quotes and spaces for me)

 Anyway, once you're in the Firefox directory, do:

 C:\Documents and Settings\davea\Application Data\Mozilla\Firefoxdir /s
 cook*

 and you'll see the actual file.

 You can also search for it from the root, but I have 13 files cookies.*
 and 8  cookies.sqlite

 Incidentally, lots of interesting stuff is in the USERPROFILE directory, so
 it's a good thing to know how to quickly find.  Different versions of
 Windows put it different places, but it ends with the logged-in user name.
  So user-specific data is typically stored there.  Some versions of Python
 even include a directory under it in the sys.path directory list.


That was great! Thanks, Dave!
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i re-write it

2009-12-16 Thread codefly
On Dec 17, 12:43 am, Diez B. Roggisch de...@nospam.web.de wrote:
 codefly wrote:
  error message is here..
  when i type import code2

  Traceback (most recent call last):
    File stdin, line 1, in module
    File code2.py, line 11
      ~
                         ^
  SyntaxError: invalid syntax

  and source code is here

 No, it isn't. The above error says line 11, but the code you show doesn't
 have 11 lines.

 From the above error, it looks as if you have a stray tilde-character on
 the last or so line in code.py. Remove it.

 Diez

now.. another problem..

when i type me = code2()

the error is here..
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'module' object is not callable


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


another problem..

2009-12-16 Thread codefly
now.. another problem..
when i type me = code2()
the error is here..
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'module' object is not callable
-- 
http://mail.python.org/mailman/listinfo/python-list


I have a cross platform os.startfile but I need to asociate files with xdg-open in linux how do I do that??

2009-12-16 Thread eric_dex...@msn.com
#this should be a cross platform example of os.startfile ( startfile )
#for windows and linux.  this is the first version and
#linux, mac, other os's commands for exceptions to the
#rule would be appreciated.  at some point this will be
#in the dex tracker project.

import os
import subprocess

def startfile(filename)
  try:
 os.startfile(filename)
  except:
 subprocess.Popen(['xdg-open', filename])


___
http://dextracker.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Imaging Library status

2009-12-16 Thread paulo.jpi...@gmail.com
Hi guys,

is the famous PIL now a dead project?

Latest available download is from 2006 and I still don't see any signs
of having it updated for Python 2.6 or 3.x versions.

Thanks in Advance,
Paulo

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


Re: basic grammer error..

2009-12-16 Thread Dave Angel

codefly wrote:

class codefly:

 def WaitFreecatz(self, hours):
 hours = self.hours
 i = 1
 while i  hours:
  print 'i wait %s hours' %(i)
  i = i+1
 if i == hours:
  print '\nhe never comes'


run error// what's wrong??

  
You can't get a runtime error there, because nothing instantiates the 
class, nor calls its method.  Once you add that code, you'll find an 
uninitialized instance attribute, plus a couple of logic errors.


So, if you actually have a question, how about stating it completely?   
Given a complete code sample, you run it (on what version of what 
computer language, on what OS), and you get some error (show complete 
traceback).  Explain what you tried, to identify the error, and then 
state what has you stumped.


And if you don't get a Python error, but get the wrong results, then 
state what you expected, and what you got.


DaveA

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


Re: i re-write it

2009-12-16 Thread Diez B. Roggisch
codefly wrote:

 On Dec 17, 12:43 am, Diez B. Roggisch de...@nospam.web.de wrote:
 codefly wrote:
  error message is here..
  when i type import code2

  Traceback (most recent call last):
  File stdin, line 1, in module
  File code2.py, line 11
  ~
  ^
  SyntaxError: invalid syntax

  and source code is here

 No, it isn't. The above error says line 11, but the code you show
 doesn't have 11 lines.

 From the above error, it looks as if you have a stray tilde-character
 on the last or so line in code.py. Remove it.

 Diez
 
 now.. another problem..
 
 when i type me = code2()
 
 the error is here..
 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'module' object is not callable

Not surprisingly, because you try to instantiate a module. Which isn't
possible.

What you most probably want is 

  me = code2.codefly()

May I suggest you move your questions here:

http://mail.python.org/mailman/listinfo/tutor

It seems that you have some very basic misconceptions about python, so that
might be a forum more geared towards your needs.

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


Re: Wrapping paper, anyone ?

2009-12-16 Thread bartc


simon pianomaes...@gmail.com wrote in message 
news:a50b1c21-287b-498d-a8c3-51a3a2f94...@k9g2000vbl.googlegroups.com...

#!/usr/bin/env python

from math import *

from random import *

import cairo
from cairo import Context


What's cairo?


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


Re: basic grammer error..

2009-12-16 Thread Bruno Desthuilliers

codefly a écrit :

class codefly:

 def WaitFreecatz(self, hours):
 hours = self.hours
 i = 1
 while i  hours:
  print 'i wait %s hours' %(i)
  i = i+1
 if i == hours:
  print '\nhe never comes'


run error// what's wrong??


wrt/ the code : bad capitalisation on the class name and method name, 
access to an inexistant attribute, useless param 'hours' (not used), 
failure to use the appropriate iteration construct.


wrt/ your post: failure to post both the full traceback and the minimal 
required code to produce this traceback.


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


Re: I have a cross platform os.startfile but I need to asociate files with xdg-open in linux how do I do that??

2009-12-16 Thread Paul Boddie
On 16 Des, 17:03, eric_dex...@msn.com eric_dex...@msn.com wrote:
 #this should be a cross platform example of os.startfile ( startfile )
 #for windows and linux.  this is the first version and
 #linux, mac, other os's commands for exceptions to the
 #rule would be appreciated.  at some point this will be
 #in the dex tracker project.

You could look at the desktop package for something similar:

http://pypi.python.org/pypi/desktop

The desktop.open function supports a few extra workarounds, mostly
because it pre-dates xdg-open.

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


Re: i re-write it

2009-12-16 Thread Bruno Desthuilliers

codefly a écrit :

now.. another problem..

when i type me = code2()


where ? and what is 'code2' in this context ? Sorry, my crystal ball is 
out for repair...



the error is here..
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'module' object is not callable



Ok, so it's in the python shell, you imported your module named 'code2', 
and tried to call it.


Well... the error message say it all: module objects are not callable 
(IOW : they are not functions). If I may ask : what's your background in 
programming ?










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


Re: another problem..

2009-12-16 Thread Dave Angel



codefly wrote:

now.. another problem..
when i type me = code2()
the error is here..
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'module' object is not callable

  
By creating a new thread for each new question, you're forcing yourself 
to repeat the code and environment answers, which you did not.  So let's 
ignore this thread, and I'll respond on the previous one.


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


Re: i re-write it

2009-12-16 Thread Dave Angel



codefly wrote:

On Dec 17, 12:43 am, Diez B. Roggisch de...@nospam.web.de wrote:
  

codefly wrote:


error message is here..
when i type import code2
  
Traceback (most recent call last):

  File stdin, line 1, in module
  File code2.py, line 11
~
   ^
SyntaxError: invalid syntax
  
and source code is here
  

No, it isn't. The above error says line 11, but the code you show doesn't
have 11 lines.

From the above error, it looks as if you have a stray tilde-character on
the last or so line in code.py. Remove it.

Diez



now.. another problem..

when i type me = code2()

the error is here..
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'module' object is not callable


  


Your code was/is in code2.py
-

class codefly:
 def WaitFreecatz(self, hours):
 hours = self.hours
 i =1
 while i  hours:
   print ' i wait for %s hours' %(i)
   i = i+1
 if i ==hours:
   print 'he never comes'

-

The message is pretty clear.  Why are you trying to call the module you 
just imported?  Perhaps you meant to instantiate the class that was 
defined there.  In that case, the syntax would be:

   me = code2.codefly()

To save you some trouble on your next bug, let me point out that your 
class does not initialize its instance variable  self.hoursThat's 
normally done in the __init__() method.  Also, you can interactively see 
the objects of an object with the dir() function.  So try  
dir(code2) dir(code2.codefly)and  dir(me)


DaveA


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


Re: Wrapping paper, anyone ?

2009-12-16 Thread r0g
bartc wrote:
 
 simon pianomaes...@gmail.com wrote in message
 news:a50b1c21-287b-498d-a8c3-51a3a2f94...@k9g2000vbl.googlegroups.com...
 #!/usr/bin/env python

 from math import *

 from random import *

 import cairo
 from cairo import Context
 
 What's cairo?
 
 


A vector graphics library.

http://en.wikipedia.org/wiki/Cairo_(graphics)

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


regex help

2009-12-16 Thread Gabriel Rossetti

Hello everyone,

I'm going nuts with some regex, could someone please show me what I'm 
doing wrong?


I have an XMPP msg :

message xmlns='jabber:client' to='n...@host.com'
   mynode xmlns='myprotocol:core' version='1.0' type='mytype'
   parameters
   param1123/param1
   param2456/param2
   /parameters
   payload type='plain'.../payload
   /mynode
   x xmlns='jabber:x:expire' seconds='15'/
/message

the parameter node may be absent or empty (parameter/), the x node 
may be absent. I'd like to grab everything exept the payload nod and 
create something new using regex, with the XMPP message example above 
I'd get this :


message xmlns='jabber:client' to='n...@host.com'
   mynode xmlns='myprotocol:core' version='1.0' type='mytype'
   parameters
   param1123/param1
   param2456/param2
   /parameters
   /mynode
   x xmlns='jabber:x:expire' seconds='15'/
/message

for some reason my regex doesn't work correctly :

r(message .*?).*?(mynode 
.*?).*?(?:(parameters.*?/parameters)|parameters/)?.*?(x .*/)?


I group the opening message node, the opening mynode node and if the 
parameters node is present and not empty I group it and if the x 
node is present I group it. For some reason this doesn't work correctly :


 import re
 s1 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' 
type='mytype'parametersparam1123/param1param2456/param2/parameterspayload 
type='plain'.../payload/mynodex xmlns='jabber:x:expire' 
seconds='15'//message
 s2 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' 
type='mytype'parameters/payload 
type='plain'.../payload/mynodex xmlns='jabber:x:expire' 
seconds='15'//message
 s3 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' type='mytype'payload 
type='plain'.../payload/mynodex xmlns='jabber:x:expire' 
seconds='15'//message
 s4 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' 
type='mytype'parametersparam1123/param1param2456/param2/parameterspayload 
type='plain'.../payload/mynode/message
 s5 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' 
type='mytype'parameters/payload 
type='plain'.../payload/mynode/message
 s6 = message xmlns='jabber:client' to='n...@host.com'mynode 
xmlns='myprotocol:core' version='1.0' type='mytype'payload 
type='plain'.../payload/mynode/message
 exp = r(message .*?).*?(mynode 
.*?).*?(?:(parameters.*?/parameters)|parameters/)?.*?(x .*/)?


 re.match(exp, s1).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', 
'parametersparam1123/param1param2456/param2/parameters', None)


 re.match(exp, s2).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', None, None)


 re.match(exp, s3).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', None, None)


 re.match(exp, s4).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', 
'parametersparam1123/param1param2456/param2/parameters', None)


 re.match(exp, s5).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', None, None)


 re.match(exp, s6).groups()
(message xmlns='jabber:client' to='n...@host.com', mynode 
xmlns='myprotocol:core' version='1.0' type='mytype', None, None)




Does someone know what is wrong with my expression? Thank you, Gabriel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Raw string substitution problem

2009-12-16 Thread Ed Keith
--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:

 From: Gabriel Genellina gagsl-...@yahoo.com.ar
 Subject: Re: Raw string substitution problem
 To: python-list@python.org
 Date: Wednesday, December 16, 2009, 9:35 AM
 En Wed, 16 Dec 2009 11:09:32 -0300,
 Ed Keith e_...@yahoo.com
 escribió:
 
  I am having a problem when substituting a raw string.
 When I do the following:
  
  re.sub('abc', r'a\nb\nc', '123abcdefg')
  
  I get
  
  
  123a
  b
  cdefg
  
  
  what I want is
  
  r'123a\nb\ncdefg'
 
 From http://docs.python.org/library/re.html#re.sub
 
     re.sub(pattern, repl, string[, count])
 
     ...repl can be a string or a function;
 if
     it is a string, any backslash escapes
 in
     it are processed. That is, \n is
 converted
     to a single newline character, \r is
     converted to a linefeed, and so forth.
 
 So you'll have to double your backslashes:
 
 py re.sub('abc', r'a\\nb\\nc', '123abcdefg')
 '123a\\nb\\ncdefg'
 
 --Gabriel Genellina
 
 --http://mail.python.org/mailman/listinfo/python-list
 

That is going to be a nontrivial exercise. I have control over the pattern, but 
the texts to be substituted and substituted into will be read from user 
supplied files. I need to reproduce the exact text the is read from the file. 

Maybe what I should do is use re to break the string into two pieces, the part 
before the pattern to be replaces and the part after it, then splice the 
replacement text in between them. Seems like doing it the hard way, but it 
should work. 

Thanks,

   -EdK



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


Re: regex help

2009-12-16 Thread r0g
Gabriel Rossetti wrote:
 Hello everyone,
 
 I'm going nuts with some regex, could someone please show me what I'm
 doing wrong?
 
 I have an XMPP msg :
 
snip
 
 
 Does someone know what is wrong with my expression? Thank you, Gabriel




Gabriel, trying to debug a long regex in situ can be a nightmare however
the following technique always works for me...

Use the interactive interpreter and see if half the regex works, if it
does your problem is in the second half, if not it's in the first so try
the first half of that and so on an so forth. You'll find the point at
which it goes wrong in a snip.

Non-trivial regexes are always best built up and tested a bit at a time,
the interactive interpreter is great for this.

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


Re: Python tricks with applescript in OS-X

2009-12-16 Thread Juanre
Thanks for the pointers to appscript, and for the comments on the
page.  I have changed the examples at 
http://juanreyero.com/article/python/os-x-python.html
to reflect them.

Cheers,

Juan
--
http://juanreyero.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another problem..

2009-12-16 Thread Grant Edwards
On 2009-12-16, codefly coron...@gmail.com wrote:

 now.. another problem..

Sorry to be so blunt, but your main problem is that you don't
know how to ask questions.  Fix that, and everything else will
become much easier:

 1) Read this:  http://catb.org/~esr/faqs/smart-questions.html

 2) Read it again.

 3) Read these sections one more time:

 http://catb.org/~esr/faqs/smart-questions.html#beprecise
 http://catb.org/~esr/faqs/smart-questions.html#code
  
-- 
Grant Edwards   grante Yow! Is it NOUVELLE
  at   CUISINE when 3 olives are
   visi.comstruggling with a scallop
   in a plate of SAUCE MORNAY?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex help

2009-12-16 Thread Intchanter / Daniel Fackrell
On Dec 16, 10:22 am, r0g aioe@technicalbloke.com wrote:
 Gabriel Rossetti wrote:
  Hello everyone,

  I'm going nuts with some regex, could someone please show me what I'm
  doing wrong?

  I have an XMPP msg :

 snip

  Does someone know what is wrong with my expression? Thank you, Gabriel

 Gabriel, trying to debug a long regex in situ can be a nightmare however
 the following technique always works for me...

 Use the interactive interpreter and see if half the regex works, if it
 does your problem is in the second half, if not it's in the first so try
 the first half of that and so on an so forth. You'll find the point at
 which it goes wrong in a snip.

 Non-trivial regexes are always best built up and tested a bit at a time,
 the interactive interpreter is great for this.

 Roger.

I'll just add that the now you have two problems quip applies here,
especially when there are very good XML parsing libraries for Python
that will keep you from having to reinvent the wheel for every little
change.

See sections 20.5 through 20.13 of the Python Documentation for
several built-in options, and I'm sure there are many community
projects that may fit the bill if none of those happen to.

Personally, I consider regular expressions of any substantial length
and complexity to be bad practice as it inhibits readability and
maintainability.  They are also decidedly non-Zen on at least
Readability counts and Sparse is better than dense.

Intchanter
Daniel Fackrell

P.S. I'm not sure how any of these libraries are implemented yet, but
I'd hope they're using a finite state machine tailored to the parsing
task rather than using regexes, but even if they do the latter, having
that abstracted out in a mature library with a clean interface is
still a huge win.
-- 
http://mail.python.org/mailman/listinfo/python-list


Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread pdlemper
I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard. 
On my desktop I dual boot with XP - Ubuntu and have Python on both.
Unfortunately all my Python programs are written on Windows XP and
I heavily rely on WConio for console I/O.
Called Apple tech support. The technician had never heard of Python,
ascertained the MAC AIR does not come preloaded with Python and 
did not know if Python 3 would run under OS X 10.6. This was beyond
their expertise.
Does anyone have experience with OS X ? Could I use WConio in a 
Windows emulator ?  I have no experience with MACs and am debating
whether to send this back before opening.  
 Thanks. Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterators and views of lists

2009-12-16 Thread Francesco Bochicchio
On Dec 16, 1:58 pm, Anh Hai Trinh anh.hai.tr...@gmail.com wrote:


 You might be interested in this library http://pypi.python.org/pypi/
 stream.

 You can easily create arbitrary slice, for example

   i = mylist  takei(primes())

 will return an iterator over the items of mylist with a prime number
 index, given that primes() return an iterator over prime numbers.



Nice :-)

I was starting to experiment data flow programming with python myself,
although I'm just playing with it..
I find the idea of data flow programming fascinatin, and wonder if it
can be considered a general-purpose program paradigm.

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


Re: Raw string substitution problem

2009-12-16 Thread Peter Otten
Ed Keith wrote:

 --- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
 
 From: Gabriel Genellina gagsl-...@yahoo.com.ar
 Subject: Re: Raw string substitution problem
 To: python-list@python.org
 Date: Wednesday, December 16, 2009, 9:35 AM
 En Wed, 16 Dec 2009 11:09:32 -0300,
 Ed Keith e_...@yahoo.com
 escribió:
 
  I am having a problem when substituting a raw string.
 When I do the following:
  
  re.sub('abc', r'a\nb\nc', '123abcdefg')
  
  I get
  
  
  123a
  b
  cdefg
  
  
  what I want is
  
  r'123a\nb\ncdefg'
 
 From http://docs.python.org/library/re.html#re.sub
 
 re.sub(pattern, repl, string[, count])
 
 ...repl can be a string or a function;
 if
 it is a string, any backslash escapes
 in
 it are processed. That is, \n is
 converted
 to a single newline character, \r is
 converted to a linefeed, and so forth.
 
 So you'll have to double your backslashes:
 
 py re.sub('abc', r'a\\nb\\nc', '123abcdefg')
 '123a\\nb\\ncdefg'
 
 --Gabriel Genellina
 
 --http://mail.python.org/mailman/listinfo/python-list
 
 
 That is going to be a nontrivial exercise. I have control over the
 pattern, but the texts to be substituted and substituted into will be read
 from user supplied files. I need to reproduce the exact text the is read
 from the file.

There is a helper function re.escape() that you can use to sanitize the  
substitution:

 print re.sub('abc', re.escape(r'a\nb\nc'), '123abcdefg')
123a\nb\ncdefg

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


python and command shell on Windows

2009-12-16 Thread josu
Hi

I am trying to execute a windows command based on a shell by mean of
python. I have proven subprocess

test=subprocess.Popen
(['shell_command'],shell=True,stdin=PIPE,stdout=PIPE)

Initally, all seems ok, but, after seconds the python shell is frozen.

Does someone know alternative ways valid for windows OS?

Thanks in advance

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


Re: Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread Philip Semanchuk


On Dec 16, 2009, at 12:41 PM, pdlem...@earthlink.net wrote:


I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard.
On my desktop I dual boot with XP - Ubuntu and have Python on both.
Unfortunately all my Python programs are written on Windows XP and
I heavily rely on WConio for console I/O.
Called Apple tech support. The technician had never heard of Python,
ascertained the MAC AIR does not come preloaded with Python and
did not know if Python 3 would run under OS X 10.6. This was beyond
their expertise.


Sounds like the tech you spoke to was a knucklehead.

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/python.1.html

I've read about some Python-related headaches under Snow Leopard  
stemming from the fact that the stock Python is 64 bit and some 3rd  
party extensions assume/are compiled as 32 bit.



Does anyone have experience with OS X ? Could I use WConio in a
Windows emulator ?  I have no experience with MACs and am debating
whether to send this back before opening.


WConio I don't know about. I'm not sure what you mean by a Windows  
emulator. I run Windows XP under VirtualBox with OS X as the host,  
and that works fine for me. That's pretty heavy to call emulation  
though.


Hope this helps at least a little
Philip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread Rami Chowdhury
On Wed, Dec 16, 2009 at 09:41,  pdlem...@earthlink.net wrote:
 I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard.
 On my desktop I dual boot with XP - Ubuntu and have Python on both.
 Unfortunately all my Python programs are written on Windows XP and
 I heavily rely on WConio for console I/O.
 Called Apple tech support. The technician had never heard of Python,
 ascertained the MAC AIR does not come preloaded with Python

As far as I am aware, OS X always comes with Python. I'm not sure if
10.6 comes with Python 2.6 or 2.5, but one or the other is certainly
there, unless you have some sort of stripped-down install I'm not
familiar with.

 Does anyone have experience with OS X ? Could I use WConio in a
 Windows emulator ?

I don't know much about WConio, but a quick search indicates it does
for Windows what curses does for Unix-like OSes. I believe OS X is
sufficiently Unix-like that curses will do the job.

-- 
Rami Chowdhury
Never assume malice when stupidity will suffice. -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread r0g
pdlem...@earthlink.net wrote:
 I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard. 
 On my desktop I dual boot with XP - Ubuntu and have Python on both.
 Unfortunately all my Python programs are written on Windows XP and
 I heavily rely on WConio for console I/O.
 Called Apple tech support. The technician had never heard of Python,
 ascertained the MAC AIR does not come preloaded with Python and 
 did not know if Python 3 would run under OS X 10.6. This was beyond
 their expertise.
 Does anyone have experience with OS X ? Could I use WConio in a 
 Windows emulator ?  I have no experience with MACs and am debating
 whether to send this back before opening.  
  Thanks. Dave WB3DWE


Snow leopard comes with 2.6 so that shouldn't be a problem but I think
you're probably going to be SOL on the Wconio front - its a windows only
module AFAIK. The equivalent on *nix os's is ncurses so if you want your
apps to support Windows, Linux  Mac you're probably going to have to
use both.

Whatever you decide to do about the above you'd be mad to send back an
AIR anyway, that's a v.sleek bit of kit you've been 'given'! You can
install Windows and Linux via bootcamp if you want, or run them in a VM,
macs are very nearly standard PC's now anyway. I suppose if you want a
desktop replacement rather than something super portable you might find
some other machines more suitable but if you want to be coding on the go
you'd be hard pushed to find a nicer machine - except maybe the thinkpad
X300 for the removable battery and optical drive.

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


Re: Python Imaging Library status

2009-12-16 Thread Gabriel Genellina
En Wed, 16 Dec 2009 13:07:30 -0300, paulo.jpi...@gmail.com  
paulo.jpi...@gmail.com escribió:



is the famous PIL now a dead project?

Latest available download is from 2006 and I still don't see any signs
of having it updated for Python 2.6 or 3.x versions.


Version 1.1.7 is in beta.
Here you can find all available versions:
http://effbot.org/downloads/#pil
There is no official 3.x version yet, but ask in the image-SIG list.

--
Gabriel Genellina

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


Re: Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread Mark Dickinson
On Dec 16, 5:41 pm, pdlem...@earthlink.net wrote:
 I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard.
 On my desktop I dual boot with XP - Ubuntu and have Python on both.
 Unfortunately all my Python programs are written on Windows XP and
 I heavily rely on WConio for console I/O.
 Called Apple tech support. The technician had never heard of Python,
 ascertained the MAC AIR does not come preloaded with Python and
 did not know if Python 3 would run under OS X 10.6. This was beyond
 their expertise.

Unless the MacBook Air has some sort of cut-down version
of Snow Leopard (which I doubt), it'll have Python 2.5.4
and Python 2.6.1 pre-installed.  You'd have to install
Python 3.1 yourself if you want it, but it runs just fine
on OS X 10.6 (and earlier).  There may be some problems
with the Python 3.1.1 version from the official download
page, though, since Python 3.1.1 was released *before*
Snow Leopard was.  An easy way to get a working
Python 3.1.1 on OS X 10.6 is to install MacPorts and
then do a 'sudo port install python31'.

I don't know anything about WConio.

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


Re: Apple Mac OS X 10.6 support compatability with Python 3 ?

2009-12-16 Thread Mensanator
On Dec 16, 11:41 am, pdlem...@earthlink.net wrote:
 I've been given a MAC AIR laptop with OS X 10.6 Snow Leopard.
 On my desktop I dual boot with XP - Ubuntu and have Python on both.
 Unfortunately all my Python programs are written on Windows XP and
 I heavily rely on WConio for console I/O.
 Called Apple tech support. The technician had never heard of Python,
 ascertained the MAC AIR does not come preloaded with Python and
 did not know if Python 3 would run under OS X 10.6. This was beyond
 their expertise.

No, it's not. Call them back and if you get that bullshit again,
ask to speak to the supervisor. And then ask for his supervisor,
if necessary. It probably doesn't come with 3.1, you just got
ahold of an idiot.

BTW, I was just looking at an iMac the other day and it had 2.3,
2.4 and 2.5 installed. Beyond their expertise indeed.

 Does anyone have experience with OS X ? Could I use WConio in a
 Windows emulator ?  I have no experience with MACs and am debating
 whether to send this back before opening.  
                                                  Thanks.     Dave WB3DWE

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


Re: Python Imaging Library status

2009-12-16 Thread Emile van Sebille

On 12/16/2009 8:07 AM paulo.jpi...@gmail.com said...

Hi guys,

is the famous PIL now a dead project?

Latest available download is from 2006 and I still don't see any signs
of having it updated for Python 2.6 or 3.x versions.


PIL for Python 2.6 is available for download from 
http://www.pythonware.com/products/pil/ -- I don't know about 3.x plans...


Emile

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


Re: iterators and views of lists

2009-12-16 Thread Brendan Miller
On Wed, Dec 16, 2009 at 4:16 AM, Paul Rudin paul.nos...@rudin.co.uk wrote:
 Steven D'Aprano st...@remove-this-cybersource.com.au writes:


 I'm sympathetic to your request for list views. I've often wanted some
 way to cleanly and neatly do this:

 for item in seq[1:]:
     process(item)

 without making an unnecessary copy of almost all of seq.


 I don't know how it's implemented - but presumably itertools.islice
 could provide what you're asking for?
 --
 http://mail.python.org/mailman/listinfo/python-list


itertools.islice returns an iterator. My main point is that in python
iterators are weak and can't be used to write many types of
algorithms. They only go in one direction and they can't write to the
collection.

Another poster mentioned a stream library that is also iterator based.
Basically I'm saying that anything with iterators is pretty limited
because of the interface they present. See section 6.5 here for the
iterator protocol:

http://docs.python.org/library/stdtypes.html

Basically this is only useful for writing for loops or map/reduce
operations. However, python's primary datastructures, the dynamic
array (list) and hashtable (dictionary) are more powerful than that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python training in Florida, January 19-21

2009-12-16 Thread Mark Lutz
Don't miss your chance to attend our upcoming Florida
Python training class next month.  This 3-day public
class is being held January 19-21, in Sarasota, Florida.
It is open to both individual and group enrollments.

For more details on the class, as well as registration
instructions, please visit the class web page:

http://home.earthlink.net/~python-training/2010-public-classes.html

If you are unable to attend in January, our next
Sarasota class is already scheduled for April 6-8.

Thanks, and we hope to see you at a Python class in
sunny and warm Florida soon.

--Mark Lutz at Python Training Services
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Re: Logging question

2009-12-16 Thread Vinay Sajip at Red Dove


 Original Message 
Subject:Re: Logging question
Date:   Tue, 15 Dec 2009 18:28:54 +
From:   Vinay Sajip at Red Dove vinay_sa...@red-dove.com
To: Yaroslav Molochko ono...@gmail.com



On 15/12/2009 14:29, Yaroslav Molochko wrote:
 Hello Vinay Sajip,

 my name is Yaroslav, I'm trying to use your logging module, and it's
 working quite good. There is one issue I've figure out:

 logging.basicConfig(filename=c_logfile,
 level=logging_level, # By default logging is
 in INFO mode. You can change it to DEBUG by -v variable
 format=gert
 :%(asctime)-10s%(msecs)d:%(levelname)s: %(message)s,
 datefmt='%d%m %H%M%S.',)

 if I use it, and delete the logfile it will not create the logfile
 again. Only restart of the application will do. Is there any
 workaround for this?


Hello Yaroslav,

Once you create a FileHandler, the file belongs to the logging package
which assumes it has exclusive access to the file. If the file is
deleted, in order to log to it again, you need to remove the existing
handler, close it, open a new handler, and attach it to the root logger.
For this you will have to use the other logging API functions.

Please post questions like this on comp.lang.python so that others can
join in the discussion.

Regards,

Vinay Sajip


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


Re: ftplib retrlines timeout

2009-12-16 Thread BJ Swope
I've had experiences with some python mail servers that time out connections
if data from the socket is not sent to the application within the timeout
parameter.

I have seen a python app on FreeBSD that would timeout a connection after
600 seconds if freebsd did not receive at least 32 kb of data within the 600
second timeout.  FreeBSD would only send from the buffer to the app if there
was 32kb of data, unless TCP segments were received with the PUSH flag set
which would force a flush of the network buffer.

It sounds like this is the behavior Brendan is seeing.



Auburn fans are like slinkys... not really good for anything but they still
bring a smile to your face when you push them down a flight of stairs.

To argue that honorable conduct is only required against an honorable enemy
degrades the Americans who must carry out the orders. -- Charles Krulak,
Former Commandant of the Marine Corps

We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay



On Wed, Dec 16, 2009 at 7:41 AM, Brendan brendandetra...@yahoo.com wrote:

 On Dec 15, 6:17 pm, Jennifer owenzhang.chic...@gmail.com wrote:
  I am writing a program that has a requirement for  a timeout of
  retrlines after the connection established. I just wonder if timeout
  of ftplib.FTP('.xxx.com',username,password,timeout) will work for
  retrlines method after the connection established. Or
  socket.setdefaulttimeout will work in this case. Please let me know.
 
  What exception will be throwed if ftp.retrlines timed out.
 
  Many Thanks!
 
  - Jennifer

 I asked a similar question on here a few days ago and got no response,
 however I tried a large download which timed out with the following:
 Traceback (most recent call last):
  File ./download_r1_neodf.py, line 167, in module
result = ftp.quit()
  File /usr/local/lib/python2.6/ftplib.py, line 566, in quit
resp = self.voidcmd('QUIT')
  File /usr/local/lib/python2.6/ftplib.py, line 248, in voidcmd
return self.voidresp()
  File /usr/local/lib/python2.6/ftplib.py, line 223, in voidresp
resp = self.getresp()
  File /usr/local/lib/python2.6/ftplib.py, line 209, in getresp
resp = self.getmultiline()
  File /usr/local/lib/python2.6/ftplib.py, line 195, in getmultiline
line = self.getline()
  File /usr/local/lib/python2.6/ftplib.py, line 182, in getline
line = self.file.readline()
  File /usr/local/lib/python2.6/socket.py, line 406, in readline
data = self._sock.recv(self._rbufsize)
 socket.error: [Errno 110] Connection timed out


 BTW, if you want to use the timeout paramter, you must also use the
 account parameter. Set it to ''.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Raw string substitution problem

2009-12-16 Thread Gabriel Genellina
En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten __pete...@web.de  
escribió:



Ed Keith wrote:


--- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:


Ed Keith e_...@yahoo.com
escribió:

 I am having a problem when substituting a raw string.
When I do the following:

 re.sub('abc', r'a\nb\nc', '123abcdefg')

 I get

 
 123a
 b
 cdefg
 

 what I want is

 r'123a\nb\ncdefg'

So you'll have to double your backslashes:

py re.sub('abc', r'a\\nb\\nc', '123abcdefg')
'123a\\nb\\ncdefg'


That is going to be a nontrivial exercise. I have control over the
pattern, but the texts to be substituted and substituted into will be  
read

from user supplied files. I need to reproduce the exact text the is read
from the file.


There is a helper function re.escape() that you can use to sanitize the
substitution:


print re.sub('abc', re.escape(r'a\nb\nc'), '123abcdefg')

123a\nb\ncdefg


Unfortunately re.escape does much more than that:

py print re.sub('abc', re.escape(r'a.b.c'), '123abcdefg')
123a\.b\.cdefg

I think the string_escape encoding is what the OP needs:

py print re.sub('abc', r'a\n(b.c)\nd'.encode(string_escape),  
'123abcdefg')

123a\n(b.c)\nddefg

--
Gabriel Genellina

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


Re: Python Imaging Library status

2009-12-16 Thread paulo.jpi...@gmail.com
On 16 Dez., 19:21, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
 En Wed, 16 Dec 2009 13:07:30 -0300, paulo.jpi...@gmail.com  
 paulo.jpi...@gmail.com escribió:

  is the famous PIL now a dead project?

  Latest available download is from 2006 and I still don't see any signs
  of having it updated for Python 2.6 or 3.x versions.

 Version 1.1.7 is in beta.
 Here you can find all available versions:http://effbot.org/downloads/#pil
 There is no official 3.x version yet, but ask in the image-SIG list.

 --
 Gabriel Genellina

Thanks for the quick feedback, it is good to know that PIL is still
alive.

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


Re: Object Relational Mappers are evil (a meditation)

2009-12-16 Thread J Kenneth King
r0g aioe@technicalbloke.com writes:

 J Kenneth King wrote:
 Steven D'Aprano st...@remove-this-cybersource.com.au writes:
 
 On Fri, 11 Dec 2009 19:20:21 -0500, Steve Holden wrote:

 snip

 Hear, hear!
 That's all very well, but some languages and techniques encourage the 
 programmer to write bad code.
 
 That's just BS.
 
 Bad code doesn't just write itself.  Programmers write bad code.  And
 ignorance is not an excuse.
 
 Just because a language allows a programmer to write sloppy code doesn't
 put the language at fault for the bad code programmers write with it.



 Okay, as long as you realize the corollary of your argument is:

 It is impossible for a language to encourage programmers to write good
 code and promote good programming practices by design.

 I'm not sure that's entirely true either.

 I think python's one way to do something design philosophy goes some
 way toward that, as does Smalltalk's enforced message passing. I think
 PHP's superglobals and namespacing encourage bad practices (or used to
 back in the day), as do Basic's GOTO and Ecmascript's prototype
 overriding.

I think your corollary is slightly misleading.

It would be more apt to say, Just because a language allows a
programmer to write good code doesn't mean that the language is
responsible for the good code programmers write with it.

It is the responsibility of the programmer to recognize the advantages
and flaws of their tools.  PHP doesn't encourage a programmer to be a
bad programmer because it lacks name-spaces or because BASIC has GOTO
statements.  A bad programmer will be a bad programmer because they
don't understand what makes these features distinct, useful, or
damaging.

The language doesn't encourage anything.  It's just a medium like oil
paints and canvas.  A painting can be good or bad despite the medium it
is constructed on.  The skill of the painter is what matters.


 Surely a language CAN be said to encourage kludges and sloppiness if it
 allows a good way and a bad way and makes the bad way much easier to
 implement or understand for noobs.

 Roger.

The programmer can be encouraged to use kludges and produce sloppy
code.  Whether by ignorance or inflated ego.  Languages with more choice
just give them more rope to hang themselves with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Raw string substitution problem

2009-12-16 Thread Peter Otten
Gabriel Genellina wrote:

 En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten __pete...@web.de
 escribió:
 
 Ed Keith wrote:

 --- On Wed, 12/16/09, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:

 Ed Keith e_...@yahoo.com
 escribió:

  I am having a problem when substituting a raw string.
 When I do the following:
 
  re.sub('abc', r'a\nb\nc', '123abcdefg')
 
  I get
 
  
  123a
  b
  cdefg
  
 
  what I want is
 
  r'123a\nb\ncdefg'

 So you'll have to double your backslashes:

 py re.sub('abc', r'a\\nb\\nc', '123abcdefg')
 '123a\\nb\\ncdefg'

 That is going to be a nontrivial exercise. I have control over the
 pattern, but the texts to be substituted and substituted into will be
 read
 from user supplied files. I need to reproduce the exact text the is read
 from the file.

 There is a helper function re.escape() that you can use to sanitize the
 substitution:

 print re.sub('abc', re.escape(r'a\nb\nc'), '123abcdefg')
 123a\nb\ncdefg
 
 Unfortunately re.escape does much more than that:
 
 py print re.sub('abc', re.escape(r'a.b.c'), '123abcdefg')
 123a\.b\.cdefg

Sorry, I didn't think of that.
 
 I think the string_escape encoding is what the OP needs:
 
 py print re.sub('abc', r'a\n(b.c)\nd'.encode(string_escape),
 '123abcdefg')
 123a\n(b.c)\nddefg

Another possibility:

 print re.sub('abc', lambda m: r'a\nb\n.c\a', '123abcdefg')
123a\nb\n.c\adefg

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


How to create a self-destructing Tkinter dialog box?

2009-12-16 Thread mrstevegross
Ok, I would like to put together a Python/Tkinter dialog box that
displays a simple message and self-destructs after N seconds. Is there
a simple way to do this?

Thanks,

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


Re: iterators and views of lists

2009-12-16 Thread Anh Hai Trinh
On Dec 16, 2:48 pm, Brendan Miller catph...@catphive.net wrote:

 No, that's what I'm getting at... Most of the existing mutating
 algorithms in python (sort, reverse) operate over entire collections,
 not partial collections delimited by indexes... which would be really
 awkward anyway.

Ok it can be done! The code is here: http://gist.github.com/258134.

   from listagent import listagent
   x = [22, 7, 2, -5, 8, 4]
   listagent(x)[1:].sort()
   x
  [22, -5, 2, 4, 7, 8]
   listagent(x)[::2].reverse()
   x
  [7, -5, 2, 4, 22, 8]

Basically the agent refers to the original list only by address
translation, and indeed made no copy of anything whatever! I
implemented Shell sort but I suppose others are possible.

The implementation is incomplete, for now you cannot do slice
assignment, i.e.

  a = listagent(x)[::-2]
  a[1:] = [4, 2]

but it should be easy to implement, and I'm too sleepy.

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


Re: Raw string substitution problem

2009-12-16 Thread Ed Keith
--- On Wed, 12/16/09, Peter Otten __pete...@web.de wrote:

 Another possibility:
 
  print re.sub('abc', lambda m: r'a\nb\n.c\a',
 '123abcdefg')
 123a\nb\n.c\adefg

I'm not sure whether that is clever, ugly, or just plain strange! 

I think I'll stick with:

 m = re.match('^(.*)abc(.*)$', '123abcdefg')
 print m.group(1) + r'a\nb\n.c\a' + m.group(2)
123a\nb\n.c\adefg

It's much less likely to fry the poor maintenance programmer's mind.

-EdK

Ed Keith
e_...@yahoo.com

Blog: edkeith.blogspot.com



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


Re: python and command shell on Windows

2009-12-16 Thread eric_dex...@msn.com
On Dec 16, 11:58 am, josu josuj...@gmail.com wrote:
 Hi

 I am trying to execute a windows command based on a shell by mean of
 python. I have proven subprocess

 test=subprocess.Popen
 (['shell_command'],shell=True,stdin=PIPE,stdout=PIPE)

 Initally, all seems ok, but, after seconds the python shell is frozen.

 Does someone know alternative ways valid for windows OS?

 Thanks in advance

 josu
os.startfile() works you will find the pipe commands are different on
unix and windows anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I have a cross platform os.startfile but I need to asociate files with xdg-open in linux how do I do that??

2009-12-16 Thread eric_dex...@msn.com
On Dec 16, 10:36 am, Paul Boddie p...@boddie.org.uk wrote:
 On 16 Des, 17:03, eric_dex...@msn.com eric_dex...@msn.com wrote:

  #this should be a cross platform example of os.startfile ( startfile )
  #for windows and linux.  this is the first version and
  #linux, mac, other os's commands for exceptions to the
  #rule would be appreciated.  at some point this will be
  #in the dex tracker project.

 You could look at the desktop package for something similar:

 http://pypi.python.org/pypi/desktop

 The desktop.open function supports a few extra workarounds, mostly
 because it pre-dates xdg-open.

 Paul

Since desktop environments like KDE and GNOME provide mechanisms for
running
browsers and editors according to the identified type of a file or
resource,
just as Windows runs files or resources, it is appropriate to have a
module
which accesses these mechanisms. It is this kind of functionality that
the
desktop package aims to support. Note that this approach is arguably
better

I am concerned this means I cant do something like associate python
files with python in artistx (ubuntu).  It just associates text files
with editors??  It does look like a cool package and I will look into
that further.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question to logging

2009-12-16 Thread Vinay Sajip at Red Dove
On 16/12/2009 12:49, stefan.messerl...@postfinance.ch wrote:
 I have the following error and no clue, how to solve that. Up to python 
 version 2.5 the following script worked without an error, but since python 
 2.6. I get the following error:

 #!/usr/bin/env python
 # -*- coding: ISO-8859-1 -*-
 import logging
 logging.getLogger().addHandler( logging.StreamHandler() )
 log = logging.getLogger()
 t = äöü
 print this is printed   :  + t
 log.error( this is log.error :  + t )



 # running the above script with Python 2.5
 $ ./x.py
 this is printed   : äöü
 this is log.error : äöü


 # running the above script with Python 2.6
 $ ./x.py
 this is printed   : äöü
 Traceback (most recent call last):
   File 
 /var/tmp/pf-python-2.6-2.6.1-root/appl_local/python-2.6/lib/python2.6/logging/__init__.py,
  line 765, in emit
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 20: 
 ordinal not in range(128)


 I found your answer of issue6991 in bugs.python.org, where somebody had a 
 similar problem, but to be honest, I have no idea how to solve my problem.

 Can you please give me a tip what I have to change or where I can find more 
 information ?
   

Hello Stefan,

You should pass a stream to StreamHandler which has an encoding
attribute set to the appropriate encoding (presumably iso-8859-1) and
ensure that your stream will encode any Unicode sent to it with that
encoding. For example,

import codecs
ENCODING = 'iso-8859-1' # or whatever
writer = codecs.getwriter(ENCODING)
w = writer(sys.stderr)
w.encoding = ENCODING
...
handler = logging.StreamHandler(w)
...

In future, please ask questions like this on comp.lang.python
(python-list@python.org) to give others the chance to participate in any
discussion.

Regards,

Vinay Sajip


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


  1   2   >