comp.lang.python - 20 new messages in 14 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* file seek is slow - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f9c31a229cdda107?hl=en
* Can't define __call__ within __init__? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/6c1e03e9d76cf596?hl=en
* Elementtree install problem in Ubuntu (a newbie ..) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/1cb5a8949024bc05?hl=en
* Can't install PIL on MacOS X Leopard - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/d17d85801f0f6fff?hl=en
* Does this already exists?: A module that checks if the used platform is
supported - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/51b6a2342cac2397?hl=en
* Importing Modules - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/74ded42ce8e146c3?hl=en
* Method / Functions - What are the differences? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/72ab93ba395822ed?hl=en
* Interacting With Another Script - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/fc3663ea0d0af3a6?hl=en
* Python Script to get Info from Site not working - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/4741fd660fb9b691?hl=en
* Ideas for creating processes - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/104bababcbab6607?hl=en
* Knight's tour Warndorff's algorithm problem - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f11741c5feca9e9f?hl=en
* Can't install ssl for Python2.5 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/70e590788ceae40f?hl=en
* os.rename [Errno 31] Too many links - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/89faea869c513d3e?hl=en
* Anything like "Effective Java" for Python? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/47674ff2d2c78fa6?hl=en
==============================================================================
TOPIC: file seek is slow
http://groups.google.com/group/comp.lang.python/t/f9c31a229cdda107?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 3:38 pm
From: "sjdevnull@yahoo.com"
On Mar 10, 6:01 pm, Neil Hodgson <nyamatongwe+thun...@gmail.com>
wrote:
> Metalone:
>
> > As it turns out each call is only
> > 646 nanoseconds slower than 'C'.
> > However, that is still 80% of the time to perform a file seek,
> > which I would think is a relatively slow operation compared to just
> > making a system call.
>
> A seek may not be doing much beyond setting a current offset value.
> It is likely that fseek(f1, 0, SEEK_SET) isn't even doing a system call.
Exactly. If I replace both calls to fseek with gettimeofday (aka
time.time() on my platform in python) I get fairly close results:
$ ./testseek
4.120
$ python2.5 testseek.py
4.170
$ ./testseek
4.080
$ python2.5 testseek.py
4.130
FWIW, my results with fseek aren't as bad as those of the OP. This is
python2.5 on a 2.6.9 Linux OS, with psyco:
$ ./testseek
0.560
$ python2.5 testseek.py
0.750
$ ./testseek
0.570
$ python2.5 testseek.py
0.760
==============================================================================
TOPIC: Can't define __call__ within __init__?
http://groups.google.com/group/comp.lang.python/t/6c1e03e9d76cf596?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Mar 10 2010 3:38 pm
From: Neal Becker
Robert Kern wrote:
> On 2010-03-10 12:23 PM, Neal Becker wrote:
>> Duncan Booth wrote:
>> ...
>>>
>>> P.S. I don't know what you did in your post but your Followup-To header
>>> is pointing to a group on gmane which makes extra work for me replying.
>>> Please don't do that.
>>
>> I'm sorry about that, there is some bad interaction between gmane's nntp-
>> smtp gateway and python's mail list. I don't know what to do about it.
>> I think the problem only happens on python's mail list (I've never seen
>> it reported on any of the MANY other lists I use via gmane).
>
> I think it may be your news reader adding the Original-Followup-To header.
> I use Thunderbird 3 to read this list via GMane, too, but my posts do not
> contain the header. What newsreader are you using?
>
knode.
== 2 of 2 ==
Date: Wed, Mar 10 2010 7:18 pm
From: Steven D'Aprano
On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote:
> Want to switch __call__ behavior. Why doesn't this work? What is the
> correct way to write this?
>
> class X (object):
> def __init__(self, i):
> if i == 0:
> def __call__ (self):
> return 0
> else:
> def __call_ (self):
> return 1
Others have already pointed out that there are two reasons that won't
work:
(1) you define __call__ as a local variable of the __init__ method which
then disappears as soon as the __init__ method completes; and
(2) special methods like __call__ are only called on the class, not the
instance, so you can't give each instance its own method.
Perhaps the best way to solve this is to use delegation:
def zero_returner():
return 0
def one_returner():
return 1
class X (object):
def __init__(self, i):
if i == 0:
self.func = zero_returner
else:
self.func = one_returner
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
zero_returner and one_returner can be any callable object, not
necessarily a function.
Of course, all this assumes that your solution isn't even simpler:
class X (object):
def __init__(self, i):
self.i = i
def __call__(self):
return self.i
but I assume if it was that simple, you would have done that already.
--
Steven
==============================================================================
TOPIC: Elementtree install problem in Ubuntu (a newbie ..)
http://groups.google.com/group/comp.lang.python/t/1cb5a8949024bc05?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 3:56 pm
From: Philip Semanchuk
On Mar 10, 2010, at 6:48 PM, robert somerville wrote:
> Hi ;
> I installed the elementtree and celementree packages throught the
> synaptic
> package manager, all seems to go fine through the install ...
>
> when i startup python and try to import them (as per the EFFBOTT.org
> suggestions) .. PROBLEMS ... (see below ..) What am i doing
> wrong ??? this
> is a new window after installation of packages ...
>
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import elementtree.ElementTree as ET
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named elementtree.ElementTree
>>>> import elementtree
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named elementtree
Hi Robert,
In Python >= 2.5, ElementTree is part the standard library so it
doesn't need to be installed separately. Here's the documentation for
it:
http://www.python.org/doc/2.6.4/library/xml.etree.elementtree.html
HTH
Philip
==============================================================================
TOPIC: Can't install PIL on MacOS X Leopard
http://groups.google.com/group/comp.lang.python/t/d17d85801f0f6fff?hl=en
==============================================================================
== 1 of 3 ==
Date: Wed, Mar 10 2010 4:05 pm
From: phantasm
Hello!
I'm trying to install PIL module on MacOS X Leopard with python 2.6.
Everything seemed to be fine - now I have PIL egg package in "site-
packages" directory, but when I'm trying "import PIL", I get an error
"ImportError: No module named PIL".
All other modules such as SQL Alchemy work fine. Their EGGs reside in
a same directory as a resulting PIL package.
I've tried to install either via easy_install and manually, results
are the same. PYTHONPATH environment variable is set to a correct
directory. python command "import _imaging" returns no error.
What I'm doing wrong?
== 2 of 3 ==
Date: Wed, Mar 10 2010 4:34 pm
From: Ned Deily
In article
<94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com>,
phantasm <genetiq@gmail.com> wrote:
> I'm trying to install PIL module on MacOS X Leopard with python 2.6.
> Everything seemed to be fine - now I have PIL egg package in "site-
> packages" directory, but when I'm trying "import PIL", I get an error
> "ImportError: No module named PIL".
>
> All other modules such as SQL Alchemy work fine. Their EGGs reside in
> a same directory as a resulting PIL package.
>
> I've tried to install either via easy_install and manually, results
> are the same. PYTHONPATH environment variable is set to a correct
> directory. python command "import _imaging" returns no error.
>
> What I'm doing wrong?
Hard to say without more information but it does seem odd that _imaging
can be imported. One thing to try:
$ python2.6
Python 2.6.4 (r264:75706, Oct 28 2009, 20:34:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
>>> _imaging.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pac
kages/PIL/_imaging.so'
# or something like that
Make sure the file is located within the expected PIL directory. Also
make sure there aren't any file permission problems on any of the PIL
directories and files. I'm assuming PIL was installed as an unzipped
egg. And double-check the contents of any .pth files.
--
Ned Deily,
nad@acm.org
== 3 of 3 ==
Date: Wed, Mar 10 2010 4:43 pm
From: phantasm
Thank you for your reply, Ned, but I just tried to install it again
and found out that I didn't finally run "python setup.py install"
after building PIL manually. It solved the problem.
==============================================================================
TOPIC: Does this already exists?: A module that checks if the used platform is
supported
http://groups.google.com/group/comp.lang.python/t/51b6a2342cac2397?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 5:37 pm
From: "Gabriel Genellina"
En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig
<martin.hellwig@dcuktec.org> escribió:
> Before I start reinventing a squared wheel, I have the following
> question:
> Is there already a (standard) module that wraps around the various
> os/sys information which checks if the platform + version is supported
> for what I want to do with it.
In case you were not aware of it: see the platform module. But you'll have
to do the checks yourself (based on the info it returns).
--
Gabriel Genellina
==============================================================================
TOPIC: Importing Modules
http://groups.google.com/group/comp.lang.python/t/74ded42ce8e146c3?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 5:37 pm
From: "Gabriel Genellina"
En Wed, 10 Mar 2010 09:19:29 -0300, PEYMAN ASKARI <paskari007@yahoo.ca>
escribió:
> I wanted to know if imported classes are treated differently than
> internal classes.
If by 'internal classes' you mean 'classes defined in the main module',
no, they're absolutely the same.
> class A():
> __init__(self):
> pass
>
> and call A, or A() I get something to the effect of <__main__.A
> instance at 0xb7f088ac>
>
> but if I call from module_name import A and then call A or A() I get
> something to the effect of <module_4.module_4 instance at 0xb7f0882c>
Note that both reprs have the same structure. Both say
<modulename.classname instance at ...>
When you execute `python test_import.py`, the code is executed into a
newly created module called __main__ (not test_import). So __main__ is the
name of the main module, and __main__.A is the full name of the A class
defined in the __main__ module.
In the other case, module_4.module_4 is the full name of the module_4
class defined in the module_4 module.
> I was wondering if this would be a problem.
In general, no, you shouldn't care. There is a problem, though, if some
other module imports the main one (using `import test_import`). Python
knows the main one as "__main__", not as "test_import", so it will load it
*again*, and you'll end with two separate copies of the same module.
Solution: don't do that :) -- redesign your application so subordinate
modules don't have to import the main one (move the required parts into a
third module).
--
Gabriel Genellina
==============================================================================
TOPIC: Method / Functions - What are the differences?
http://groups.google.com/group/comp.lang.python/t/72ab93ba395822ed?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 5:37 pm
From: "Gabriel Genellina"
En Wed, 10 Mar 2010 11:45:38 -0300, John Posner <jjposner@optimum.net>
escribió:
> As I promised/threatened, here's the *start* of a write-up on
> properties, aimed at non-advanced Python programmers:
>
> http://www.jjposner.net/media/python-properties-0310.pdf
I'd use 'function' instead of 'procedure', as this last word is very
uncommon in Python literature (also, "the procedure's return value..." may
look very strange to some people).
I'm unsure if one should make a distinction 'storage attribute' vs.
'method attribute', or even if it makes things actually more clear. I
think you could present the motivating idea first ("I want to execute some
code when accessing an attribute") and only later talk about properties
and descriptors (as written, the reader still doesn't know how to define a
simple property and you've already talked about deleting attributes...)
--
Gabriel Genellina
==============================================================================
TOPIC: Interacting With Another Script
http://groups.google.com/group/comp.lang.python/t/fc3663ea0d0af3a6?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Mar 10 2010 5:37 pm
From: "Gabriel Genellina"
En Wed, 10 Mar 2010 09:32:15 -0300, Victor Subervi
<victorsubervi@gmail.com> escribi�:
> There's a program (vpopmail) that has commands which, when called,
> request
> input ("email address", "password", etc.) from the command line. I would
> like to build a TTW interface for my clients to use that interacts with
> these commands.
I know nothing about vpopmail, but can't you provide all the required
information by some other means? Command line arguments, a configuration
file, perhaps there is an API to call some internal functions? Faking an
interactive session would be my last option.
--
Gabriel Genellina
== 2 of 2 ==
Date: Wed, Mar 10 2010 6:16 pm
From: alex23
Victor Subervi <victorsube...@gmail.com> wrote:
> > There's a program (vpopmail) that has commands which, when called, request
> > input ("email address", "password", etc.) from the command line. I would
> > like to build a TTW interface for my clients to use that interacts with
> > these commands.
The Pexpect[1] module is pretty much aimed at doing exactly this.
1: http://www.noah.org/wiki/Pexpect
==============================================================================
TOPIC: Python Script to get Info from Site not working
http://groups.google.com/group/comp.lang.python/t/4741fd660fb9b691?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Mar 10 2010 5:38 pm
From: "Gabriel Genellina"
En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo <nilly16@yahoo.com> escribió:
> I found a semi Python & internet tutorial here if anyone else would
> like it http://www.upriss.org.uk/python/session6.html
>
> My script is meant to find which radio button is selected & tell me
> that. But it just keeps saying "No Drink Selected!"
Are you sure? From the code you posted, the message should read "You need
to select a drink!", not that one.
> if drink == "tea":
> print("You requested tea.")
> elif drink == "coffee":
> print("You requested coffee.")
> elif drink == "hot chocolate":
> print ("You requested hot chocolate.")
> else:
> print ("You need to select a drink!")
Replace the last line with something like this, to see what you are
getting exactly:
print("Sorry, no %r (%r) available." % (
drink,
cgi.escape(repr(type(drink)))))
BTW, which Python version are you using? The tutorial you linked to is
aimed at Python 2.x, but your print syntax suggests you're using Python 3.x
--
Gabriel Genellina
== 2 of 2 ==
Date: Wed, Mar 10 2010 6:26 pm
From: Jimbo
On Mar 11, 12:38 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo <nill...@yahoo.com> escribió:
>
> > I found a semi Python & internet tutorial here if anyone else would
> > like ithttp://www.upriss.org.uk/python/session6.html
>
> > My script is meant to find which radio button is selected & tell me
> > that. But it just keeps saying "No Drink Selected!"
>
> Are you sure? From the code you posted, the message should read "You need
> to select a drink!", not that one.
> Replace the last line with something like this, to see what you are
> getting exactly:
>
> print("Sorry, no %r (%r) available." % (
> drink,
> cgi.escape(repr(type(drink)))))
>
> BTW, which Python version are you using? The tutorial you linked to is
> aimed at Python 2.x, but your print syntax suggests you're using Python 3.x
>
> --
> Gabriel Genellina
Yeah that("You need to select a drink!") was the string I was getting
but I should be getting hot chocolate or something else(which ever one
I have selected)
I am using 3.x, do you think I should be using something else? Also
the your code I put in does the some thing, just now it says "Sorry no
none drink available" all the time.
==============================================================================
TOPIC: Ideas for creating processes
http://groups.google.com/group/comp.lang.python/t/104bababcbab6607?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 6:52 pm
From: J
On Wed, Mar 10, 2010 at 18:03, MRAB <python@mrabarnett.plus.com> wrote:
> Are you sure that you would gain from doing more than one at a time?
>
> The bottleneck will probably be the speed of your network connection,
> and if that's working at its maximum speed with one sync then doing
> several concurrently won't save any time. (The syncs will also be
> completing for disk I/O.)
Good point MRAB... thanks for making it.
I started to wonder the same thing, but it took me a couple hours away
from working on it and a good dinner before I saw that...
Yeah, looking at it freshly now, I agree, I think I probably would be
better off running them one at a time.
The goal is to update several directories of ISO images with nightly
builds. I can use rsync and only download images that are changed, or
I can use zsync and only download diffs (I believe that's how it
works) which is faster anyway.
The only reason I was considering doing them all simultaneously, or in
batches at least, is that I have to update 10 - 12 ISOs daily... BUT,
now that I look at it from your perspective, yeah, it would probably
be faster overall to do them one at a time instead because of the
bottleneck.
Thanks! That helped a lot (and probably saved me a lot of headache
later on) :-)
Cheers
Jeff
==============================================================================
TOPIC: Knight's tour Warndorff's algorithm problem
http://groups.google.com/group/comp.lang.python/t/f11741c5feca9e9f?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 8:44 pm
From: Terry Reedy
On 3/10/2010 4:49 PM, Lawrence D'Oliveiro wrote:
> In message<mailman.527.1268199449.23598.python-list@python.org>, Gabriel
> Genellina wrote:
>
>> Warnsdorff's algorithm is heuristic ...
>
> Then it shouldn't be called an "algorithm".
Heuristic algorithms correctly compute some function, just not the one
you want ;-).
==============================================================================
TOPIC: Can't install ssl for Python2.5
http://groups.google.com/group/comp.lang.python/t/70e590788ceae40f?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 9:48 pm
From: Lacrima
On Mar 10, 11:23 pm, "Martin v. Loewis" <mar...@v.loewis.de> wrote:
> > I don't know how to solve this problem and I am looking forward for
> > help.
>
> Try running "python setup.py install" directly, after downloading and
> unpacking the package.
>
> Regards,
> Martin
Thanks a lot! It helped!
==============================================================================
TOPIC: os.rename [Errno 31] Too many links
http://groups.google.com/group/comp.lang.python/t/89faea869c513d3e?hl=en
==============================================================================
== 1 of 1 ==
Date: Wed, Mar 10 2010 10:22 pm
From: Richard
On Mar 11, 3:08 am, Thomas Guettler <h...@tbz-pariv.de> wrote:
> Richard wrote:
> > I want to atomically write to a file so have been using temporary
> > files and renaming:
>
> > temp = tempfile.NamedTemporaryFile(delete=False)
> > temp.file.write(data)
> > temp.file.close()
> > os.rename(temp.name, output_file)
>
> > This worked but after 39567 files os.rename raises an OSError: [Errno
> > 31] Too many links
>
> > I can still create files in this directory so I doubt it is a platform
> > limitation.
> > Can you tell what is wrong? Am I not freeing the temporary file
> > resources properly?
>
> If you are on linux you can have a look at the open file descriptors of
> a running process like this:
>
> ls -l /proc/PID/fd/
>
> But I guess it is a limitation of your filesystem. What do you use?
>
> I once had this problem with ext2. It has a low limit for
> subdirectories.
>
> With xfs the limits are much greater.
>
> Thomas
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
I am using Ubuntu 9.10 with ext3, which I believe has a limit for the
number of subdirectories but not files.
Thanks for the open file descriptor tip - I will check that out.
Richard
==============================================================================
TOPIC: Anything like "Effective Java" for Python?
http://groups.google.com/group/comp.lang.python/t/47674ff2d2c78fa6?hl=en
==============================================================================
== 1 of 2 ==
Date: Wed, Mar 10 2010 11:53 pm
From: Stefan Behnel
Chris Withers, 10.03.2010 17:46:
> kj wrote:
>> Subject line pretty much says it all: is there a book like "Effective
>> Java"
>
> oxymoronic, no?
>
> Sorry, couldn't resist ;-)
Nothing to excuse for. I thought exactly the same thing.
Stefan
== 2 of 2 ==
Date: Thurs, Mar 11 2010 12:30 am
From: James Harris
On 10 Mar, 15:19, kj <no.em...@please.post> wrote:
> Subject line pretty much says it all: is there a book like "Effective
> Java" for Python. I.e. a book that assumes that readers are
> experienced programmers that already know the basics of the language,
> and want to focus on more advanced programming issues?
I don't know about the Java book you mention but I find Python in a
Nutshell published by O'Reilly to be a good reference.
James
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en
To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home