Re: Ordering python sets

2008-10-26 Thread Marc 'BlackJack' Rintsch
On Sat, 25 Oct 2008 21:53:10 +, Lie Ryan wrote:

> Oh no, the two dict implementation would work _exactly_ the same from
> the outside, they are transparently interchangeable. Only the
> performance characteristic differs because of the different
> implementation.

They are not 100% interchangeably.  Dictionaries as implemented need keys 
to be hashable objects and sorted dictionaries need the keys to have an 
order defined.  So switching mapping types may fail unless the key 
objects already have the needed magic methods implemented to do the right 
thing.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary

2008-10-26 Thread Bob Martin
in 86949 20081024 205720 "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
>Steven D'Aprano  wrote:
>
>>On Fri, 24 Oct 2008 14:53:19 +, Peter Pearson wrote:
>>
>>> On 24 Oct 2008 13:17:45 GMT, Steven D'Aprano wrote:

 What are programmers coming to these days? When I was their age, we
 were expected to *read* the error messages our compilers gave us, not
 turn to the Interwebs for help as soon there was the tiniest problem.
>>>
>>> Yes, and what's more, the text of the error message was "IEH208".  After
>>> reading it several times, one looked it up in a big fat set of books,
>>> where one found the explanation:
>>>
>>>   IEH208: Your program contains an error. Correct the error and resubmit
>>>   your job.
>>>
>>> An excellent system for purging the world of the weak and timid.
>>
>>You had reference books? You were lucky! When I was lad, we couldn't
>>afford reference books. If we wanted to know what an error code meant, we
>>had to rummage through the bins outside of compiler vendors' offices
>>looking for discarded documentation.
>
>eee!  You were Lucky!
>
>You had Compilers!
>You had Compiler Vendors!
>
>When I was lad, we had nowt but raw hardware.
>We had to sit in cold room, ears deafened by
>whine of fan, clicking switches to load our
>octal in computer. We just had error light...
>
>- Hendrik

Computers?  you had computers?
--
http://mail.python.org/mailman/listinfo/python-list


Re: @property decorator doesn't raise exceptions

2008-10-26 Thread Duncan Booth
Rafe <[EMAIL PROTECTED]> wrote:

> Peter Oten pointed me in the right direction. I tried to reply to his
> post 2 times and in spite of GoogleGroups reporting the post was
> successful, it never showed up.

This is the third variant on your message that has shown up in the 
newsgroup.

Please be aware that messages take time to propogate through usenet: don't 
repost just because Google groups hasn't yet got around to displaying your 
message. If it says the post was successful then the post was successful. 
Just be patient a bit longer for it to become visible to you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I handle the char immediately after its input, without waiting an endline?

2008-10-26 Thread Duncan Booth
Lie Ryan <[EMAIL PROTECTED]> wrote:

> And as far as I know, it is impossible to implement a "press any key" 
> feature with python in a simple way (as it should be). 

"press any key" is a misfeature at the best of times. Quite apart from the 
people who can't find the key with 'any' written on it there are also the 
people who can't figure out why it 'Ctrl', 'Alt', 'Shift', 'Caps Lock' 
aren't keys (not to mention the smartass's who think Ctrl+Break is a key). 
It is better to always ask for a specific key.

Have you tried Google? Googling for "python getch" gives 
http://snippets.dzone.com/posts/show/915 as the first hit.
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread Martin v. Löwis
>>> As far as I can tell, it seems
>>> CPython's current state can't CPU bound parallelization in the same
>>> address space.
>> That's not true.
>>
> 
> Um...  So let's say you have a opaque object ref from the OS that
> represents hundreds of megs of data (e.g. memory-resident video).  How
> do you get that back to the parent process without serialization and
> IPC?

What parent process? I thought you were talking about multi-threading?

> What should really happen is just use the same address space so
> just a pointer changes hands.  THAT's why I'm saying that a separate
> address space is  generally a deal breaker when you have large or
> intricate data sets (ie. when performance matters).

Right. So use a single address space, multiple threads, and perform the
heavy computations in C code. I don't see how Python is in the way at
all. Many people do that, and it works just fine. That's what
Jesse (probably) meant with his remark

>> A c-level module, on the other hand, can sidestep/release
>> the GIL at will, and go on it's merry way and process away.

Please reconsider this; it might be a solution to your problem.

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


Re:: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread Hendrik van Rooyen
"Andy O'Meara"  Wrote:

>Um...  So let's say you have a opaque object ref from the OS that
>represents hundreds of megs of data (e.g. memory-resident video).  How
>do you get that back to the parent process without serialization and
>IPC?  What should really happen is just use the same address space so
>just a pointer changes hands.  THAT's why I'm saying that a separate
>address space is  generally a deal breaker when you have large or
>intricate data sets (ie. when performance matters).

You can try to assign the buffer in the shared memory space, that can
be managed by Nikita the Spider's shm module.

Then you can implement what would be essentially a systolic array
structure, passing the big buffer along to the processes who
may, or may not, be running on different processors, to do whatever
magic each process has to do, to complete the whole transformation.

(filter, fft, decimation, compression, mpeg, whatever...)


This may be faster than forking an OS thread - don't subprocesses get
a COPY of the parent's environment?
<\aside>

But this will give you only one process running at a time, as you
can't do stuff simultaneously to the same data.

So you will need to split a real big ram area into your big buffers so
that each of the processes you contemplate running seperately can be given
one 100 M area (out of the shared big one) to own to do its magic on.
When it is finished, it passes the ownership back, and the block is
assigned to the next process in the sequence, while a new block from
the OS is assigned to the first process, and so on.

So you still have shared ram IPC, but there is no serialisation.
And you don't move the data, unless you want to. You can update
or twiddle in place. Its the serialisation that kills the performance.
And the pointers can be passed by the same mechanism, if I 
understand what shm does after a quick look.

So you can build a real ripsnorter - it rips this, while it
snorts the previous and tears the antepenultimate...

- Hendrik



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


Re: Improving interpreter startup speed

2008-10-26 Thread James Mills
On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> How are you getting those numbers? 330 μs is still pretty fast, isn't
> it? :) Most disks have a seek time of 10-20 ms so it seem implausible
> to me that Ruby would be able to cold start in 47 ms.

$ time python -c "pass"

real0m0.051s
user0m0.036s
sys 0m0.008s

$ time python3.0 -c "pass"

real0m0.063s
user0m0.048s
sys 0m0.004s

And yes I agree. the CPython interpreter startup times is
a stupid thing to be worrying about, especially since that
is never the bottleneck.

Python loads plenty fast enough!

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why can't I assign a class method to a variable?

2008-10-26 Thread Lie Ryan
On Wed, 22 Oct 2008 12:34:26 -0400, ed wrote:

> I'm trying to make a shortcut by doing this:
> 
> t = Globals.ThisClass.ThisMethod
> 
> Calling t results in an unbound method error.
> 
> Is it possible to do what I want?  I call this method in hundreds of
> locations and I'm trying to cut down on the visual clutter.
> 
> Thank you!

Remember that in python when you do:

A_instance = A()
A_instance.foo(a, b)

is actually the same as

A_instance = A()
A.foo(A_instance, a, b)

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


Re: How can I handle the char immediately after its input, without waiting an endline?

2008-10-26 Thread Lie Ryan
On Sun, 26 Oct 2008 09:23:41 +, Duncan Booth wrote:

> Lie Ryan <[EMAIL PROTECTED]> wrote:
> 
>> And as far as I know, it is impossible to implement a "press any key"
>> feature with python in a simple way (as it should be).
> 
> "press any key" is a misfeature at the best of times. Quite apart from
> the people who can't find the key with 'any' written on it there are
> also the people who can't figure out why it 'Ctrl', 'Alt', 'Shift',
> 'Caps Lock' aren't keys (not to mention the smartass's who think
> Ctrl+Break is a key). It is better to always ask for a specific key.

I know about those jokes. And it's the reason why I mentioned that (the 
serious point is about getting one-char input for "command-line GUI" 
applications like curse-based apps that is too simple to include the 
whole curse).

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


Re: Why can't I assign a class method to a variable?

2008-10-26 Thread James Mills
On Thu, Oct 23, 2008 at 2:34 AM, ed <[EMAIL PROTECTED]> wrote:
> I'm trying to make a shortcut by doing this:
>
> t = Globals.ThisClass.ThisMethod
>
> Calling t results in an unbound method error.
>
> Is it possible to do what I want?  I call this method in hundreds of
> locations and I'm trying to cut down on the visual clutter.

I can't help but think there is a better approach to
your problem. Why are you calling in hundreds of places ?
What is it and what does it do ?

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordering python sets

2008-10-26 Thread Lie Ryan
On Sun, 26 Oct 2008 00:53:18 +, Steven D'Aprano wrote:
[...]
> And how do you find an arbitrary object's creation point without
> searching the project's source code?

How is it better using the current way?
Asking the .implementation field isn't much harder than asking the type
(), and is much more obvious that we're asking the "implementation" being 
used.

>>> If I wanted that sort of nightmare, I can already do it by shadowing
>>> the builtin:
>>> 
>>> dict = binarytree
>>> D = dict({'a': 'A'})  # make a binary tree
>> 
>> I DON'T want THAT sort of nightmare you mentioned... And it'd be
>> impossible to have two dictionary that have two different
>> implementations.
>
> Nonsense.
>


There is two good arguments for using a plain string to specify the 
implementation used: 1) Plain-text Configuration, 2) argument passing.

1) The current way requires you have a map of the configuration text to a 
function (i.e. imps = {'linkedlist': linkedlist}), than assign the 
function to _a global name_ (i.e. lista = imps[configuration[confkey]] -- 
namespace pollution), then instantiate an object using that (ls = lista
([...]))). The implementation way, only requires ls = list([...], 
implementation = configuration[confkey])

2) Easily said, plain text passing is safer and easier than passing 
function object.

>>> There is no possible good that come from this suggestion. The beauty
>>> of Python is that the built-in data structures (list, dict, set) are
>>> powerful enough for 99% of uses[1], and for the other 1%, you can
>>> easily and explicitly use something else.
>> 
>> Oh really? As far as I know, python's list is extremely bad if you're
>> inserting data at the beginning of the list
> 
> And how often do you do that?

It's not even a deque yet, a regular queue is slow using list in python, 
and any insertion sort requires you to insert elements into arbitrary 
position. This makes using array for it a O(n**2). On the other hand, 
using binary tree is a O(log n). 

> [...]
>>> But *explicitly* is the point. There's never any time where you can do
>>> this:
>> 
>> Yes, true, explicitly IS the point. How more explicit can you be than:
>> dict({foo: bar}, implementation = 'binarytree')
>> 
>>> type(mydict) is dict
> 
> 
> You miss the point. With your plan, you can do this:
> 
> D1 = dict({foo: bar}, implementation = 'binarytree') D2 = dict({foo:
> bar}, implementation = 'dict') type(D1) is type(D2)
> 
> and yet D1 and D2 have UTTERLY different performance characteristics. 

It does not matter that it have different performance characteristic.

> So
> now you need to add ANOTHER test to distinguish dicts-which-are-dicts
> from dicts-which-are-binary-trees:

How often would you need to care about the specific implementation used? 
Compare with how often you want to know how to work with the object. Most 
of the time, you only need to know how to work with it (i.e. knowing its 
interface), only _sometimes_ when it DOES matter speed-wise, you'd need 
to know and affect its implementation.

> D1.implementation != D2.implementation
> 
> And why? So you can avoid calling a goose a goose, and call it a duck
> instead.

I think we have an utterly different view here.
I wished that list() becomes an abstract type, instead of a data 
structure. (binarytreelist and arraylist is some property of a list)

While you insisted that list() is a data structure, and abstract type is 
some obscureness somewhere unknown. 

>> If my memory serves right, binary tree dict and hashed table dict is
>> both a dict right? (Duck Typing)
>> Only their implementation differs. Implementation is... well,
>> "implementation detail".
> 
> Duck typing refers to *interface*, not implementation. 

Well said, you've just supported my view. 

> I have no problem
> with you using a type with the same interface as a dict. That's what
> duck typing is all about. Just don't call it a dict!

why do you think binarytreedict is "less dict" than hasheddict?

>>> and not know exactly what performance characteristics mydict will
>>> have.
>> 
>> Oh... why do I need to know what the performance characteristic of
>> mydict is? Unless I know what I'm doing.
> 
> http://www.joelonsoftware.com/articles/fog000319.html

Sometimes it is good to have control of everything. Sometimes (most of 
the time) I know I can dump some of the details to think on more 
important matters. To know which parts need more thinking by doing 
profiling.

> Because when you do this:
> 
> mydict[key] = 1
> 
> it's important whether each dict lookup is O(1), O(log N) or O(N). For a
> dict with one million items, that means that an implementation based on
> a binary tree does O(20) times more processing than a dict, and an
> implementation based on linear searching does O(100) times more
> processing.

Well, I don't need to know how the dict works if I'm only using it to 
store twenty items right? (I do know how python's dict/set/list/etc is 
implemented, but unless that particula

using paramiko problem? please help me

2008-10-26 Thread sa6113

I want to connect to a Windows machine in my network , using ssh, I use
paramiko but I have problem in authentication, would you please help me?

1- I have installed freeSSHD in server machine? Is it necessery ? or may I
have to install another program?

2- I have entered server's Ip insted of hostname.Is it correct?

3- I have creat a user in server machine with a password to connect. Am I
right?

4- I use this code in clinet computer? May I need another code for server
computer?
hostname = "192.168.1.4" 
username = "test" 
port = 22 
password = '123456' 

# now connect 
try: 
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
sock.connect_ex((hostname, port)) 
except Exception, e: 
print 'Connect failed: ' + str(e) 
traceback.print_exc() 
sys.exit(1) 

t = paramiko.Transport(sock) 
event = threading.Event() 
t.start_client(event) 
print "started client" 
event.wait(15) 

if not t.is_active(): 
print 'SSH negotiation failed.' 
sys.exit(1) 
else: 
print "SSH negotiation sucessful" 

print "doing authentication" 
t.auth_password(username, password, event) 


event.clear() 
event.wait(20) 

the result is : 
started client 
ssh negotiation sucessful 
authentication failed

what should I do?
please help me , I am new in paramiko.
-- 
View this message in context: 
http://www.nabble.com/using-paramiko-problem--please-help-me-tp20172937p20172937.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Ordering python sets

2008-10-26 Thread Lie Ryan
On Sat, 25 Oct 2008 21:50:36 -0400, Terry Reedy wrote:

> Lie Ryan wrote:
>> On Sat, 25 Oct 2008 18:20:46 -0400, Terry Reedy wrote:
> Then why do you object to current
>   mylist = linkedlist(data)
> and request the harder to write and implement
>   mylist = list(data, implementation = 'linkedlist')

I don't wholly object it. I think it's fine but can be improved.

I tend to be more inclined on this side though:

mylist = list.linkedlist(data) # or listlinkedlist(data)
as syntax sugar for
mylist = list(data, implementation = 'linkedlist')

this kinds of syntax magnify the fact that linkedlist is a choice of 
implementation for list abstract type. The current syntax makes no 
indication whatsoever that linkedlist is anything related to list.

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


Type feedback tool?

2008-10-26 Thread Martin Vilcans
Hi list,

I'm wondering if there's a tool that can analyze a Python program
while it runs, and generate a database with the types of arguments and
return values for each function. In a way it is like a profiler, that
instead of measuring how often functions are called and how long time
it takes, it records the type information. So afterwards, when I'm
reading the code, I can go to the database to see what data type
parameter "foo" of function "bar" typically has. It would help a lot
with deciphering old code.

When I googled this, I learned that this is called "type feedback",
and is used (?) to give type information to a compiler to help it
generate fast code. My needs are much more humble. I just want a
faster way to understand undocumented code with bad naming.

-- 
[EMAIL PROTECTED]
http://www.librador.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter question

2008-10-26 Thread Chuckk Hubbard
Hello.
How about this?  I changed the if statements so the coordinates are
always updated, but only changed if within the right limits, otherwise
updated to the existing value.  Now if you drag outside the limits of
one dimension, it still moves in the other dimension.  Not sure if
that's what you want.  I'm amazed that this can be so simple, I came
up with an intricate system for my app, not realizing I could bind
events to canvas items!
BTW, I've never come across csoundroutines, can you give me a synopsis
of what it's for?  I'm using the Python Csound API.  This is why I
commented out all the references to csoundroutines, I don't have it
installed at the moment.
-Chuckk

#!/usr/bin/python
from Tkinter import *
#import csoundroutines as cs


root = Tk()


global canv
xx = {}

def makeFrame(root):
  global canv
#  test = cs.csdInstrumentlist3('bay-at-night.csd')
  canv = Canvas (root, height = 200, width = 350)

#  for i in range (0, len(test.instr_number)):
  for i in range (0, 4):
#canv.create_text(10, i *10, text=str(test.instr_number[i]) +
canv.create_text(10, i *10, text=str(i) +
'...', tags=('movable'))
xx[i] = canv.tag_bind('movable', '', slide) #B1-motion
is a drag with left button down
canv.pack()


def slide (event):
  '''
  triggered when something is dragged on the canvas - move thing
under
mouse ('current') to new position
  '''
  if 0 < event.x < 200:
  newx = event.x
  else: newx = canv.coords('current')[0]
  if 0 < event.y < 100:
newy = event.y
  else: newy = canv.coords('current')[1]
  canv.coords('current', newx, newy)


makeFrame(root)
root.mainloop()


On Fri, Oct 3, 2008 at 3:44 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I saw this (close to this anyway) lieing around on the internet and
> was wanting to use it to define a start point exc but I need the
> graphics to stay within a set y coords and I am not realy sure how to
> do that.  I have no idea on how to bind a min/max y to it.  (the
> concept is inspired by the java csound blue).
>
>
> #!/usr/bin/python
> from Tkinter import *
> import csoundroutines as cs
>
>
> root = Tk()
>
>
> global canv
> xx = {}
>
> def makeFrame(root):
>   global canv
>   test = cs.csdInstrumentlist3('bay-at-night.csd')
>   canv = Canvas (root, height = 200, width = 350)
>
>   for i in range (0, len(test.instr_number)):
> canv.create_text(10, i *10, text=str(test.instr_number[i]) +
> '...', tags=('movable'))
> xx[i] = canv.tag_bind('movable', '', slide) #B1-motion
> is a drag with left button down
> canv.pack()
>
>
> def slide (event):
>   '''
>   triggered when something is dragged on the canvas - move thing
> under
> mouse ('current') to new position
>   '''
>   newx = event.x
>   if event.y < 10 and event.y > 0:
> newy = event.y
> canv.coords('current', newx, newy)
>
>
> makeFrame(root)
> root.mainloop()
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.badmuthahubbard.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Global dictionary or class variables

2008-10-26 Thread Arnaud Delobelle
On Oct 24, 8:44 pm, Mr.SpOOn <[EMAIL PROTECTED]> wrote:
> Hi,
> in an application I have to use some variables with fixed valuse.
>
> For example, I'm working with musical notes, so I have a global
> dictionary like this:
>
> natural_notes = {'C': 0, 'D': 2, 'E': 4 }
>
> This actually works fine. I was just thinking if it wasn't better to
> use class variables.
>
> Since I have a class Note, I could write:
>
> class Note:
>     C = 0
>     D = 2
>     ...
>
> Which style maybe better? Are both bad practices?

You can also put them in a module:

notes.py


C = 0
D = 2


Then you can:

import notes
print notes.F - notes.C

or

from notes import *

print F - C

If your application consists of several files this may be a good idea.

--
Arnaud

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


Re: Improving interpreter startup speed

2008-10-26 Thread Pedro Borges
The scripts i need to run but be executed with no apparent delay  
specially when the text transforms are simple.



On Oct 26, 2008, at 11:13 AM, James Mills wrote:

On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist  
<[EMAIL PROTECTED]> wrote:
How are you getting those numbers? 330 μs is still pretty fast,  
isn't

it? :) Most disks have a seek time of 10-20 ms so it seem implausible
to me that Ruby would be able to cold start in 47 ms.


$ time python -c "pass"

real0m0.051s
user0m0.036s
sys 0m0.008s

$ time python3.0 -c "pass"

real0m0.063s
user0m0.048s
sys 0m0.004s

And yes I agree. the CPython interpreter startup times is
a stupid thing to be worrying about, especially since that
is never the bottleneck.

Python loads plenty fast enough!

--JamesMills

--
--
-- "Problems are solved by method"


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


Pydev 1.3.23 Released

2008-10-26 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.23 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Code-analysis: Fixed condition that could make code-analysis get
into a halt depending on the code structure
* Remote Debugger: Can properly debug multiple processes concurrently
* Remote Debugger: Makes the proper setup of breakpoints when
pydevd.settrace is called with suspend=False


Release Highlights in Pydev:
--

* Can cancel scanning of files (Radim Kubacki)
* Detection of symlink cycles inside of the pythonpath structure
(could enter in a loop) (Radim Kubacki)
* Removed log message if log is not enabled
* .pyc remover not giving error anymore
* Fixed code-completion bug when importing token with the same name of
module where it's declared (datetime.datetime)
* Assign with tuple not being correctly handled in the type-inference engine
* Nature no longer initialized by shutdown
* Code-completion works when inner method is declared without self
* __all__: when imported no longer filters out the builtins from the
current module on a wild import
* Fixed problem in update site and Eclipse 3.4 (after installed could
prevent other plugins from being installed -- compatibility problem on
eclipse 3.4 and old versions of Pydev)



What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

Aptana
http://aptana.com/python

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Proxy authentication in common libraries

2008-10-26 Thread Sahasranaman
Hi

I am behind a proxy server that needs proxy authentication. There are
a lot of libraries that  come without proxy support. The function
below, which is part of the python-twitter library does HTTP
Authentication, and I can't figure out how to do this with a
ProxyBasicAuthHandler object. I'm pasting the function here. Can
someone tell me how this code can be rewritten to do proxy
authentication as well as http authentication?

  def _GetOpener(self, url, username=None, password=None):
if username and password:
  self._AddAuthorizationHeader(username, password)
  handler = self._urllib.HTTPBasicAuthHandler()
  (scheme, netloc, path, params, query, fragment) =
urlparse.urlparse(url)
  handler.add_password(Api._API_REALM, netloc, username, password)
  opener = self._urllib.build_opener(handler)
else:
  opener = self._urllib.build_opener()
opener.addheaders = self._request_headers.items()
return opener
--
http://mail.python.org/mailman/listinfo/python-list


[Python 2.6] print_function and unicode_literals cannot be used at the same time?

2008-10-26 Thread 周济是母老鼠
Any ideas?

Code 1:

from __future__ import print_function, unicode_literals
import sys
print(type('HELLO, WORLD!'), file=sys.stderr)

Result 1:



Code 2:

from __future__ import unicode_literals, print_function
import sys
print(type('HELLO, WORLD!'), file=sys.stderr)

Result 2:

  File "tmp.py", line 3
print(type(''), file=sys.stderr)
^
SyntaxError: invalid syntax

Code 3:

from __future__ import unicode_literals, print_function
import sys
print >> sys.stderr, type('HELLO, WORLD!')

Result 3:


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


Re: Improving interpreter startup speed

2008-10-26 Thread Paul Rubin
Pedro Borges <[EMAIL PROTECTED]> writes:
> The scripts i need to run but be executed with no apparent delay
> specially when the text transforms are simple.

Basically you should keep the interpreter running and the script in
memory in that case.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 2.6] print_function and unicode_literals cannot be used at the same time?

2008-10-26 Thread Christian Heimes

?? wrote:

Any ideas?

Code 1:

from __future__ import print_function, unicode_literals
import sys
print(type('HELLO, WORLD!'), file=sys.stderr)


You have to do each future import in a separate line:

>>> from __future__ import unicode_literals
>>> from __future__ import print_function
>>> print(type(""), file=sys.stderr)


Christian

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


Re: SendKeys-0.3.win32-py2.1.exe

2008-10-26 Thread Thorsten Kampe
* Jesse (Sat, 25 Oct 2008 14:33:52 -0700 (PDT))
> cant seem to install this, using python 2.6, any known errors that
> wont let me select the python installation to use, just opens a blank
> dialog and wont let me continue..do i need to downgrade python??

Well, you could. But honestly, this is more like an IQ test. Reflect 
about what you have done, reflect about the file name you are trying to 
install and then finally go to SendKeys' web site and see if you find 
enlightenment.

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


Error when creating class

2008-10-26 Thread flaviostz
Hi,

I wrote this small program:

class Simples:


def minha_func (valor1, valor2):
return valor1 - valor2


mf = Simples()

x = mf.minha_func(2, 3)

print x


But when I try execute it, python interpreter gives me this error:

>>> Traceback (most recent call last):
  File "/tmp/py91849hI", line 11, in 
x = mf.minha_func(2, 3)
TypeError: minha_func() takes exactly 2 arguments (3 given)


Please, help me with this issue.

Thanks,

Flávio
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error when creating class

2008-10-26 Thread Walter Cruz
You forgot the self in minha_func.


-- 
[]'
- Walter
waltercruz.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error when creating class

2008-10-26 Thread Diez B. Roggisch

flaviostz schrieb:

Hi,

I wrote this small program:

class Simples:


def minha_func (valor1, valor2):
return valor1 - valor2


mf = Simples()

x = mf.minha_func(2, 3)

print x


But when I try execute it, python interpreter gives me this error:


Traceback (most recent call last):

  File "/tmp/py91849hI", line 11, in 
x = mf.minha_func(2, 3)
TypeError: minha_func() takes exactly 2 arguments (3 given)


Please, help me with this issue.


You need to declare minha_func with an explicit self-parameter as first 
argument. That's the way python passes the instance to methods.


Consult the tutorial:

http://www.python.org/doc/2.5.2/tut/node11.html

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


Exact match with regular expression

2008-10-26 Thread Mr . SpOOn
Hi,
I'd like to use regular expressions to parse a string and accept only
valid strings. What I mean is the possibility to check if the whole
string matches the regex.

So if I have:

>>> p = re.compile('a*b*')

I can match this: 'aabbb'

>>> m = p.match('aabbb')
>>> m.group()
'aabbb'

But I'd like to get None with this: 'aabb'
Instead it matches the first part:

>>> m = p.match('aabb')
>>> m.group()
'aab'

I know this is the expected behaviour, but I'm sure it should be
possible doing what I said.
Are there other methods I don't know about in the re module?

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


XML-RPC

2008-10-26 Thread asit
what is XML-RPC System 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Exact match with regular expression

2008-10-26 Thread Rob Williscroft
Mr.SpOOn wrote in news:mailman.3069.1225039892.3487.python-
[EMAIL PROTECTED] in comp.lang.python:

> Hi,
> I'd like to use regular expressions to parse a string and accept only
> valid strings. What I mean is the possibility to check if the whole
> string matches the regex.
> 
> So if I have:
> 
 p = re.compile('a*b*')
> 
> I can match this: 'aabbb'
> 
 m = p.match('aabbb')
 m.group()
> 'aabbb'
> 
> But I'd like to get None with this: 'aabb'
> Instead it matches the first part:
> 
 m = p.match('aabb')
 m.group()
> 'aab'

Read (and bookmark) this:

http://www.python.org/doc/2.5.2/lib/re-syntax.html

You want the 3rd item down about the "$" special character.
 
>>> p = re.compile('a*b*$')
>>> m = p.match('aabb')
>>> m is None
True
>>> m = p.match('aabbb')
>>> m.group()
'aabbb'

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Exact match with regular expression

2008-10-26 Thread Lie Ryan
On Sun, 26 Oct 2008 17:51:29 +0100, Mr.SpOOn wrote:

> Hi,
> I'd like to use regular expressions to parse a string and accept only
> valid strings. What I mean is the possibility to check if the whole
> string matches the regex.
> 
> So if I have:
> 
 p = re.compile('a*b*')
> 
> I can match this: 'aabbb'
> 
 m = p.match('aabbb')
 m.group()
> 'aabbb'
> 
> But I'd like to get None with this: 'aabb' Instead it matches the
> first part:
> 
 m = p.match('aabb')
 m.group()
> 'aab'
> 
> I know this is the expected behaviour, but I'm sure it should be
> possible doing what I said.
> Are there other methods I don't know about in the re module?
> 
> Thanks.

re.compile('a*b*$')

$ matches the end of a string, or in MULTILINE mode, the end of a line 
(right before newline)

Symmetrically, ^ matches the start of a string, or in MULTILINE mode, the 
start of a line (including the start of the string)


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


Re: XML-RPC

2008-10-26 Thread Stefan Behnel
asit wrote:
> what is XML-RPC System 

Doesn't Wikipedia tell you that?

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


Re: Improving interpreter startup speed

2008-10-26 Thread BJörn Lindqvist
2008/10/26 James Mills <[EMAIL PROTECTED]>:
> On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
>> How are you getting those numbers? 330 μs is still pretty fast, isn't
>> it? :) Most disks have a seek time of 10-20 ms so it seem implausible
>> to me that Ruby would be able to cold start in 47 ms.
>
> $ time python -c "pass"
>
> real0m0.051s
> user0m0.036s
> sys 0m0.008s

Pedro was talking about cold startup time:

$ sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
$ time python -c "pass"

real0m0.627s
user0m0.016s
sys 0m0.008s

That is quite a lot and for short scripts the startup time can easily
dominate the total time.

> And yes I agree. the CPython interpreter startup times is
> a stupid thing to be worrying about, especially since that
> is never the bottleneck.

I disagree. The extra time Python takes to start makes it unsuitable
for many uses. For example, if you write a simple text editor then
Pythons longer startup time might be to much.


-- 
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list


Iowa Python User's Group Meeting Next Week!

2008-10-26 Thread Mike Driscoll
Hi,

The next Iowa Python Users Group (AKA Pyowa) is nearly upon us. We
will be meeting November 3rd, from 7-9 p.m. at the following location:

Marshall County Sheriff's Office
2369 Jessup Ave
Marshalltown, IA 50158

At this meeting, we will be having a Crash Course of sorts for all the
new programmers in our group. As anyone who has ever taken a
programming course know, it is impossible to teach everything in two
hours, so we'll be focusing on tools that will allow our group to help
themselves. In other words, we'll be focusing on source code analysis
techniques like introspection and how to use IDLE effectively. There
will also be a presentation on basic GUI design and also Django.

We will have 8 laptops there to use for any new people, pre-loaded
with Python 2.5.2 and any additional packages we need for our
presentations. You are welcome to bring your own laptop if you want.
Be sure to have 2.5 on yours as well as wxPython and the PyWin32
package (if you use Windows). We will have them on USB flash drives
should you forget.

Free pop and bottled water will be provided.  Questions and comments
can be directed to mike [at] pythonlibrary [dot] org. Updates can be
found at http://www.ipug.pythonlibrary.org


---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-26 Thread Benjamin Kaplan
On Sun, Oct 26, 2008 at 1:45 PM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:

> 2008/10/26 James Mills <[EMAIL PROTECTED]>:
> > On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist <[EMAIL PROTECTED]>
> wrote:
> >> How are you getting those numbers? 330 μs is still pretty fast, isn't
> >> it? :) Most disks have a seek time of 10-20 ms so it seem implausible
> >> to me that Ruby would be able to cold start in 47 ms.
> >
> > $ time python -c "pass"
> >
> > real0m0.051s
> > user0m0.036s
> > sys 0m0.008s
>
> Pedro was talking about cold startup time:
>
> $ sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
> $ time python -c "pass"
>
> real0m0.627s
> user0m0.016s
> sys 0m0.008s
>
> That is quite a lot and for short scripts the startup time can easily
> dominate the total time.
>
> > And yes I agree. the CPython interpreter startup times is
> > a stupid thing to be worrying about, especially since that
> > is never the bottleneck.
>
> I disagree. The extra time Python takes to start makes it unsuitable
> for many uses. For example, if you write a simple text editor then
> Pythons longer startup time might be to much.
>

You must be in a real big hurry if half a second matters that much to you.
Maybe if it took 5 seconds for the interpreter to start up, I could
understand having a problem with the start up time.
--
http://mail.python.org/mailman/listinfo/python-list


Tix/TCL Problem (I Think)

2008-10-26 Thread Steve Phillips
Hi All,
Wondering if you can tell me what I am missing.  I am trying to move some
projects over to the Linux side and Tix is giving me a fit.  Here's what I
get when I try to do something in Ubuntu relating to Tix. (Python 2.5)

>>> import Tix
>>> tk = Tix.Tk()
Traceback (most recent call last):
  File "", line 1, in 
tk = Tix.Tk()
  File "/usr/lib/python2.5/lib-tk/Tix.py", line 210, in __init__
self.tk.eval('package require Tix')
TclError: can't find package Tix
>>>


If I do this in IDLE on the Windows (Also Python 2.5), I don't encounter any
errors and I can go on my merry way.
Now I do note the TclError part but I am not familiar with TCL proper to
diagnose this error.  I went to /usr/lib/python2.5/lib-tk
and everything looks normal.  On the other hand, I can do:

import Tkinter
tk = Tkinter.Tk() on the Linux side and all is cool as well.

For most of my stuff where I use minor GUI, I always start out my code with:

import Tix
tk = Tix.Tk()
...
...

And so on.


Any Ideas?

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


Immutable object thread-safety

2008-10-26 Thread k3xji
Hi all,

This will probably be a long question/short answer, sorry, but I have
wandered net about the subject and really feel cannot find just enough
information.I want to ask my question by giving an example to
explicitly express my understanding which may be also wrong:

So, let's have a string in a module like:
st = 'IAmAstring'
My understanding: Python allocates a string object and binds the st to
that string's reference.

and let's have two threads simply doing following operations on the st
string:

Thread A:
st += 'ThreadAWasHere'

Thread B
st = 'ThreadBWasHere'

Let's think about the following situation:
Thread A reads the st value, and it is currently binded to an object
which is holding the string 'IAmAString'.
So let Thread B starts execution at that point. Note that Thread A
does not add the new string to object, it only reads st object. So,
then Thread B just writes to st, and all of a sudden st is binded to
something which is ThreadBWasHere. And then let's continue Thread A,
it already readed st's reference which is a reference to 'IamAString'.

So, finally if the execution flow is like above, we will have
'IAmAStringThreadAWasHere'. I am assuming this should not be the case.
We should have 'ThreadBWasHereThreadAWasHere' in the final string,
because we have just consumed the code in ThreadB.

Also, the other question is the operation st = 'ThreadBWasHere' is
atomic? I mean, if Python does not guarantee if an immutable object
assignment is atomic, then how can we say that the object is thread-
safe? So, if it is an atomic operation, which operators are atomic,
means only assignment'='? How about other operators like +=, or -
=..etc?

I am confused about which data structure to rely on thread-safety, or
operator in Python?

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


Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!

2008-10-26 Thread Larry Hale
Thank you, again, Michael, for all your help many months ago.

I *FINALLY* got a HowTo done up; please see 
http://wiki.python.org/moin/HowTo/FileMagic

I've also emailed Mr. Hupp to see if he'll re-post the SWIG version;
he's working on a newer binding (forget... ctypes??) and once that
one's working...  :)

But for now...


Cheers,
Larry


REF:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0
--
http://mail.python.org/mailman/listinfo/python-list


Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!

2008-10-26 Thread Larry Hale
Thank you, again, Michael, for all your help many months ago.

I *FINALLY* got a HowTo done up; please see 
http://wiki.python.org/moin/HowTo/FileMagic

I've also emailed Mr. Hupp to see if he'll re-post the SWIG version;
he's working on a newer binding (forget... ctypes??) and once that
one's working...  :)

But for now...


Cheers,
Larry


REF:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/4c60ec1599056df8/3eff4049a7bfdfc0?hl=en%E3%AD%82a54360c4d26&lnk=gst&q=python-magic#3eff4049a7bfdfc0
--
http://mail.python.org/mailman/listinfo/python-list


Web crawler on python

2008-10-26 Thread sonich
I need simple web crawler,
I found Ruya, but it's seems not currently maintained.
Does anybody know good web crawler on python or with python interface?
--
http://mail.python.org/mailman/listinfo/python-list


Immutable object thread-safety

2008-10-26 Thread k3xji
Hi all,

This will probably be a long question/short answer, sorry, but I have
wandered net about the subject and really feel cannot find just enough
information.I want to ask my question by giving an example to
explicitly express my understanding which may be also wrong:

So, let's have a string in a module like:
st = 'IAmAstring'
My understanding: Python allocates a string object and binds the st to
that string's reference.

and let's have two threads simply doing following operations on the st
string:

Thread A:
st += 'ThreadAWasHere'

Thread B
st = 'ThreadBWasHere'

Let's think about the following situation:
Thread A reads the st value, and it is currently binded to an object
which is holding the string 'IAmAString'.
So let Thread B starts execution at that point. Note that Thread A
does not add the new string to object, it only reads st object. So,
then Thread B just writes to st, and all of a sudden st is binded to
something which is ThreadBWasHere. And then let's continue Thread A,
it already readed st's reference which is a reference to 'IamAString'.

So, finally if the execution flow is like above, we will have
'IAmAStringThreadAWasHere'. I am assuming this should not be the case.
We should have 'ThreadBWasHereThreadAWasHere' in the final string,
because we have just consumed the code in ThreadB.

Also, the other question is the operation st = 'ThreadBWasHere' is
atomic? I mean, if Python does not guarantee if an immutable object
assignment is atomic, then how can we say that the object is thread-
safe? So, if it is an atomic operation, which operators are atomic,
means only assignment'='? How about other operators like +=, or -
=..etc?

I am confused about which data structure to rely on thread-safety, or
operator in Python?

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


Re: Web crawler on python

2008-10-26 Thread Mr . SpOOn
On Sun, Oct 26, 2008 at 9:54 PM, sonich <[EMAIL PROTECTED]> wrote:
> I need simple web crawler,
> I found Ruya, but it's seems not currently maintained.
> Does anybody know good web crawler on python or with python interface?

What about BeautifulSoup?

http://www.crummy.com/software/BeautifulSoup/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!

2008-10-26 Thread Carl K
Larry Hale wrote:
> Thank you, again, Michael, for all your help many months ago.
> 
> I *FINALLY* got a HowTo done up; please see 
> http://wiki.python.org/moin/HowTo/FileMagic
> 
> I've also emailed Mr. Hupp to see if he'll re-post the SWIG version;
> he's working on a newer binding (forget... ctypes??) and once that
> one's working...  :)

I need to convert pdf to png, which imagemagic convert does, I think by using
ghostscript.  a little over a year ago I tried with some imagemagic (there are
at least 2 i think) and neither seemed close to working (for pdf that is.)  any
idea if pdf conversion is working?

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


Re: Question about scope

2008-10-26 Thread Bruno Desthuilliers

Lawrence D'Oliveiro a écrit :

In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:


Why is it a class attribute instead of an instance attribute?


Singleton class.


Possibly, yes (and I believe it is the case, but...). Or the OP doesnt 
have a good enough understanding of Python's object model, in which case 
Steven's question makes sense.

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


capturing ESC, page up/down in Python

2008-10-26 Thread jordilin
Is there any way to capture the keyboard events ESC, page up (next
page), page down (previous page) in Python?. I mean, how can I capture
if user presses one of those keys in a terminal based application? I
was thinking about pygame.key.get_pressed from the pygame module, but
I don't feel really happy about importing pygame in a non related game
project.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-26 Thread Terry Reedy

Benjamin Kaplan wrote:


I disagree. The extra time Python takes to start makes it unsuitable
for many uses. For example, if you write a simple text editor then
Pythons longer startup time might be to much.


You must be in a real big hurry if half a second matters that much to 
you. Maybe if it took 5 seconds for the interpreter to start up, I could 
understand having a problem with the start up time.


The secret is to start Python at least a second before one is actually 
ready to start.


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


Re: Immutable object thread-safety

2008-10-26 Thread Laszlo Nagy



Also, the other question is the operation st = 'ThreadBWasHere' is
atomic? 
I think this is the same question. And I believe it is not atomic, 
because it is actually rebinding a name. Consider this:


a,b = b,a

This will rebind both a and b. In order to be correct, it MUST happen in 
two phases: first calculate the right side, then do the rebind to the 
names on the left side. The expression on the right side can be anything 
that executes for a long time, and can even rebind 'a' and 'b' several 
times, and will probably be paused by other threads etc. So the 
assignment above cannot be atomic.


I strongly feel that if such an assignment is not atomic for "a,b = b,a" 
then int wont be atomic for "a+=b" or eveb "a=b" or any other 
assignment. However, I can be completely wrong. :-)

I mean, if Python does not guarantee if an immutable object
assignment is atomic, then how can we say that the object is thread-
safe? 
An assigment rebinds name to an object. It is assignment to a name. 
Assigning immutable and mutable objects to names are not specially 
distinguished.

So, if it is an atomic operation, which operators are atomic,
means only assignment'='? 

I don't think that '=' operator is atomic, see above.

I am confused about which data structure to rely on thread-safety, or
operator in Python?
  
The immutable object itself will never change state, so it is thread 
safe. The problem is not with the object, but the dictionary which holds 
the name 'b' and 'a' and 'st' in your example. It is mutable, and so 
must be protected in a threaded application.


Best,

 Laszlo

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


Re: Web crawler on python

2008-10-26 Thread James Mills
On Mon, Oct 27, 2008 at 6:54 AM, sonich <[EMAIL PROTECTED]> wrote:
> I need simple web crawler,
> I found Ruya, but it's seems not currently maintained.
> Does anybody know good web crawler on python or with python interface?

Simple, but  it works. Extend it all you like.

http://hg.softcircuit.com.au/index.wsgi/projects/pymills/file/330d047ff663/examples/spider.py

$ spider.py --help
Usage: spider.py [options] 

Options:
  --version show program's version number and exit
  -h, --helpshow this help message and exit
  -q, --quiet   Enable quiet mode
  -l, --links   Get links for specified url only
  -d DEPTH, --depth=DEPTH
Maximum depth to traverse

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Immutable object thread-safety

2008-10-26 Thread Laszlo Nagy




This will rebind both a and b. In order to be correct, it MUST happen 
in two phases: first calculate the right side, then do the rebind to 
the names on the left side.
"rebind to the names" -> "rebind the names found on the left side, to 
the objects calculated from the expressions on the right side".
I strongly feel that if such an assignment is not atomic for "a,b = 
b,a" then int wont be atomic for "a+=b" or eveb "a=b" or any other 
assignment. 

"int" -> "it"
"eveb" -> "even" 
The immutable object itself will never change state, so it is thread 
safe. The problem is not with the object, but the dictionary which 
holds the name 'b' and 'a' and 'st' in your example. 
"The problem is not with the object" -> "The problem is not with THAT 
object".


Wanted to answer too quickly. :-( Sorry.

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


Re: Triple-quoted strings hath not the Python-nature

2008-10-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano
wrote:

> I disagree. Triple-quoted strings are exactly the same as other strings:
> they capture *exactly* what you put in them ...

But that conflicts with the use of whitespace for indentation rules. Other
languages are freeform, and have strings that include whitespace as
significant.

In short, if whitespace is significant outside a string, then it shouldn't
be significant inside. And vice versa.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Triple-quoted strings hath not the Python-nature

2008-10-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Robert Lehmann
wrote:

> I would feel greatly offended if I had to indent all *raw* data.

You mean raw strings?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Interface to Matlab

2008-10-26 Thread Lawrence D'Oliveiro
In message
<[EMAIL PROTECTED]>, Daniel
wrote:

> On Oct 17, 2:26 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
> central.gen.new_zealand> wrote:
>>
>> In message
>> <[EMAIL PROTECTED]>,
>> Daniel wrote:
>>
>>> Also, I think that Matlab's perferred language is Java.
>>
>> It has its own built-in language (good for some things, crappy for
>> others), though no doubt it's been making more use of Java over the
>> years.
> 
> The Matlab interpreter is written in Java:
> http://www.cs.princeton.edu/introcs/11matlab/

MATLAB started out as a FORTRAN program.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Type feedback tool?

2008-10-26 Thread Scott David Daniels

Martin Vilcans wrote:

Hi list,

I'm wondering if there's a tool that can analyze a Python program
while it runs, and generate a database with the types of arguments and
return values for each function. In a way it is like a profiler, that
instead of measuring how often functions are called and how long time
it takes, it records the type information. So afterwards, when I'm
reading the code, I can go to the database to see what data type
parameter "foo" of function "bar" typically has. It would help a lot
with deciphering old code.

When I googled this, I learned that this is called "type feedback",
and is used (?) to give type information to a compiler to help it
generate fast code. My needs are much more humble. I just want a
faster way to understand undocumented code with bad naming.


It should be pretty easy to do this as a decorator, then (perhaps
automatically) sprinkle it around your source.

def watch(function):
def wrapped(*args, **kwargs):
argv = map(type, args)
argd = dict((key, type(value)) for key, value
 in kwargs.iteritems())
try:
result = function(*args, **kwargs)
except Exception, exc:
record_exception(function, type(exc), argv, argd)
raise
else:
record_result(function, type(result), argv, argd)
return wrapped

then fill your normal code with:

   @watch
   def somefun(arg, defarg=1):
   ...
   ...


Finally record_* could write to a data structure (using bits like
function.__name__, and f.__module__, and possibly goodies from inspect).
Then you wrap your actual code start with something like:

try:
main(...)
finally:



--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Porting VB apps to Python for Window / Linux use

2008-10-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Stef
Mientki wrote:

> ... although I realize closed source is not completely possibly in Python,
> but that's no problem if the program is large/complex enough compared to
> it's market value ;-)

Software has no market value. Business models that try to assign it one are
doomed to fight an uphill battle against market forces.
--
http://mail.python.org/mailman/listinfo/python-list


IDLE stopped working

2008-10-26 Thread brianrpsgt1
Using OS X 10.5.5
Python 2.5.1

IDLE was working, then all of a sudden, the window size went off of
the screen could not resize it.  I closed IDLE and rebooted and
now IDLE will not start.  Below is the Traceback

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/Current/bin/
IDLE", line 5, in 
main()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 1402, in main
shell = flist.open_shell()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 275, in open_shell
self.pyshell = PyShell(self)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 811, in __init__
OutputWindow.__init__(self, flist, None, None)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/OutputWindow.py", line 16, in __init__
EditorWindow.__init__(self, *args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/EditorWindow.py", line 121, in __init__
height=idleConf.GetOption('main','EditorWindow','height') )
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/MultiCall.py", line 299, in __init__
apply(widget.__init__, (self,)+args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/lib-tk/Tkinter.py", line 2828, in __init__
Widget.__init__(self, master, 'text', cnf, kw)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/lib-tk/Tkinter.py", line 1930, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: bad screen distance "60gill"

Any assistance in getting this back up and running would be great

Thanks

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


Re: Urllib vs. FireFox

2008-10-26 Thread Tim Roberts
Lie Ryan <[EMAIL PROTECTED]> wrote:
>
>Cookies?

Yes, please.  I'll take two.  Chocolate chip.  With milk.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-26 Thread James Mills
On Sun, Oct 26, 2008 at 11:19 PM, Pedro Borges <[EMAIL PROTECTED]> wrote:
> The scripts i need to run but be executed with no apparent delay specially
> when the text transforms are simple.

That makes no sense whatsoever!

If you are performing data conversion with
Python, interpreter startup times are going
to be so insignificant.

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


IDLE stopped working

2008-10-26 Thread brianrpsgt1
OSX 10.5.5
Python 2.5.1

I started up IDLE today and the bottom of the window was off of the
screen.  I could not find a way to resize it.  I closed all apps and
rebooted.  After rebooting, IDLE will not start.  Below is the
Traceback:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/Current/bin/
IDLE", line 5, in 
main()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 1402, in main
shell = flist.open_shell()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 275, in open_shell
self.pyshell = PyShell(self)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/PyShell.py", line 811, in __init__
OutputWindow.__init__(self, flist, None, None)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/OutputWindow.py", line 16, in __init__
EditorWindow.__init__(self, *args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/EditorWindow.py", line 121, in __init__
height=idleConf.GetOption('main','EditorWindow','height') )
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/idlelib/MultiCall.py", line 299, in __init__
apply(widget.__init__, (self,)+args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/lib-tk/Tkinter.py", line 2828, in __init__
Widget.__init__(self, master, 'text', cnf, kw)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/lib-tk/Tkinter.py", line 1930, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: bad screen distance "60gill"

Thanks for any assistance


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


Best Unit Testing framework for Linux system administration scripting?

2008-10-26 Thread Bryan Berry
I manage a team of 5 linux sysadmins and I am trying to transition us
from lengthy, mostly unreadable shell scripts to python scripting. After
a few tutorials, I have been infected with the unit testing bug. 

Our scripts create custom versions of Fedora Core, build and deploy web
software, and test servers post-installation for proper configuration.

Friends in the python community, which unit testing frameworks do you
recommend for these purposes? I have looked at unittest and py.test so
far and prefer py.test after a cursory examination. 

Also, can anyone point to me tutorials, resources on using unit testing
in system administration?

thanks, 


-- 
Bryan W. Berry
Technology Director
OLE Nepal, http://www.olenepal.org

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


Re: capturing ESC, page up/down in Python

2008-10-26 Thread Tim Roberts
jordilin <[EMAIL PROTECTED]> wrote:
>
>Is there any way to capture the keyboard events ESC, page up (next
>page), page down (previous page) in Python?. I mean, how can I capture
>if user presses one of those keys in a terminal based application? I
>was thinking about pygame.key.get_pressed from the pygame module, but
>I don't feel really happy about importing pygame in a non related game
>project.

Are you talking about Windows or Unix?  It matters.

In Windows, if you don't need a bunch of other features, you should check
out the WConio package.  It has kbhit and getch functions that can do this.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


String manipulation using RE

2008-10-26 Thread aditya shukla
Hello folks, i have a string

eg

"(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"

now i have to convert this string to

"(((A:1,B:1):2,C:3):1,((E:1,F:1):1,D:2):2)"
So i used the logic eg. taking the substring "1):3" and converting it to
"1):2"(3-1=2) so on for all the similar substrings.But i am not able to
replace them back into the original string.
This is what my code looks like

import re

str = "(((A:1,B:1):3,C:3):4,((E:1,F:1):2,D:2):4)"

p =re.compile('\d\):\d') # compiling an re object

list1 =[]

iterator = p.finditer(str)

for match in iterator:

   x = match.group()

   l = x.split('):')

   value = int(l[1])-int(l[0])

   z= repr(value)

   rm = l[1]

   x= x.rstrip(rm)

   y = x + repr(value)

  print y

I am able to get the desired output further, any help is appreciated

Thanks

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread Andy O'Meara

Grrr... I posted a ton of lengthy replies to you and other recent
posts here using Google and none of them made it, argh. Poof. There's
nothing that fires more up more than lost work,  so I'll have to
revert short and simple answers for the time being.  Argh, damn.


On Oct 25, 1:26 am, greg <[EMAIL PROTECTED]> wrote:
> Andy O'Meara wrote:
> > I would definitely agree if there was a context (i.e. environment)
> > object passed around then perhaps we'd have the best of all worlds.
>
> Moreover, I think this is probably the *only* way that
> totally independent interpreters could be realized.
>
> Converting the whole C API to use this strategy would be
> a very big project. Also, on the face of it, it seems like
> it would render all existing C extension code obsolete,
> although it might be possible to do something clever with
> macros to create a compatibility layer.
>
> Another thing to consider is that passing all these extra
> pointers around everywhere is bound to have some effect
> on performance.


I'm with you on all counts, so no disagreement there.  On the "passing
a ptr everywhere" issue, perhaps one idea is that all objects could
have an additional field that would point back to their parent context
(ie. their interpreter).  So the only prototypes that would have to be
modified to contain the context ptr would be the ones that don't
inherently operate on objects (e.g. importing a module).


On Oct 25, 1:54 am, greg <[EMAIL PROTECTED]> wrote:
> Andy O'Meara wrote:
> > - each worker thread makes its own interpreter, pops scripts off a
> > work queue, and manages exporting (and then importing) result data to
> > other parts of the app.
>
> I hope you realize that starting up one of these interpreters
> is going to be fairly expensive. It will have to create its
> own versions of all the builtin constants and type objects,
> and import its own copy of all the modules it uses.
>

Yeah, for sure. And I'd say that's a pretty well established
convention already out there for any industry package.  The pattern
I'd expect to see is where the app starts worker threads, starts
interpreters in one or more of each, and throws jobs to different ones
(and the interpreter would persist to move on to subsequent jobs).

> One wonders if it wouldn't be cheaper just to fork the
> process. Shared memory can be used to transfer large lumps
> of data if needed.
>

As I mentioned, wen you're talking about intricate data structures, OS
opaque objects (ie. that have their own internal allocators), or huge
data sets, even a shared memory region unfortunately  can't fit the
bill.


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


v4l module

2008-10-26 Thread Carl K
I am looking for a v4l (either version 1 or 2) module.

I tried to use ctypes with ghostscript and failed.  I have a feeling trying to
use it with kernel modules would be even harder, so not exactly what "I" want to
do.

I just tried http://antonym.org/libfg and it segfaulted.  (bugs reported)

I found http://code.google.com/p/python-v4l2/ which is just a description, (and
a post about what I want to do) but no code.

I want to write unit tests to help debug v4l drivers, so I don't actually need
to display any video.   I expect lots of "crashed when I did this" reports.

what this is for:  http://chipy.org/V4l2forPyCon

Carl K

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


Re: Immutable object thread-safety

2008-10-26 Thread Alcari The Mad
k3xji wrote:
> Hi all,
> 
> This will probably be a long question/short answer, sorry, but I have
> wandered net about the subject and really feel cannot find just enough
> information.I want to ask my question by giving an example to
> explicitly express my understanding which may be also wrong:
> 
> So, let's have a string in a module like:
> st = 'IAmAstring'

When you make an assignment like that, python generates bytecode that
looks like this(straight from dis.dis):
  1   0 LOAD_CONST   0 ('IAmAstring')
  3 STORE_NAME   0 (a)

That's 1 instruction to load the constant and another one to bind it.

> My understanding: Python allocates a string object and binds the st to
> that string's reference.
> 
> and let's have two threads simply doing following operations on the st
> string:
> 
> Thread A:
> st += 'ThreadAWasHere'
> 
> Thread B
> st = 'ThreadBWasHere'
> 
> Let's think about the following situation:
> Thread A reads the st value, and it is currently binded to an object
> which is holding the string 'IAmAString'.
> So let Thread B starts execution at that point. Note that Thread A
> does not add the new string to object, it only reads st object. So,
> then Thread B just writes to st, and all of a sudden st is binded to
> something which is ThreadBWasHere. And then let's continue Thread A,
> it already readed st's reference which is a reference to 'IamAString'.
> 
> So, finally if the execution flow is like above, we will have
> 'IAmAStringThreadAWasHere'. I am assuming this should not be the case.
> We should have 'ThreadBWasHereThreadAWasHere' in the final string,
> because we have just consumed the code in ThreadB.
> 
Assuming that thread A and B contain nothing but that code, you will
either get 'ThreadBWasHereThreadAWasHere' or just 'ThreadBWasHere',
because by default the interpreter switches threads every 100 bytecode
instructions.
> Also, the other question is the operation st = 'ThreadBWasHere' is
> atomic? I mean, if Python does not guarantee if an immutable object
> assignment is atomic, then how can we say that the object is thread-
> safe? So, if it is an atomic operation, which operators are atomic,
> means only assignment'='? How about other operators like +=, or -
> =..etc?
The augmented assignment operators first load the current value of the
variable like this:
a += 'asdf'
becomes
  1   0 LOAD_NAME0 (a)
  3 LOAD_CONST   0 ('asdf')
  6 INPLACE_ADD
  7 STORE_NAME   0 (a)
> 
> I am confused about which data structure to rely on thread-safety, or
> operator in Python?
All of the builtin functions(which are implemented in C, like len()) are
atomic(but assigning their output to a value may not be).

I hope this helps,
AlcariTheMad
--
http://mail.python.org/mailman/listinfo/python-list


Re: Porting VB apps to Python for Window / Linux use

2008-10-26 Thread Ben Finney
Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:

> Software has no market value. Business models that try to assign it
> one are doomed to fight an uphill battle against market forces.

+1 QOTW.

-- 
 \   “Yesterday I told a chicken to cross the road. It said, ‘What |
  `\ for?’” —Steven Wright |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread Andy O'Meara
On Oct 24, 9:52 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> >> A c-level module, on the other hand, can sidestep/release
> >> the GIL at will, and go on it's merry way and process away.
>
> > ...Unless part of the C module execution involves the need do CPU-
> > bound work on another thread through a different python interpreter,
> > right?
>
> Wrong.


Let's take a step back and remind ourselves of the big picture.  The
goal is to have independent interpreters running in pthreads that the
app starts and controls.  Each interpreter never at any point is doing
any thread-related stuff in any way.  For example, each script job
just does meat an potatoes CPU work, using callbacks that, say,
programatically use OS APIs to edit and transform frame data.

So I think the disconnect here is that maybe you're envisioning
threads being created *in* python.  To be clear, we're talking out
making threads at the app level and making it a given for the app to
take its safety in its own hands.



>
> > As far as I can tell, it seems
> > CPython's current state can't CPU bound parallelization in the same
> > address space.
>
> That's not true.
>

Well, when you're talking about large, intricate data structures
(which include opaque OS object refs that use process-associated
allocators), even a shared memory region between the child process and
the parent can't do the job.  Otherwise, please describe in detail how
I'd get an opaque OS object (e.g. an OS ref that refers to memory-
resident video) from the child process back to the parent process.

Again, the big picture that I'm trying to plant here is that there
really is a serious need for truly independent interpreters/contexts
in a shared address space.  Consider stuff like libpng, zlib, ipgjpg,
or whatever, the use pattern is always the same: make a context
object, do your work in the context, and take it down.  For most
industry-caliber packages, the expectation and convention (unless
documented otherwise) is that the app can make as many contexts as its
wants in whatever threads it wants because the convention is that the
app is must (a) never use one context's objects in another context,
and (b) never use a context at the same time from more than one
thread.  That's all I'm really trying to look at here.


Andy




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


Re: Improving interpreter startup speed

2008-10-26 Thread James Mills
On Mon, Oct 27, 2008 at 4:12 AM, Benjamin Kaplan
<[EMAIL PROTECTED]> wrote:
> You must be in a real big hurry if half a second matters that much to you.
> Maybe if it took 5 seconds for the interpreter to start up, I could
> understand having a problem with the start up time.

+1 This thread is stupid and pointless.
Even for a so-called cold startup 0.5s is fast enough!

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Immutable object thread-safety

2008-10-26 Thread Alcari The Mad
Laszlo Nagy wrote:
> 
>> Also, the other question is the operation st = 'ThreadBWasHere' is
>> atomic? 
> I think this is the same question. And I believe it is not atomic,
> because it is actually rebinding a name. Consider this:
> 
> a,b = b,a
> 
> This will rebind both a and b. In order to be correct, it MUST happen in
> two phases: first calculate the right side, then do the rebind to the
> names on the left side. The expression on the right side can be anything
> that executes for a long time, and can even rebind 'a' and 'b' several
> times, and will probably be paused by other threads etc. So the
> assignment above cannot be atomic.

You are correct.
a,b = b,a
yields the bytecode:

  1   0 LOAD_NAME0 (b)
  3 LOAD_NAME1 (a)
  6 ROT_TWO
  7 STORE_NAME   1 (a)
 10 STORE_NAME   0 (b)

Which is most definitely not atomic.

> 
> I strongly feel that if such an assignment is not atomic for "a,b = b,a"
> then int wont be atomic for "a+=b" or eveb "a=b" or any other
> assignment. However, I can be completely wrong. :-)

'a = b' requires two bytecodes:

  1   0 LOAD_NAME0 (b)
  3 STORE_NAME   1 (a)

>> I mean, if Python does not guarantee if an immutable object
>> assignment is atomic, then how can we say that the object is thread-
>> safe? 
> An assigment rebinds name to an object. It is assignment to a name.
> Assigning immutable and mutable objects to names are not specially
> distinguished.
>> So, if it is an atomic operation, which operators are atomic,
>> means only assignment'='? 
> I don't think that '=' operator is atomic, see above.
>> I am confused about which data structure to rely on thread-safety, or
>> operator in Python?
>>   
> The immutable object itself will never change state, so it is thread
> safe. The problem is not with the object, but the dictionary which holds
> the name 'b' and 'a' and 'st' in your example. It is mutable, and so
> must be protected in a threaded application.

I would suggest reading up on using the 'with' statement and
thread.allocate_lock().

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


Re: Improving interpreter startup speed

2008-10-26 Thread James Mills
On Mon, Oct 27, 2008 at 3:45 AM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote:
> Pedro was talking about cold startup time:
>
> $ sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
> $ time python -c "pass"
>
> real0m0.627s
> user0m0.016s
> sys 0m0.008s

$ sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
$ time python -S -c "pass"

real0m0.244s
user0m0.004s
sys 0m0.008s

With -S (don't imply 'import site' on initialization)

I suspect that's to do with importing modules,
the site specific modules, etc. Disk access will
tend to chew into this "startup time". Use -S
if you're that worried about startup times (heaven
knows what affect it'll have on your app though).

--JamesMils

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread Andy O'Meara


> > And in the case of hundreds of megs of data
>
> ... and I would be surprised at someone that would embed hundreds of
> megs of data into an object such that it had to be serialized... seems
> like the proper design is to point at the data, or a subset of it, in a
> big buffer.  Then data transfers would just transfer the offset/length
> and the reference to the buffer.
>
> > and/or thousands of data structure instances,
>
> ... and this is another surprise!  You have thousands of objects (data
> structure instances) to move from one thread to another?
>

I think we miscommunicated there--I'm actually agreeing with you.  I
was trying to make the same point you were: that intricate and/or
large structures are meant to be passed around by a top-level pointer,
not using and serialization/messaging.  This is what I've been trying
to explain to others here; that IPC and shared memory unfortunately
aren't viable options, leaving app threads (rather than child
processes) as the solution.


> Of course, I know that data get large, but typical multimedia streams
> are large, binary blobs.  I was under the impression that processing
> them usually proceeds along the lines of keeping offsets into the blobs,
> and interpreting, etc.  Editing is usually done by making a copy of a
> blob, transforming it or a subset in some manner during the copy
> process, resulting in a new, possibly different-sized blob.


Your instincts are right.  I'd only add on that when you're talking
about data structures associated with an intricate video format, the
complexity and depth of the data structures is insane -- the LAST
thing you want to burn cycles on is serializing and unserializing that
stuff (so IPC is out)--again, we're already on the same page here.

I think at one point you made the comment that shared memory is a
solution to handle large data sets between a child process and the
parent.  Although this is certainty true in principle, it doesn't hold
up in practice since complex data structures often contain 3rd party
and OS API objects that have their own allocators.  For example, in
video encoding, there's TONS of objects that comprise memory-resident
video from all kinds of APIs, so the idea of having them allocated
from shared/mapped memory block isn't even possible. Again, I only
raise this to offer evidence that doing real-world work in a child
process is a deal breaker--a shared address space is just way too much
to give up.


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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-26 Thread James Mills
On Mon, Oct 27, 2008 at 12:03 PM, Andy O'Meara <[EMAIL PROTECTED]> wrote:
> I think we miscommunicated there--I'm actually agreeing with you.  I
> was trying to make the same point you were: that intricate and/or
> large structures are meant to be passed around by a top-level pointer,
> not using and serialization/messaging.  This is what I've been trying
> to explain to others here; that IPC and shared memory unfortunately
> aren't viable options, leaving app threads (rather than child
> processes) as the solution.

Andy,

Why don't you just use a temporary file
system (ram disk) to store the data that
your app is manipulating. All you need to
pass around then is a file descriptor.

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: set/dict comp in Py2.6

2008-10-26 Thread Benjamin
On Oct 25, 3:13 am, [EMAIL PROTECTED] wrote:
> I'd like to know why Python 2.6 doesn't have the syntax to create sets/
> dicts of Python 3.0, like:

Because nobody bothered to backport it.
>
> {x*x for x in xrange(10)}
> {x:x*x for x in xrange(10)}
>
> Bye,
> bearophile

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


Re: set/dict comp in Py2.6

2008-10-26 Thread Benjamin
On Oct 25, 3:13 am, [EMAIL PROTECTED] wrote:
> I'd like to know why Python 2.6 doesn't have the syntax to create sets/
> dicts of Python 3.0, like:

Because nobody bothered to backport it.
>
> {x*x for x in xrange(10)}
> {x:x*x for x in xrange(10)}
>
> Bye,
> bearophile

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


Re: Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!

2008-10-26 Thread Michael Torrie
Carl K wrote:
> I need to convert pdf to png, which imagemagic convert does, I think by using
> ghostscript.  a little over a year ago I tried with some imagemagic (there are
> at least 2 i think) and neither seemed close to working (for pdf that is.)  
> any
> idea if pdf conversion is working?

python-magic isn't about image conversion.  libmagic has nothing to do
with ImageMagick.  It's a library for identifying what type of file
something is based in it's signature (magic number).  This is the same
library that drives the unix "file" command.

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


Re: Module python-magic on/for Windows - UPDATE: WORKING & HowTo!!!

2008-10-26 Thread Carl K
Michael Torrie wrote:
> Carl K wrote:
>> I need to convert pdf to png, which imagemagic convert does, I think by using
>> ghostscript.  a little over a year ago I tried with some imagemagic (there 
>> are
>> at least 2 i think) and neither seemed close to working (for pdf that is.)  
>> any
>> idea if pdf conversion is working?
> 
> python-magic isn't about image conversion.  libmagic has nothing to do
> with ImageMagick.  It's a library for identifying what type of file
> something is based in it's signature (magic number).  This is the same
> library that drives the unix "file" command.
> 

I was wondering why the docs didn't seem very image related Someone may want
to add a note that python-magic isn't PythonMagick:

http://www.imagemagick.org/download/python/PythonMagick-0.8.tar.bz2

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


Re: Triple-quoted strings hath not the Python-nature

2008-10-26 Thread Mel
Lawrence D'Oliveiro wrote:

> In message <[EMAIL PROTECTED]>, Steven D'Aprano
> wrote:
> 
>> I disagree. Triple-quoted strings are exactly the same as other strings:
>> they capture *exactly* what you put in them ...
> 
> But that conflicts with the use of whitespace for indentation rules. Other
> languages are freeform, and have strings that include whitespace as
> significant.
> 
> In short, if whitespace is significant outside a string, then it shouldn't
> be significant inside. And vice versa.

I think the rule is that whitespace leading a statement is significant. 
Whitespace inside a statement isn't.  For example, whitespace inside a pair
of parentheses isn't significant:

Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> if True:
... print (
... 'a b d c d')
...
a b d c d
>>>


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


Re: capturing ESC, page up/down in Python

2008-10-26 Thread Terry Reedy



jordilin <[EMAIL PROTECTED]> wrote:

Is there any way to capture the keyboard events ESC, page up (next
page), page down (previous page) in Python?. I mean, how can I capture
if user presses one of those keys in a terminal based application? I
was thinking about pygame.key.get_pressed from the pygame module, but
I don't feel really happy about importing pygame in a non related game
project.


Much of Pygame is a wrapper for the SDL library.  Would you be happier 
using that part if it had been called PySDL?


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


Re: Improving interpreter startup speed

2008-10-26 Thread David Cournapeau
On Mon, Oct 27, 2008 at 10:52 AM, James Mills
<[EMAIL PROTECTED]> wrote:
> On Mon, Oct 27, 2008 at 4:12 AM, Benjamin Kaplan
> +1 This thread is stupid and pointless.
> Even for a so-called cold startup 0.5s is fast enough!

Not if the startup is the main cost for a command you need to repeat many times.

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


Re: Improving interpreter startup speed

2008-10-26 Thread James Mills
On Mon, Oct 27, 2008 at 3:15 PM, David Cournapeau <[EMAIL PROTECTED]> wrote:
> Not if the startup is the main cost for a command you need to repeat many 
> times.

Seriously if you have to spawn and kill python
processes that many times for an initial cold
startup and subsequent warm startups to be
any significance, you're doing something wrong!

--JamesMills

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Improving interpreter startup speed

2008-10-26 Thread Terry Reedy

David Cournapeau wrote:

On Mon, Oct 27, 2008 at 10:52 AM, James Mills
<[EMAIL PROTECTED]> wrote:

On Mon, Oct 27, 2008 at 4:12 AM, Benjamin Kaplan
+1 This thread is stupid and pointless.
Even for a so-called cold startup 0.5s is fast enough!


Not if the startup is the main cost for a command you need to repeat many times.


It this a theoretical problem or an actual one, that we might have other 
suggestions for?


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


Re: [Python 2.6] print_function and unicode_literals cannot be used at the same time?

2008-10-26 Thread Gabriel Genellina
En Sun, 26 Oct 2008 12:13:08 -0200, Christian Heimes <[EMAIL PROTECTED]>  
escribió:



?? wrote:

Any ideas?
 Code 1:
 from __future__ import print_function, unicode_literals
import sys
print(type('HELLO, WORLD!'), file=sys.stderr)


You have to do each future import in a separate line:

 >>> from __future__ import unicode_literals
 >>> from __future__ import print_function
 >>> print(type(""), file=sys.stderr)



That's a bug, isn't it? The language reference explicitely allows it:
http://docs.python.org/reference/simple_stmts.html#future-statements

--
Gabriel Genellina

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