Re: Cannot connect to IMAP server in Python 3.2

2012-04-04 Thread Steve Howell
On Apr 4, 9:49 pm, Steven D'Aprano  wrote:
> I can connect to an IMAP server using Python 2.6:
>
> steve@runes:~$ python2.6
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import imaplib
> >>> server = imaplib.IMAP4_SSL('x')
> >>> print server
>
> 
>
> But when I try with Python 3.2, it just sits there until it times out:
>
> steve@runes:~$ python3.2
> Python 3.2.2 (default, Feb 29 2012, 18:11:33)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import imaplib
> >>> server = imaplib.IMAP4('x', imaplib.IMAP4_SSL_PORT)
>
> Traceback (most recent call last):
> [...]
> socket.timeout: timed out
>
> What am I doing wrong?
>

Is it simply the wrong port?  (IMAP4_SSL_PORT vs. IMAP4_PORT)

How long do you wait before seeing the timeout?

Have you tried print-debugging within your local copy of imaplib.py?
The code related to making the connection just wraps
socket.create_connection:


   234
   235 def _create_socket(self):
   236 return socket.create_connection((self.host, self.port))
   237
   238 def open(self, host = '', port = IMAP4_PORT):
   239 """Setup connection to remote server on "host:port"
   240 (default: localhost:standard IMAP4 port).
   241 This connection will be used by the routines:
   242 read, readline, send, shutdown.
   243 """
   244 self.host = host
   245 self.port = port
   246 self.sock = self._create_socket()
   247 self.file = self.sock.makefile('rb')


http://hg.python.org/cpython/file/3.2/Lib/imaplib.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot connect to IMAP server in Python 3.2

2012-04-04 Thread Rob Williscroft
Steven D'Aprano wrote in news:4f7d2475$0$3$c3e8...@news.astraweb.com in 
gmane.comp.python.general:

> I can connect to an IMAP server using Python 2.6:
> 
> steve@runes:~$ python2.6 
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 

 server = imaplib.IMAP4_SSL('x')
 
> But when I try with Python 3.2, it just sits there until it times out:

 server = imaplib.IMAP4('x', imaplib.IMAP4_SSL_PORT)
 
> What am I doing wrong?
> 

Not using IMAP4_SSL, above you are using IMAP4 (non SSL) but with the 
SSL port.

http://docs.python.org/py3k//library/imaplib.html#imaplib.IMAP4_SSL

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


Cannot connect to IMAP server in Python 3.2

2012-04-04 Thread Steven D'Aprano
I can connect to an IMAP server using Python 2.6:

steve@runes:~$ python2.6 
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imaplib
>>> server = imaplib.IMAP4_SSL('x')
>>> print server



But when I try with Python 3.2, it just sits there until it times out:

steve@runes:~$ python3.2
Python 3.2.2 (default, Feb 29 2012, 18:11:33) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imaplib
>>> server = imaplib.IMAP4('x', imaplib.IMAP4_SSL_PORT)
Traceback (most recent call last):
[...]
socket.timeout: timed out


What am I doing wrong?


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


Re: Igraph and usage of Read(kclass, f, format=...) question

2012-04-04 Thread alex23
On Apr 5, 12:00 am, ish  wrote:
> Any pointer will be appreciated.

1. Show your input. Odds are there's a problem with your data.
2. Show the output. "Does not work" tells us nothing of value.
3. Don't repeatedly post the same question in different threads. That
doesn't make people answer any faster.
4. Try the appropriate support mailing list:
https://lists.nongnu.org/mailman/listinfo/igraph-help


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


Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Thu, Apr 5, 2012 at 1:15 AM, Steve Howell  wrote:
> On Apr 4, 1:37 am, Chris Angelico  wrote:
>> And, as a subtle point: This method can't create the file "at size". I
>> don't know how it'll end up allocating space, but certainly there's no
>> opportunity to announce to the OS at file open/create time "please
>> allocate X bytes for this file". That may be an utterly trivial point,
>> or a crucially vital one.
>>
>> ChrisA
>
> FWIW shutil.py doesn't do anything particularly fancy with respect to
> creating files "at size", unless I'm missing something:

So it doesn't. However, that's current implementation, and it's
entirely possible that a future version might add that feature - it
wouldn't break any existing code, and would improve file system
performance. Doing it yourself means you miss out on any such
enhancements.

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


Re: Python Gotcha's?

2012-04-04 Thread Tim Chase

On 04/04/12 17:34, Miki Tebeka wrote:

Greetings,

I'm going to give a "Python Gotcha's" talk at work.
If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
share.

(Note that I want over http://wiki.python.org/moin/PythonWarts already).


1) While I believe it was fixed in more recent releases (perhaps 
Py3 or later, most of my code is still in 2.x), leaking of 
list-comprehension variables into the surrounding scope has stung 
me on occasion:


  val = something_important
  whatever = [val for val in iterable if condition(val)]
  assert val == something_important, "ug!"


2) While totally understandable, the significance of leading 
whitespace in docstrings/triple-quoted items occasionally catches 
me in places I didn't intentionally want it:


  class Foo:
def frobniculate(self, x, y):
  """Frobniculate the x & y
  x is the macrowobble variance
  y is the miniwibble grobulation
  """
  pass

(there's now leading whitespace on lines 2 & 3, and an extra 
trailing line of pure whitespace).


3) the peculiarities of old-style classes and new-style classes 
in 2.x (mooted by 3.x) take careful reading of the docs if you're 
overriding __getattr__ or __getattribute__, as well as possible 
other old-vs-new gotchas.


4) the __del__ method may have things in the containing scopes 
(such as modules imported at the top of the containing module) 
that get garbage-collected before the __del__ is called.  In 
general, __del__ stinks, and is better replaced by "with" 
statements using context managers.


5) the masking of system modules.  On multiple occasions I've 
created a local module named "email.py", and then upon importing 
something else (I think it may have been smtplib...not sure), it 
failed with a confusing error because the imported module found 
mine rather than the system module.


Those are my off-the-top-of-the-head gotchas.

-tkc




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


Re: Python Gotcha's?

2012-04-04 Thread Chris Angelico
On Thu, Apr 5, 2012 at 8:34 AM, Miki Tebeka  wrote:
> Greetings,
>
> I'm going to give a "Python Gotcha's" talk at work.
> If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
> share.
>
> (Note that I want over http://wiki.python.org/moin/PythonWarts already).

Don't know if it's what's meant on that page by the += operator, but
the weirdness with concatenating onto a list inside a tuple may merit
a mention.

>>> a=([1],)
>>> a[0].append(2) # This is fine
>>> a
([1, 2],)
>>> a[0]+=[3] # This is not.
Traceback (most recent call last):
  File "", line 1, in 
a[0]+=[3]
TypeError: 'tuple' object does not support item assignment
>>> a
([1, 2, 3],)

Throws exception, but still does append to the list.

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


Re: Python Gotcha's?

2012-04-04 Thread Cameron Simpson
No module level properties:

  >>> @property
  ... def x():
  ...   print 1
  ... 
  >>> x
  

Actually, that doesn't work with classes either, only instances.
Can I refer to the instance of the module/package?

In the interpreter, __package__ is None instead of some unnamed
"module/package".

In general I have a nagging desire that modules were more like classes.
But the details remain nebulous in my mind. The property thing is the
only concrete thing I trip over at present.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Louis Pasteur's theory of germs is ridiculous fiction.
   --Pierre Pachet, Professor of Physiology at Toulouse, 1872
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-04 Thread Cameron Simpson
On 04Apr2012 23:07, Steven D'Aprano  
wrote:
| If you decorate a function, by default the docstring is lost.
| 
| @decorate
| def spam(x, y):
| """blah blah blah blah"""
| 
| spam.__doc__ => raises exception
| 
| Solution: make sure your decorator uses functools.wraps().

There's a functools.wraps()? [*smacks forehead with palm*] Thanks.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

A pessimist is an optimist in full possession of the facts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-04 Thread Cameron Simpson
On 04Apr2012 15:34, Miki Tebeka  wrote:
| I'm going to give a "Python Gotcha's" talk at work.
| If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
share.
| 
| (Note that I want over http://wiki.python.org/moin/PythonWarts already).

Missing "return" means "return None".
One only has to miss a control path to have this happen.
Easy enough to accomodate, if only by having a return or raise at the
end of the function, but ...
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

I really don't like :-) symbols as well. I feel that if you can't see the pie
coming, you deserve whipped cream up your nose.
- r...@cherry.cray.com (rob derrick)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-04 Thread Steven D'Aprano
On Wed, 04 Apr 2012 15:34:20 -0700, Miki Tebeka wrote:

> Greetings,
> 
> I'm going to give a "Python Gotcha's" talk at work. If you have an
> interesting/common "Gotcha" (warts/dark corners ...) please share.
> 
> (Note that I want over http://wiki.python.org/moin/PythonWarts already).


The GIL prevents Python from taking advantage of multiple cores in your 
CPU when using multiple threads.

Solution: use a GIL-less Python, like IronPython or Jython, or use 
multiple processes instead of threads.



exec() and execfile() are unintuitive if you supply separate dicts for 
the globals and locals arguments.

http://bugs.python.org/issue1167300
http://bugs.python.org/issue14049

Note that both of these are flagged as WON'T FIX.

Solution: to emulate top-level code, pass the same dict as globals and 
locals.


max() and min() fail with a single argument:
max(2, 3) => 3
max(3) => raises exception

Solution: don't do that. Or pass a list:
max([2, 3]) => 3
max([3]) => 3


Splitting on None and splitting on space is not identical:
"".split() => []
"".split(' ') => ['']



JSON expects double-quote marks, not single:
v = json.loads("{'test':'test'}")  fails
v = json.loads('{"test":"test"}')  succeeds




If you decorate a function, by default the docstring is lost.

@decorate
def spam(x, y):
"""blah blah blah blah"""

spam.__doc__ => raises exception

Solution: make sure your decorator uses functools.wraps().


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


Python Gotcha's?

2012-04-04 Thread Miki Tebeka
Greetings,

I'm going to give a "Python Gotcha's" talk at work.
If you have an interesting/common "Gotcha" (warts/dark corners ...) please 
share.

(Note that I want over http://wiki.python.org/moin/PythonWarts already).

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


Re: Async IO Server with Blocking DB

2012-04-04 Thread Jean-Paul Calderone
On Apr 3, 6:13 pm, looking for  wrote:
> Hi
>
> We are thinking about building a webservice server and considering
> python event-driven servers i.e. Gevent/Tornado/ Twisted or some
> combination thereof etc.
>
> We are having doubts about the db io part. Even with connection
> pooling and cache, there is a strong chance that server will block on
> db. Blocking for even few ms is bad.
>
> can someone suggest some solutions or is async-io is not at the prime-
> time yet.
>
> Thanks

Twisted provides support for any DB-API module via
twisted.enteprise.adbapi,
which wraps the module in an asynchronous API (implemented using a
thread pool).

Since the calls all happen in separate threads, it doesn't matter that
they block.

If you're not talking about a SQL database or a DB-API module, maybe
be more
specific about the kind of database I/O you have in mind.

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


Why does this hang sometimes?

2012-04-04 Thread Jesse Jaggars
I am just playing around with threading and subprocess and found that
the following program will hang up and never terminate every now and
again.

import threading
import subprocess
import time

def targ():
   p = subprocess.Popen(["/bin/sleep", "2"])
   while p.poll() is None:
       time.sleep(1)

t1 = threading.Thread(target=targ)
t2 = threading.Thread(target=targ)
t1.start()
t2.start()

t1.join()
t2.join()


I found this bug, and while it sounds similar it seems that it was
closed during python 2.5 (I'm using 2.7.2):
http://bugs.python.org/issue1404925

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


Re: igraph and usage of Read(klass, f, format=None, *args, **kwds) question

2012-04-04 Thread Ian Kelly
On Tue, Apr 3, 2012 at 9:45 PM,   wrote:
> I have a file with with adjacency list of an undirected graph one vertex list 
> per input line [0 1, 1 2 3, 2 1, 3 1] assume a newline for commas (file is 
> named adjl.txt). Can some one give an example of loading this into graph of 4 
> vertices?
>
> import igraph
> g = igraph.Graph()
> g.Read("adjl.txt", "edgelist")
>   does not work..

"does not work" is not very useful in figuring out what the problem
is.  What actually happens, versus what you were expecting?  Was there
an error message?

Looking at the documentation, it appears that Read is a class method,
not an instance method -- it is agnostic to the instance g and only
cares that it is a member of Graph.  The docs do not specify this, but
I would guess that it probably returns a newly created instance of
Graph.  The correct way to call it then would probably be something
like:

g = igraph.Graph.Read("adjl.txt", "edgelist")
-- 
http://mail.python.org/mailman/listinfo/python-list


Installing a binary package on virtualenv on windows

2012-04-04 Thread Manu
Hi
  I have been using virtualenv on my windows desktop for quite a while
now and would really recommend everyone to use it.
  Something I come across is how can I install a binary dependency  in
my virtual environment . I need to install lxml and gevent. Both
packages are delivered as windows installer (and not always the latest
version !!!) and it seems that pip install will not make the job( as
it will go through the build process...)

Thanks for your help.
M
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-04 Thread Nathan Rice
> The "building cabinets" problem is interesting:
>
>  1. To actually build a cabinet, there's a lot of domain knowledge
> that's probably implicit in most circumstances.  A carpenter might
> tell another carpenter which hinge to use, but they won't have to talk
> about why doors need hinges or how to do the assembly.
>  2. It's quite common for humans to use computer programs as part of
> the design process.
>  3. Often, the output of a CAD program (at the file level) is some
> sort of vector representation that only describes the end product
> (basic dimensions, etc.).
>
> I wonder if there are mini-languages out there that allow you to
> describe cabinets in a very descriptive way, where the description
> easily translates to the actual steps of building the cabinet, not
> just the final dimensions.

I think if you were to describe the parts of the cabinet that needed
to be assembled separately (and thus could be viewed as separate
entities in some sense) and showed the cabinet as the composition of
those parts, you would be on the right track.  Being a mediocre
carpenter, I can't really say anything conclusively here though :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No os.copy()? Why not?

2012-04-04 Thread Nobody
On Wed, 04 Apr 2012 08:14:18 -0400, Roy Smith wrote:

>> And sparse files are really hard to reproduce, at least on Unix: on
>> Linux even the system's cp doesn't guarantee sparseness of the copy (the
>> manual mentions a "crude heuristic").
> 
> I imagine the heuristic is to look for blocks of all zeros.

Yes. Although it's not really accurate to describe it as a "heuristic".

With --sparse=always, it will try to make the output sparse regardless of
whether the input was sparse, replacing any all-zeros block with a hole.

The default of --sparse=auto will only create a sparse file if the input
itself is sparse, i.e. if the length of the file rounded up to the nearest
block exceeds its disk usage.

Regardless of the --sparse= setting and whether the input was sparse, if
it tries to create a sparse file it will create holes wherever possible
rather than attempting to preserve the exact pattern of holes in a sparse
input file.

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


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-04 Thread Nathan Rice
> Long personal note ahead.
> tl;dr version: Computers are such a large shift for human civilization
> that generally we dont get what that shift is about or towards.

Another option: since *computers* are such a general device, there
isn't just one notion.

> In the long run I expect computing science to transcend its parent
> disciplines, mathematics and logic, by effectively realizing a
> significant part of Leibniz's Dream of providing symbolic calculation
> as an alternative to human reasoning. (Please note the difference
> between "mimicking" and "providing an alternative to": alternatives
> are allowed to be better.)

A thinking machine.  +1.

> Needless to say, this vision of what computing science is about is not
> universally applauded. On the contrary, it has met widespread --and
> sometimes even violent-- opposition from all sorts of directions. I
> mention as examples
>
> (0) the mathematical guild, which would rather continue to believe
> that the Dream of Leibniz is an unrealistic illusion

Mathematics is not a closet guild, it is large and contentious.  Ideas
live and die in mathematics based on their fundamental truth.  If
there is some bold, sweeping statement it *MIGHT* be possible to prove
or disprove, mathematicians will be all over it.  just look at
Fermat's last theorem and the Poincare conjecture if you want proof of
this.

> (1) the business community, which, having been sold to the idea that
> computers would make life easier, is mentally unprepared to accept
> that they only solve the easier problems at the price of creating much
> harder one

Most business people I know secretly love when they can sell a
solution to one problem that creates new problems (and thus
opportunities for new products!).  The business term for this is an
"Upsell" or "Value-add".

> (2) the subculture of the compulsive programmer, whose ethics
> prescribe that one silly idea and a month of frantic coding should
> suffice to make him a life-long millionaire

I love hacker culture, but it has been infected by the idea of
entrepreneurship as a good in and of itself.  Being a creator is a
beautiful thing, go forth and make *art*.  Improve the human
condition.  Make the world a better place.  STFU about venture capital
and stage 2 funding and minimum viable products; that sort of talk is
a sure sign that you haven't created anything of actual value.

> (3) computer engineering, which would rather continue to act as if it
> is all only a matter of higher bit rates and more flops per second

These guys are doing something that I find very uninteresting, but is
absolutely necessary.  Bravo I say.

> (4) the military, who are now totally absorbed in the business of
> using computers to mutate billion-dollar budgets into the illusion of
> automatic safety

Nations will always try and be imperialist.  At least drones and robot
soldiers mean less human suffering.

> (5) all soft sciences for which computing now acts as some sort of
> interdisciplinary haven

Digital humanities (outside of a VERY small set of projects) is a
joke.  Multimedia history presentations (and what not) are the domain
of edutainment companies, not academia.

> (6) the educational business that feels that, if it has to teach
> formal mathematics to CS students, it may as well close its schools.

I feel quite the opposite actually.  At the really top notch computer
science schools, there is a clear mathematical bent (though it is
interdisciplinary).  Places like MIT, Stanford, Berkeley, CMU,
Cambridge, etc make a STRONG effort to separate the
mathematical/theory of computation side and engineering side.  At your
average state college, the computer science department is just a
hodgepodge, and you tend to see more graphics, "applied computation"
and embedded/DSP type people.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No os.copy()? Why not?

2012-04-04 Thread Steve Howell
On Apr 4, 1:37 am, Chris Angelico  wrote:
> On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano
>
>  wrote:
> > On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote:
>
> >> def cp(infile, outfile):
> >>    open(outfile, "w").write(open(infile).read())
>
> > Because your cp doesn't copy the FILE, it copies the file's CONTENTS,
> > which are not the same thing.
>
> And, as a subtle point: This method can't create the file "at size". I
> don't know how it'll end up allocating space, but certainly there's no
> opportunity to announce to the OS at file open/create time "please
> allocate X bytes for this file". That may be an utterly trivial point,
> or a crucially vital one.
>
> ChrisA

FWIW shutil.py doesn't do anything particularly fancy with respect to
creating files "at size", unless I'm missing something:

 http://hg.python.org/cpython/file/2.7/Lib/shutil.py

Only one level away from copyfile, you have copyfileobj, which is a
read/write loop:

46 def copyfileobj(fsrc, fdst, length=16*1024):
47 """copy data from file-like object fsrc to file-like object
fdst"""
48 while 1:
49 buf = fsrc.read(length)
50 if not buf:
51 break
52 fdst.write(buf)

...and that gets called by copyfile, which only does a little bit of
"os"-related stuff:

66 def copyfile(src, dst):
67 """Copy data from src to dst"""
68 if _samefile(src, dst):
69 raise Error("`%s` and `%s` are the same file" % (src,
dst))
70
71 for fn in [src, dst]:
72 try:
73 st = os.stat(fn)
74 except OSError:
75 # File most likely does not exist
76 pass
77 else:
78 # XXX What about other special files? (sockets,
devices...)
79 if stat.S_ISFIFO(st.st_mode):
80 raise SpecialFileError("`%s` is a named pipe" %
fn)
81
82 with open(src, 'rb') as fsrc:
83 with open(dst, 'wb') as fdst:
84 copyfileobj(fsrc, fdst)

The "value add" vs. a simple read/write loop depends on whether you
want OSError suppressed.  The _samefile guard is nice to have, but
probably unnecessary for many apps.

I'm sure shutil.copyfile() makes perfect sense for most use cases, and
it's nice that you can see what it does under the covers pretty
easily, but it's not rocket science.


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


Re: Google Tech Talk: lisp at JPL

2012-04-04 Thread ccc31807
On Apr 3, 1:53 am, Xah Lee  wrote:
> 〈The Remote Agent Experiment: Debugging Code from 60 Million Miles
> Away〉
> Google Tech Talk, (2012-02-14) Presented by Ron Garret. 
> @http://www.youtube.com/watch?v=_gZK0tW8EhQ

RG mentions giving a more technical version to a Lisp User Group. Any
chance that this talk is publicly available?

My reaction to this talk, particularly the part near the end, is that
NASA isn't alone. RG uses terms like 'rudderless institutions',
'outreach', 'mission', and others, which would be appropriate when
talking about religious institutions, i.e., churches. I'm not sure
that his prescriptions are addressed to the underlying causes, but
they certainly deal with the symptoms.

As to the question about Python vs. Lisp, I though RG's reaction
(wanting to shed a tear or two) was telling. Languages are tools that
users use to accomplish tasks. Apparently, Python has the appearance
of being a 'better' tool to accomplish programming tasks (at Google,
since that's the context) than Lisp.

My take FWIW is to learn many languages and use them appropriately. In
connection with my job, I recently did a comparison of several
different tasks in C++, ColdFusion, Perl, and Lisp. I use Perl
(mostly) and the tasks were those for which Perl is suited. The
functions are now written in ColdFusion (they are part of a web app.)
I use Lisp in order to highlight the verbosity and ease of different
languages, and even though using Lisp is totally impossible (speaking
to my employer's environment) I can tell you that the Lisp part of the
comparison received the most comment, and the most interesting
comments.

Thanks for the talk, Ron, I really enjoyed it, and wish you (and NASA)
all the best.

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


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-04 Thread Steve Howell
On Apr 3, 11:19 pm, Steven D'Aprano  wrote:
> On Tue, 03 Apr 2012 08:39:14 -0400, Nathan Rice wrote:
> > Much like
> > with the terminal to GUI transition, you will have people attacking
> > declarative natural language programming as a stupid practice for noobs,
> > and the end of computing (even though it will allow people with much
> > less experience to be more productive than them).
>
> I cry every time I consider GUI programming these days.
>
> In the late 1980s and early 1990s, Apple released a product, Hypercard,
> that was a combination GUI framework and natural-ish language programming
> language. It was an astonishing hit with non-programmers, as it allowed
> people to easily move up from "point and click" programming to "real"
> programming as their skills improved.
>
> Alas, it has been abandoned by Apple, and while a few of its intellectual
> successors still exit, it very niche.
>
> I *really* miss Hypercard. Not so much for the natural language syntax,
> as for the astonishingly simple and obvious GUI framework.
>
> To get a flavour of the syntax, see OpenXION:
>
> http://www.openxion.org
>
> and for a hint of the framework, see Pythoncard:
>
> http://pythoncard.sourceforge.net
>
> > Ultimately, the answers to your questions exist in the world for you to
> > see.  How does a surgeon describe a surgical procedure?  How does a chef
> > describe a recipe?  How does a carpenter describe the process of
> > building cabinets?  Aside from specific words, they all use natural
> > language, and it works just fine.
>
> No they don't. In general they don't use written language at all, but
> when they are forced to, they use a combination of drawings or
> illustrations plus a subset of natural language plus specialist jargon.
>
> Programming languages include both specialist grammar and specialist
> semantics. That makes it a cant or an argot.

The "building cabinets" problem is interesting:

  1. To actually build a cabinet, there's a lot of domain knowledge
that's probably implicit in most circumstances.  A carpenter might
tell another carpenter which hinge to use, but they won't have to talk
about why doors need hinges or how to do the assembly.
  2. It's quite common for humans to use computer programs as part of
the design process.
  3. Often, the output of a CAD program (at the file level) is some
sort of vector representation that only describes the end product
(basic dimensions, etc.).

I wonder if there are mini-languages out there that allow you to
describe cabinets in a very descriptive way, where the description
easily translates to the actual steps of building the cabinet, not
just the final dimensions.


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


Igraph and usage of Read(kclass, f, format=...) question

2012-04-04 Thread ish
I am using igraph package via Python interface. I have a list of edges of a 
graph one edge per line of input in a file (e.txt) and want igraph to read the 
edges into the graph. Can any one give me a usage hint of igraph.Graph.Read()??

import igraph
g = igraph.Graph()
g.add_vertices(3)# 4 vertices
g.Read("e.txt", "egdes")

but does not work!

Any pointer will be appreciated.
-ish
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Async IO Server with Blocking DB

2012-04-04 Thread Steve Howell
On Apr 3, 3:13 pm, looking for  wrote:
> Hi
>
> We are thinking about building a webservice server and considering
> python event-driven servers i.e. Gevent/Tornado/ Twisted or some
> combination thereof etc.
>
> We are having doubts about the db io part. Even with connection
> pooling and cache, there is a strong chance that server will block on
> db. Blocking for even few ms is bad.
>
> can someone suggest some solutions or is async-io is not at the prime-
> time yet.
>

Can you farm off DB requests to another process, so that you're at
least not blocking the main process?

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


Seeking help: reading text file with genfromtxt

2012-04-04 Thread frankenstein

Hi all

I have got a text file which is only 32 MB in size and consists of the
following type of lines (columns are fixed):

==
Header text 1 line
...
01-Jan-2006   0055   145.069
-16.0449   83.2246   84.2835 499.14680
0.074029965
01-Jan-2006   0065   15.069  -1.0449
83.2246   84.2835 499.14680   12.074029965
...
12-Dec-2006   1255   145.069
23.0449   3.2246   4.2835 49.140
0.74029965
...
==

I have 3 questions:

1. Why is my translation (read_slow) of the IDL code so damn slow
(IDL: 13 sec, Python:2min16sec). Although both IDL and Python consume
about 40 MB.

2. Why is my faster version (read_fast) (13sec) so memory hungry (it
takes 200MB)?
2.1 Why is my second fastest version (read_second_fast) (16sec) still
memory hungry?

3. What do I need to do to get the speed of IDL and the memory
footprint of IDL (in that case 40MB)?


#convdate converts the date in the first column (e.g. 12-Dec-2006)
into day of year
#convtime does something else
==
import fileinput
import numpy as np
import datetime
import time
from StringIO import StringIO

def read_slow(file):

count=max(enumerate(open(file)))[0]

erg=np.zeros((count,10),dtype=np.float64)

convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday
convtime= lambda x: np.int(np.float64(x)*1.0e-1)

i=0
with open(file) as infile:
#read first header line
infile.readline()
for line in infile:
tmp=np.genfromtxt(StringIO(line),\
   dtype=np.float64,\
   converters={0:convdate,
1:convtime})
   #not sure if it does the right thing here:
   erg[i,:]=tmp
   i=i+1
infile.close()
return erg

==
def read_fast(file):

convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday
convtime= lambda x: np.int(np.float64(x)*1.0e-1)

with open(file) as infile:
erg=np.genfromtxt(infile, autostrip=True,skip_header=1,\
  dtype=np.float64,\
  converters={0:convdate,1:convtime})
infile.close()
return erg
==

==
def read_second_fast(file):

convdate= lambda x: time.strptime(x,"%d-%b-%Y").tm_yday
convtime= lambda x: np.int(np.float64(x)*1.0e-1)


erg=np.loadtxt(file,skiprows=1,\
   dtype=np.float64,\
   converters={0:convdate,1:convtime})
return erg
==

Thanks for all the help.

By the way: I colleague told me my code is 1. poorly written and more
or less unreadable and unmaintainable because of the use of lambda. I
am just learning but is his observation true?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Async IO Server with Blocking DB

2012-04-04 Thread Jon Clements
On Tuesday, 3 April 2012 23:13:24 UTC+1, looking for  wrote:
> Hi
> 
> We are thinking about building a webservice server and considering
> python event-driven servers i.e. Gevent/Tornado/ Twisted or some
> combination thereof etc.
> 
> We are having doubts about the db io part. Even with connection
> pooling and cache, there is a strong chance that server will block on
> db. Blocking for even few ms is bad.
> 
> can someone suggest some solutions or is async-io is not at the prime-
> time yet.
> 
> Thanks

Maybe look at Cyclone (a Tornado variation built on Twisted), and various 
modules that will offer synch and events - GIYF! It's doable!

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


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-04 Thread rusi
On Apr 3, 11:42 pm, Nathan Rice 
wrote:
> Lets start with some analogies.  In cooking, chefs use recipes to
> produce a meal; the recipe is not a tool.  In architecture, a builder
> uses a blueprint to produce a building; the blueprint is not a tool.
> In manufacturing, expensive machines use plans to produce physical
> goods; the plans are not the tool.
>
> You could say the compiler is a tool, or a development environment is
> a tool.  The programming language is a mechanism for communication.

Long personal note ahead.
tl;dr version: Computers are such a large shift for human civilization
that generally we dont get what that shift is about or towards.
--
Longer version
My mother often tells me (with some awe): You are so clever! You know
how to use computers! (!?!?)

I try to tell her that a computer is not a machine like a car is (she
is better with things like cars than most of her generation).  Its
physical analogy to a typewriter is surprisingly accurate.  In fact
its more like a pen than other machines and its civilizational
significance is larger than Gutenbergs press and is on par with the
'invention' (or should I say discovery?) of language as a fundamental
fact of what it means to be human.

[At this point or thereabouts my communication attempt breaks down
because I am trying to tell her of the huge significance of
programming...]

A pen can be used to write love-letter or a death-sentence, a text-
book of anatomy or a symphony.
An yet it would be a bizarre superman who could do all these.
Likewise (I vainly try to communicate with my mother!) that I cant
design machines (with autocad) or paint (with photoshop) or ...
probably 99% of the things that people use computers for.
And so saying that I 'know computers' is on par with saying that
because I know (how to use a pen to) fill up income tax forms, I
should also know how to (use a pen to) write Shakespearean sonnets.

There is a sense in which a pen is a 'universal device.'  To some
extent the layman can get this.
There is a larger sense in which the computer is a universal device
(aka universal turing machine).
In my experience, not just 'my mother's' but even PhDs in computer
science dont get what this signifies.

This sense can (somewhat?) be appreciated if we see that the pen is
entirely a declarative tool
The computer is declarative+imperative.
The person who writes the love-letter needs the postman to deliver it.
The judge may write the death-sentence. A hangman is needed to execute
it.
When it comes to computers, the same device can write the love-letter/
death-sentence as the one which mails/controls the electric chair.

Let me end with a quote from Dijkstra: 
http://www.smaldone.com.ar/documentos/ewd/EWD1036_pretty.html

In the long run I expect computing science to transcend its parent
disciplines, mathematics and logic, by effectively realizing a
significant part of Leibniz's Dream of providing symbolic calculation
as an alternative to human reasoning. (Please note the difference
between "mimicking" and "providing an alternative to": alternatives
are allowed to be better.)

Needless to say, this vision of what computing science is about is not
universally applauded. On the contrary, it has met widespread --and
sometimes even violent-- opposition from all sorts of directions. I
mention as examples

(0) the mathematical guild, which would rather continue to believe
that the Dream of Leibniz is an unrealistic illusion

(1) the business community, which, having been sold to the idea that
computers would make life easier, is mentally unprepared to accept
that they only solve the easier problems at the price of creating much
harder one

(2) the subculture of the compulsive programmer, whose ethics
prescribe that one silly idea and a month of frantic coding should
suffice to make him a life-long millionaire

(3) computer engineering, which would rather continue to act as if it
is all only a matter of higher bit rates and more flops per second

(4) the military, who are now totally absorbed in the business of
using computers to mutate billion-dollar budgets into the illusion of
automatic safety

(5) all soft sciences for which computing now acts as some sort of
interdisciplinary haven

(6) the educational business that feels that, if it has to teach
formal mathematics to CS students, it may as well close its schools.
-- 
http://mail.python.org/mailman/listinfo/python-list


igraph and usage of Read(klass, f, format=None, *args, **kwds) question

2012-04-04 Thread ishwar . rattan
I have a file with with adjacency list of an undirected graph one vertex list 
per input line [0 1, 1 2 3, 2 1, 3 1] assume a newline for commas (file is 
named adjl.txt). Can some one give an example of loading this into graph of 4 
vertices?

import igraph
g = igraph.Graph()
g.Read("adjl.txt", "edgelist")
   does not work..

Help will be appreciated.
-ishwar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xlrd 0.7.6 released!

2012-04-04 Thread Chris Withers

On 04/04/2012 09:57, Karim wrote:

Hello,

This release manage the '.xlsx' format?


No, that is planned for the 0.8 release.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Programing Art or Science?

2012-04-04 Thread Chiron
On Wed, 04 Apr 2012 03:33:24 -0400, Shmuel (Seymour J.) Metz wrote:

> If the term "art" is good enough for Knuth it's good enough for me.

I think that may be the most intelligent comment so far...


-- 
Some rise by sin and some by virtue fall.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getaddrinfo NXDOMAIN exploit - please test on CentOS 6 64-bit

2012-04-04 Thread John Nagle

On 4/2/2012 6:53 PM, John Nagle wrote:

On 4/1/2012 1:41 PM, John Nagle wrote:

On 4/1/2012 9:26 AM, Michael Torrie wrote:

On 03/31/2012 04:58 PM, John Nagle wrote:



Removed all "search" and "domain" entries from /etc/resolve.conf


It's a design bug in glibc. I just submitted a bug report.

http://sourceware.org/bugzilla/show_bug.cgi?id=13935


  The same bug is in "dnspython". Submitted a bug report there,
too.

   https://github.com/rthalley/dnspython/issues/6

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


Re: Number of languages known [was Re: Python is readable] - somewhat OT

2012-04-04 Thread Nathan Rice
On Wed, Apr 4, 2012 at 1:49 AM, Steven D'Aprano
 wrote:
> On Tue, 03 Apr 2012 13:17:18 -0400, Nathan Rice wrote:
>
>> I have never met a programmer that was not completely into computers.
>> That leaves a lot unspecified though.
>
> You haven't looked hard enough. There are *thousands* of VB, Java, etc.
> code monkeys who got into programming for the money only and who have
> zero inclination to expand their skills or knowledge beyond that
> necessary to keep their job.

Every programmer that I've ever met who got into it for the money has
washed out within about five years.  Sometimes they make a lateral
move to project management, other times they end up as requirements
analysts, and occasionally they become technical sales staff.  The
story is always the same - they do technical mediocre work, but get
along well with their peers, so they are transitioned to a role that
requires more people skills.

I've never met someone who had both poor people skills and mediocre
technical skills who actually kept their job.

> Go to programming blogs, and you will find many examples of some
> allegedly professional programmer selecting an arbitrary blog post to ask
> "Pls sombody write me this code", where "this code" is either an utterly
> trivial question or a six month project.

Honestly, I have seen that, but usually when I inspect closer it is an
Indian ODesk or Rent-a-coder worker who oversold himself and is trying
to cover his ass.

>> As part of my troll-outreach effort, I will indulge here.  I was
>> specifically thinking about some earlier claims that programming
>> languages as they currently exist are somehow inherently superior to a
>> formalized natural language in expressive power.
>
> I would argue that they are, but only for the very limited purpose for
> which they are written. With the possible exception of Inform 7, most
> programming languages are useless at describing (say) human interactions.
>
> Human languages are optimised for many things, but careful, step-by-step
> algorithms are not one of them. This is why mathematicians use a
> specialist language for their problem domain, as do programmers. Human
> language is awfully imprecise and often ambiguous, it encourages implicit
> reasoning, and requires a lot of domain knowledge:

You have to be careful when you bring mathematical notation into the
picture.  Remember that mathematics has developed over thousands of
years, with developments shared in many languages.  Greek letters
serve the same purpose in math that latin and greek names serve in
biology - they are neutral and avoid confusion with common names in
"living" languages.  Not everything about mathematical notation is
good, and in some cases it suffers the same issues that programming
does.  Mathematicians have a tendency to be very terse, and although
some greek letters and symbols have standard meaning, many authors run
roughshod over them.  Logic is somewhat better than math in this
regard, logicians respect their notation and rarely deviate from the
standard meaning of symbols.  Things ARE getting better, but for the
most part it is still kind of a mess.

Also, I should clarify that I consider part of mathematical notation
to be "natural language", namely +/-/*, and rational numbers.  People
"discover" these things on their own, mathematics just provides rigor.
 It is considered bad form to use them in prose, but that is just an
arbitrary "style" restriction; children intermix mathematical symbols
and language all the time, as to older students taking notes in a
variety of subjects.

>    Joe snatched the hammer from Fred. "Hey," he said, "what are
>    you doing? Don't you know that he'll hit the roof if he catches
>    you with that?"

Are you trying to get me to write obfuscated code?  You can write
ambiguous garbage in any language.

>> The crux of my view is that programming languages exist in part because
>> computers in general are not smart enough to converse with humans on
>> their own level, so we have to talk to them like autistic 5 year-olds.
>> That was fine when we didn't have any other options, but all the pieces
>> exist now to let computers talk to us very close to our own level, and
>> represent information at the same way we do.
>
> I think you're dreaming. We (that is to say, human beings in general, not
> you and I specifically) cannot even talk to each other accurately,
> precisely and unambiguously all the time. Natural language simply isn't
> designed for that -- hence we have specialist languages like legal
> jargon, mathematics, and programming languages, for specialist purposes.

Legalese is English with a ton of new words.  Mathematics is older
than most languages in current use and has a lot of baggage that is
(very) slowly being dealt with.

Programming really can't take the relaxed attitude about cleaning up
notation and vocabulary that we see in math.  Mathematicians spend a
lot of time thinking, and the transcription of their thoughts is a
relati

Re: No os.copy()? Why not?

2012-04-04 Thread Thomas Rachel

Am 03.04.2012 11:34 schrieb John Ladasky:

I use subprocess.call() for quite a few other things.

I just figured that I should use the tidier modules whenever I can.


Of course. I only wanted to point out that os.system() is an even worse 
approach. shutils.copy() is by far better, of course.

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


Re: Run once while loop

2012-04-04 Thread Benjamin Kaplan
On Wed, Apr 4, 2012 at 9:21 AM, Anatoli Hristov  wrote:
> I thing the best will be if I use hundreds of the seconds to print the
> message.
>
> for example at 12:00:00:10, but unfortunately I cant see that I can use
> hundreds of the seconds.
>
> Does anyone knows if I can use it ?
>
> Thanks
>
> Anatoli
>
>

Your proposed solution is one of those hacks that will cause your
program to fail if we get better machines that could run that loop
twice in 1/100th of a second. "When the only tool you have is a
hammer, every problem looks like a nail". You need to add more tools
to your toolbox than an infinite loop. If your problem is that you
want to trigger an event at a specific time, John's answer is the
correct one. If your entire program is just this recurring task, use
your OS's task scheduler (Task Scheduler for Windows, Launchd for Mac
OS X, and Cron for other *nixes).

> On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan 
> wrote:
>>
>> On Tue, 3 Apr 2012 23:00:22 +0200
>> Anatoli Hristov  wrote:
>>
>> > On 03 Apr 2012, at 22:45, Ian Kelly  wrote:
>> >
>> > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov 
>> > > wrote:
>> > >> Hi,
>> > >>
>> > >> I'm trying to do a while loop with condition of time if time is
>> > >> 12:00:00 print text, but for this one second the text is printed at
>> > >> least 50 times, how can I print only once?
>> > >
>> > > Set a flag when you print the text to indicate that you've already
>> > > printed it, and don't print it again if the flag is set.  When it's no
>> > > longer 12:00:00, reset the flag.
>> > >
>> > > That said, a busy while loop is probably the wrong way to do this,
>> > > because it will run your CPU at 100%.  Better would be to put the
>> > > thread to sleep with time.sleep() calls or a real event loop with a
>> > > timer event.
>> > >
>> > > Cheers,
>> > > Ian
>> >
>> > Thank you Ian,
>> >
>> > what if I wait for other conditions if I use time.sleep for 1 sec? it
>> > means that all the program is sleeping for a sec.
>> >
>>
>> If I understand correctly, you don't want the whole program to sleep. If
>> that's the case, you could use threading.Timer, for example:
>>
>> import threading, time
>>
>> def twelve():
>>    print("It's twelve o'clock")
>>
>> local_secs = (time.time() - time.timezone) % (24 * 60 * 60)
>> secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60))
>>
>> wait_till_12 = threading.Timer(secs_till_12, twelve)
>> wait_till_12.start()
>>
>>
>> Regards,
>>
>> John
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Run once while loop

2012-04-04 Thread Anatoli Hristov
I thing the best will be if I use hundreds of the seconds to print the
message.

for example at 12:00:00:10, but unfortunately I cant see that I can use
hundreds of the seconds.

Does anyone knows if I can use it ?

Thanks

Anatoli



On Wed, Apr 4, 2012 at 2:25 PM, John O'Hagan wrote:

> On Tue, 3 Apr 2012 23:00:22 +0200
> Anatoli Hristov  wrote:
>
> > On 03 Apr 2012, at 22:45, Ian Kelly  wrote:
> >
> > > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov 
> wrote:
> > >> Hi,
> > >>
> > >> I'm trying to do a while loop with condition of time if time is
> > >> 12:00:00 print text, but for this one second the text is printed at
> > >> least 50 times, how can I print only once?
> > >
> > > Set a flag when you print the text to indicate that you've already
> > > printed it, and don't print it again if the flag is set.  When it's no
> > > longer 12:00:00, reset the flag.
> > >
> > > That said, a busy while loop is probably the wrong way to do this,
> > > because it will run your CPU at 100%.  Better would be to put the
> > > thread to sleep with time.sleep() calls or a real event loop with a
> > > timer event.
> > >
> > > Cheers,
> > > Ian
> >
> > Thank you Ian,
> >
> > what if I wait for other conditions if I use time.sleep for 1 sec? it
> > means that all the program is sleeping for a sec.
> >
>
> If I understand correctly, you don't want the whole program to sleep. If
> that's the case, you could use threading.Timer, for example:
>
> import threading, time
>
> def twelve():
>print("It's twelve o'clock")
>
> local_secs = (time.time() - time.timezone) % (24 * 60 * 60)
> secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60))
>
> wait_till_12 = threading.Timer(secs_till_12, twelve)
> wait_till_12.start()
>
>
> Regards,
>
> John
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Run once while loop

2012-04-04 Thread John O'Hagan
On Tue, 3 Apr 2012 23:00:22 +0200
Anatoli Hristov  wrote:

> On 03 Apr 2012, at 22:45, Ian Kelly  wrote:
> 
> > On Tue, Apr 3, 2012 at 2:36 PM, Anatoli Hristov  wrote:
> >> Hi,
> >>
> >> I'm trying to do a while loop with condition of time if time is
> >> 12:00:00 print text, but for this one second the text is printed at
> >> least 50 times, how can I print only once?
> >
> > Set a flag when you print the text to indicate that you've already
> > printed it, and don't print it again if the flag is set.  When it's no
> > longer 12:00:00, reset the flag.
> >
> > That said, a busy while loop is probably the wrong way to do this,
> > because it will run your CPU at 100%.  Better would be to put the
> > thread to sleep with time.sleep() calls or a real event loop with a
> > timer event.
> >
> > Cheers,
> > Ian
> 
> Thank you Ian,
> 
> what if I wait for other conditions if I use time.sleep for 1 sec? it
> means that all the program is sleeping for a sec.
> 

If I understand correctly, you don't want the whole program to sleep. If
that's the case, you could use threading.Timer, for example:

import threading, time

def twelve():
print("It's twelve o'clock")

local_secs = (time.time() - time.timezone) % (24 * 60 * 60)
secs_till_12 = 12 * 60 * 60 - (local_secs % (12 * 60 * 60))

wait_till_12 = threading.Timer(secs_till_12, twelve)
wait_till_12.start()


Regards,

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


Re: Is Programing Art or Science?

2012-04-04 Thread Seymour J.
In <87hax0suun@sapphire.mobileactivedefense.com>, on 04/03/2012
   at 04:22 PM, Rainer Weikusat  said:

>http://en.wikipedia.org/wiki/Liberal_arts

Do you need the Quadrivium or is the Trivium enough for programming
?

If the term "art" is good enough for Knuth it's good enough for me.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

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


Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Wed, Apr 4, 2012 at 10:08 PM, Roy Smith  wrote:
> Slightly off-topic, but are there file systems these days which support
> off-line copying?  If I have a disk at the other end of a network link,
> it would be nice to tell the disk to copy a file and tell me when it's
> done.

Depends on your network protocol. One of the coolest and oldest tricks
with FTP is initiating a file transfer from one remote host to
another; I've never done it but it ought to work with localhost (ie
two sessions to the same host).

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


Re: No os.copy()? Why not?

2012-04-04 Thread Roy Smith
In article <87fwcj4zru@dpt-info.u-strasbg.fr>,
 Alain Ketterlin  wrote:

> And sparse files are really hard to reproduce, at least on Unix: on
> Linux even the system's cp doesn't guarantee sparseness of the copy (the
> manual mentions a "crude heuristic").

I imagine the heuristic is to look for blocks of all zeros.  The problem 
is, unless you know the block size of the file system, you can only 
guess as to how many zeros in a row you need to look for.

In the old days, dump/restore used to know about sparse files.  But 
things like dump/restore really get inside the file system's kimono.  In 
today's world of SANs, WANs, and all sorts of virtual file-system-ish 
things, I would expect that's less common.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No os.copy()? Why not?

2012-04-04 Thread Roy Smith
On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote:
> > cp is not a system command, it's a shell command.  Why not just use the
> > incredibly simple and portable
> > 
> >>>>open("outfile", "w").write(open("infile").read())

In article <4f7be1e8$0$2$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> Because your cp doesn't copy the FILE, it copies the file's CONTENTS, 
> which are not the same thing.

Not to mention that this will read the entire contents of the file into 
memory at once.  Probably don't want to do that with 100 GB of data.

Slightly off-topic, but are there file systems these days which support 
off-line copying?  If I have a disk at the other end of a network link, 
it would be nice to tell the disk to copy a file and tell me when it's 
done.  As opposed to dragging all that data over the network just so I 
can buffer it in local memory and shove it right back out the network 
port to the same disk.  That kind of stuff used to be standard practice 
in the neanderthalic days of IBM mainframes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No os.copy()? Why not?

2012-04-04 Thread Alain Ketterlin
Steven D'Aprano  writes:

> On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote:
>
>> On 03/28/12 16:12, John Ladasky wrote:

>>> I'm looking for a Python (2.7) equivalent to the Unix "cp" command.

>>>>>open("outfile", "w").write(open("infile").read())

> Because your cp doesn't copy the FILE, it copies the file's CONTENTS, 
> which are not the same thing.
> Consider:
> * permissions
> * access times
> * file ownership
> * other metadata
> * alternate streams and/or resource fork, on platforms that support them
> * sparse files
> By the time you finish supporting the concept of copying the file itself, 
> rather than merely its content, you will have something similar to the 
> shutil.copy command -- only less tested.

A minor point, but shutil.copy only "copies" contents and permissions
(no access times, etc.) You probably mean shutil.copy2.

And sparse files are really hard to reproduce, at least on Unix: on
Linux even the system's cp doesn't guarantee sparseness of the copy (the
manual mentions a "crude heuristic").

But of course shutil.copy is the best solution to mimic a raw cp.

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


Re: Python and Bloomberg

2012-04-04 Thread Bastian Ballmann

Am 03.04.2012 16:35, schrieb smac2...@comcast.net:

Hello, I was just wondering if anyone had experience using Python to
interact with Bloomberg. Ideally, I'd look to use Python to feed
Bloomberg's OVML calculator with a list of inputs, and then use an
additional program to grab the results of the calculator for each
calculation, and pull them into another document, ideally an excel
spreadsheet or alternatively a delimited .txt file.

Any thoughts or ideas are very much appreciated. Thanks!


Bloomberg has got SOAP for many (or all?) of its services.

So maybe you could use SOAPpy to communicate with it.
See http://www.ibm.com/developerworks/library/ws-pyth5/

HTH && Greets

Basti

--
Bastian Ballmann / Web Developer
Notch Interactive GmbH / Badenerstrasse 571 / 8048 Zürich
Phone +41 43 818 20 91 / www.notch-interactive.com

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


Re: xlrd 0.7.6 released!

2012-04-04 Thread Karim

Le 04/04/2012 09:24, Chris Withers a écrit :

And the goat sacrifice continues...

On 03/04/2012 08:34, Chris Withers wrote:

On 03/04/2012 08:04, Chris Withers wrote:

I'm pleased to announce the release of xlrd 0.7.4.

I've just release a 0.7.5 that fixes this.


Except it didn't, I've just released 0.7.6, which will hopefully bring 
an end to the brown-bagging.


Any more problems, please let the python-ex...@googlegroups.com 
mailing list know...


cheers,

Chris


Hello,

This release manage the '.xlsx' format?

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


ANN: bayeux 0.2 released

2012-04-04 Thread Matej Cepl

Bayeux 0.2 is now available at http://pypi.python.org/pypi/bayeux

bayeux is a module for generating TAP (http://testanything.org/).

Version 0.2 is an initial version registered in the Cheesshop.

Release notes:
--

 * module tap.py for programatic writing of TAP stream
 * clone of unittest2 generating TAP stream instead of the normal
   unittest output.
 * example script for generating TAP stream from JSON results of
   piglit test suite.


Links:
--

 * homepage http://pypi.python.org/pypi/bayeux
 * code repository https://gitorious.org/bayeux/bayeux
 * bug reports and enhancement requests to mcepl_at_redhat_dot_com
   or to https://luther.ceplovi.cz/bugzilla/ (product TAP)
--
http://mail.python.org/mailman/listinfo/python-list


Re: No os.copy()? Why not?

2012-04-04 Thread Chris Angelico
On Wed, Apr 4, 2012 at 3:53 PM, Steven D'Aprano
 wrote:
> On Tue, 03 Apr 2012 15:46:31 -0400, D'Arcy Cain wrote:
>
>> def cp(infile, outfile):
>>    open(outfile, "w").write(open(infile).read())
>
> Because your cp doesn't copy the FILE, it copies the file's CONTENTS,
> which are not the same thing.

And, as a subtle point: This method can't create the file "at size". I
don't know how it'll end up allocating space, but certainly there's no
opportunity to announce to the OS at file open/create time "please
allocate X bytes for this file". That may be an utterly trivial point,
or a crucially vital one.

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


Implementing python program running in background.

2012-04-04 Thread Rishabh Verma
I need to implement a simple python program, which will be using the oAuth
tokens and secrets of all users in out system and will be fetching some
stuff from a JSON API. The list of all these users(with a flag if they are
logged-in or not right now) is there in a Redis DB.

The JSON API needs to be queried every 5 minutes for a user who is not
logged-in right now, and every 2 minutes for a user who is logged in right
now. This program should always be running in the background.

What should be the correct way to implement this kind of a thing?
-- 
*Rishabh Verma
@rishabhverma  | +91-8285687993
www.rishabhverma.me*
-- 
http://mail.python.org/mailman/listinfo/python-list


xlrd 0.7.6 released!

2012-04-04 Thread Chris Withers

And the goat sacrifice continues...

On 03/04/2012 08:34, Chris Withers wrote:

On 03/04/2012 08:04, Chris Withers wrote:

I'm pleased to announce the release of xlrd 0.7.4.

I've just release a 0.7.5 that fixes this.


Except it didn't, I've just released 0.7.6, which will hopefully bring 
an end to the brown-bagging.


Any more problems, please let the python-ex...@googlegroups.com mailing 
list know...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: [pyxl] Re: xlrd 0.7.4 released!

2012-04-04 Thread Chris Withers

On 03/04/2012 21:46, Josh English wrote:

When I try to import xlrd, I get an error

IOError: [Errno 2] No such file or directory:
'C:\\Users\\josh\\Desktop\\Portable
Python\\App\\lib\\site-packages\\xlrd-0.7.5-py2.7.egg\\xlrd\\version.txt'


*sigh* I hate python packaging, I'll get a 0.7.6 release out this 
morning which will hopefully finally fix this...



I didn't think EGG files could be folders. Is there a change in the way
the EGG file was meant to be distributed?


Eggs have always been installed as folders.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list