Need help on using the USB module

2011-09-18 Thread swarupchandra kamerkar
Hi,
   I am trying to use Pythoin on windows.
   I wanted to use the uSB module.

   I downloaded it and installed it.

   Still I get the following message.

 >>> import usb
Traceback (most recent call last):
  File "", line 1, in 
import usb
ImportError: DLL load failed: The specified module could not be found.

What is it that I am missing?

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


Re: Killing threads (was Re: Cancel or timeout a long running regular expression)

2011-09-18 Thread Chris Angelico
On Mon, Sep 19, 2011 at 3:41 PM, Ian Kelly  wrote:
> And what if the thread gets killed in the middle of the commit?
>

Database managers solved this problem years ago. It's not done by
preventing death until you're done - death can come from someone
brutally pulling out your power cord. There's no "except
PowerCordRemoved" to protect you from that!

There are various ways, and I'm sure one of them will work for
whatever situation is needed.

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


Re: Killing threads (was Re: Cancel or timeout a long running regular expression)

2011-09-18 Thread Adam Jorgensen
The point of the Java thread.stop() being deprecated seems to have very
little to do with undeclared exceptions being raised and a lot to do
with objects being left in a potentially damaged state.

As Ian said, it's a lot more complex than just adding try/catches. Killing a
thread in the middle of some non-atomic operation with side-effects
that propagate beyond the thread is a recipe for trouble.

In fact, while a a lot can be written about Java being a poor language the
specific article linked to about why Java deprecated thread.stop()
gives a pretty damn good explanation as to why Thread.stop() and the like
are a bad idea and what a better idea might be (Signalling that
a graceful halt should be attempted)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Killing threads (was Re: Cancel or timeout a long running regular expression)

2011-09-18 Thread Gregory Ewing

Ian Kelly wrote:


And what if the thread gets killed a second time while it's in the except block?



And what if the thread gets killed in the middle of the commit?


For these kinds of reasons, any feature for raising asynchronous
exceptions in another thread would need to come with some related
facilites:

* A way of blocking asynchronous exceptions around a critical
  section would be needed.

* Once an asynchronous exception has been raised, further
  asynchronous exceptions should be blocked until explicitly
  re-enabled.

* Asynchronous exceptions should probably be disabled initially
  in a new thread until it explicitly enables them.

Some care would still be required to write code that is robust
in the presence of asynchronous exceptions, but given these
facilities, it ought to be possible.

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


Re: Killing threads (was Re: Cancel or timeout a long running regular expression)

2011-09-18 Thread Ian Kelly
On Sat, Sep 17, 2011 at 5:38 PM, Chris Angelico  wrote:
> But if it's done as an exception, all you need is to
> catch that exception and reraise it:
>
> def threadWork(lock, a1, a2, rate):
>   try:
>       while True:
>               time.sleep(rate)
>               lock.lock()
>               t = a2.balance / 2
>               a1.balance += t
>               #say a thread.kill kills at this point
>               a2.balance -= t
>               lock.release()
>  except:
>      # roll back the transaction in some way
>      lock.release()
>      raise

And what if the thread gets killed a second time while it's in the except block?

> It'd require some care in coding, but it could be done. And if the
> lock/transaction object can be coded for it, it could even be done
> automatically:
>
> def threadWork(lock, a1, a2, rate):
>       while True:
>               time.sleep(rate)
>               transaction.begin()
>               t = a2.balance / 2
>               transaction.apply(a1.balance,t)
>               #say a thread.kill kills at this point
>               transaction.apply(a2.balance,-t)
>               transaction.commit()
>
> If the transaction object doesn't get its commit() called, it does no
> actions at all, thus eliminating all issues of locks.

And what if the thread gets killed in the middle of the commit?

Getting the code right is going to be a lot more complicated than just
adding a couple of try/excepts.

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


ANN: Pyro 4.9 released

2011-09-18 Thread Irmen de Jong
Hello,

Pyro 4.9 has just been released!

Get it from Pypi:  http://pypi.python.org/pypi/Pyro4/
Documentation: http://packages.python.org/Pyro4/index.html

Changes include:

* the documentation has finally been completed
* changed asyncresult a little in non-compatible ways.
* added more examples: gui_eventloop, deadlock, itunes
* serialized data is released a bit faster to improve garbage collection
* fixed setting several socket options such as SO_REUSEADDR.

(See the change log in the documentation for a more detailed list)


Pyro = Python Remote Objects. It is a library that enables you to build 
applications in
which objects can talk to each other over the network, with minimal programming 
effort.
You can just use normal Python method calls, with almost every possible 
parameter and
return value type, and Pyro takes care of locating the right object on the right
computer to execute the method. It is designed to be very easy to use, and to 
generally
stay out of your way. But it also provides a set of powerful features that 
enables you
to build distributed applications rapidly and effortlessly. Pyro is written in 
100% pure
Python and therefore runs on many platforms and Python versions, including 
Python 3.x.


Enjoy,

Irmen de Jong

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


Re: What is wrong with this code?

2011-09-18 Thread Steven D'Aprano
On Sun, 18 Sep 2011 21:07:22 +, superhappyfuntime wrote:

> On 09-15-2011, Ulrich Eckhardt  wrote:
> 
>> superhappyfuntime wrote:
>>>  #this is antiWYSIWYG, an easy to learn cap for begginners to LaTeX.
> 
>> It's LaTeX, not Python.
> 
>> Uli
> 
> no, it's a cap for LaTeX written in python

If it's Python, it's no Python syntax I've ever seen before.


>>> here it is: = '\begin{document}'
  File "", line 1
here it is: = '\begin{document}'
  ^
SyntaxError: invalid syntax


How about if you start off by explaining what you think "a cap for LaTeX" 
means, or provide a link to something that will explain it? This is a 
Python list, and we don't necessarily know much about LaTeX.



-- 
Steven

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


Re: What is wrong with this code?

2011-09-18 Thread superhappyfuntime
On 09-15-2011, Ulrich Eckhardt  wrote:

> superhappyfuntime wrote:
>>  #this is antiWYSIWYG, an easy to learn cap for begginners to LaTeX.

> It's LaTeX, not Python.

> Uli

no, it's a cap for LaTeX written in python


-- 
I'm trying a new usenet client for Mac, Nemo OS X, since 0 days.
You can download it at http://www.malcom-mac.com/nemo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy.array with dtype works on list of tuples not on list of lists?

2011-09-18 Thread Robert Kern

On 9/18/11 10:55 AM, Alex van der Spek wrote:

Why does this not work?


dat=[[1,2,3],[4,5,6]]
col=[('a','f4'),('b','f4'),('c','f4')]
arr=numpy.array(dat,dtype=col)


Traceback (most recent call last):
File "", line 1, in 
arr=numpy.array(dat,dtype=col)
TypeError: expected a readable buffer object




But this does:


dat=[(1,2,3),(4,5,6)]
arr=numpy.array(dat,dtype=col)
arr

array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)], dtype=[('a', '



The only difference that the object is a list of tuples now?


numpy questions are best asked on the numpy mailing list:

  http://www.scipy.org/Mailing_Lists

To answer your question, though, numpy.array() needs to figure out a lot of 
different things about the input data simultaneously, in particular its shape. 
Structured arrays (i.e. with elements that have individual fields as above) pose 
a new problem in that its individual elements are sequences themselves. In order 
to help it decide whether it should recurse down into a sequence to find its 
elements or decide that the sequence *is* an element in its own right, we 
settled on the convention that tuples are to be considered elements and that 
lists are sequences of elements.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: cause __init__ to return a different class?

2011-09-18 Thread Matthew Pounsett
On Sep 15, 1:54 am, Ryan Kelly  wrote:
> To be friendlier to others reading your code, I would consider using a
> classmethod to create an alternative constructor:

I finally got back to looking at this today.  As it turns out, un-
overriding __new__ in the child class is more complicated than I first
expected, and isn't worth the extra effort.  So, I ended up using a
constructor class method as you suggested.

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


Re: Numpy.array with dtype works on list of tuples not on list of lists?

2011-09-18 Thread Philip Semanchuk

On Sep 18, 2011, at 11:55 AM, Alex van der Spek wrote:

> Why does this not work?
> 
 dat=[[1,2,3],[4,5,6]]
 col=[('a','f4'),('b','f4'),('c','f4')]
 arr=numpy.array(dat,dtype=col)
> 
> Traceback (most recent call last):
> File "", line 1, in 
>   arr=numpy.array(dat,dtype=col)
> TypeError: expected a readable buffer object
> 
> But this does:
> 
 dat=[(1,2,3),(4,5,6)]
 arr=numpy.array(dat,dtype=col)
 arr
> array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)],  dtype=[('a', ' ' 
> The only difference that the object is a list of tuples now?

I don't know why you're seeing what you're seeing, but if you don't get answer 
here you could try asking on the numpy list. 

Good luck
Philip

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


Re: GTK2.TextView examples

2011-09-18 Thread Chris Angelico
On Mon, Sep 19, 2011 at 3:33 AM, Lance Dillon  wrote:
> Here are some examples that use GTK2.TextTag.

Interestingly, neither runs on my Windows system - I don't have GDK2
or Pango. Much appreciate the examples though - can some of them go
into the official docs?

It may well be that I'm using completely the wrong tools here. What I
want to do is write a console in Pike, more or less a telnet/MUD
client. Is it better to use TextView, or to use a GdkDisplay or
somesuch and draw the text myself?

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


Numpy.array with dtype works on list of tuples not on list of lists?

2011-09-18 Thread Alex van der Spek

Why does this not work?


dat=[[1,2,3],[4,5,6]]
col=[('a','f4'),('b','f4'),('c','f4')]
arr=numpy.array(dat,dtype=col)


Traceback (most recent call last):
 File "", line 1, in 
   arr=numpy.array(dat,dtype=col)
TypeError: expected a readable buffer object




But this does:


dat=[(1,2,3),(4,5,6)]
arr=numpy.array(dat,dtype=col)
arr
array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)], 
 dtype=[('a', '



The only difference that the object is a list of tuples now?

Thanks for clarification,
Alex van der Spek


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


Re: way to calculate 2**1000 without expanding it?

2011-09-18 Thread Arnaud Delobelle
On Sep 18, 2011 1:20 PM, "Mark Dickinson"  wrote:
>
> On Sep 16, 9:17 pm, Arnaud Delobelle  wrote:
> > Ah go on, let's make a codegolf contest out of it.
> > My entry:
> >
> > >>> sum(map(int,str(2**1000)))
>
> You could save another character by replacing "2**1000" with "2<<999"
>

Excellent!

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


Re: Cancel or timeout a long running regular expression

2011-09-18 Thread python
Thanks for everyone's comments - much appreciated!

Malcolm (the OP)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a list value from key/value pair

2011-09-18 Thread Kayode Odeyemi
On Sun, Sep 18, 2011 at 11:22 AM, Vincent Vande Vyvre <
vincent.vandevy...@swing.be> wrote:

> **
> Le 18/09/11 11:39, Kayode Odeyemi a écrit :
>
> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> Like that:
>
> # -*- coding: utf-8 -*-
>
>
> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> for key, value in items.iteritems():
> print "\n {0}".format(key)
> for val in value:
> print "\t{0}:  {1}".format(val[0], val[1])
>
> for python 2.x
>

Vincent, with:

values =  ('status', 'pending') ('timeout', '120') ('status', 'pending')
('timeout', 60)

How do I comma separate it and put each each item in a dict?

>>> for key, value in items.iteritems():
... for val in value:
... md = {}
... for q in val:
... md.update(q)
... print md
...
Traceback (most recent call last):
  File "", line 5, in 
ValueError: dictionary update sequence element #0 has length 1; 2 is
required

Thank you

-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to calculate 2**1000 without expanding it?

2011-09-18 Thread Mark Dickinson
On Sep 16, 9:17 pm, Arnaud Delobelle  wrote:
> Ah go on, let's make a codegolf contest out of it.
> My entry:
>
> >>> sum(map(int,str(2**1000)))

You could save another character by replacing "2**1000" with "2<<999"

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


Re: Getting a list value from key/value pair

2011-09-18 Thread Kayode Odeyemi
On Sun, Sep 18, 2011 at 11:25 AM, Vincent Vande Vyvre <
vincent.vandevy...@swing.be> wrote:

> **
> Le 18/09/11 11:39, Kayode Odeyemi a écrit :
>
> Hi all,
>
>
> If I have a list with key/value pair, how do I get the value of the key?
>
>
> I'm working with this code snippet:
>
> >>> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
> >>> print [items[i] for i in items.keys()]
> [[('status', 'pending'), ('timeout', '120')], [('status', 'pending'),
> ('timeout'
> , 60)]]
> >>>
>
> --
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
>
>  Sorry, for python3.x
>
> # -*- coding: utf-8 -*-
>
>
> d = {'fees':[('status','pending'), ('timeout',60)], 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> for key, value in d.items():
>
> print("\n {0}".format(key))
> for val in value:
> print("\t{0}:  {1}".format(val[0], val[1]))
>
> Very helpful! I gave your karma at
http://stackoverflow.com/questions/7460675/getting-a-list-value-from-key-value-pair

-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: create a directory structure

2011-09-18 Thread Andrea Crotti

On 09/17/2011 12:56 PM, Rafael Durán Castañeda wrote:
I think you might want to look at Fabric 
 or vagrant 






Thanks, but I don't understand how these two project would help me...
I don't need to deploy on many machines via ssh, I only need that each 
machine is able to create an initial infrastructure.


Paste-script allows me to do that, and in plus is ready to do many other 
things.
Doing it in a hand-made fashion might also work well, but I think using 
paste-script is better for future extensions/improvements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a list value from key/value pair

2011-09-18 Thread Kayode Odeyemi
On Sun, Sep 18, 2011 at 11:22 AM, Vincent Vande Vyvre <
vincent.vandevy...@swing.be> wrote:

> **
> Le 18/09/11 11:39, Kayode Odeyemi a écrit :
>
> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> Like that:
>
> # -*- coding: utf-8 -*-
>
>
> items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
>
> for key, value in items.iteritems():
> print "\n {0}".format(key)
> for val in value:
> print "\t{0}:  {1}".format(val[0], val[1])
>
> for python 2.x
>

Thank you very much :)


-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a list value from key/value pair

2011-09-18 Thread Vincent Vande Vyvre


  
  
Le 18/09/11 11:39, Kayode Odeyemi a écrit :
Hi all,

If I have a list with key/value pair, how do I get the value of
the key?
  
  I'm working with this code snippet:
  
  >>> items = {'fees':[('status','pending'),
  ('timeout',60)], 'hostel':[('status',
   'pending'), ('timeout','120')]}
  >>> print [items[i] for i in items.keys()]
  [[('status', 'pending'), ('timeout', '120')], [('status',
  'pending'), ('timeout'
  , 60)]]
  >>>
  
  -- 
  Odeyemi 'Kayode O.
  http://www.sinati.com. t: @charyorde
  

Sorry, for python3.x

# -*- coding: utf-8 -*-

d = {'fees':[('status','pending'), ('timeout',60)],
'hostel':[('status',
 'pending'), ('timeout','120')]}

for key, value in d.items():
    print("\n {0}".format(key))
    for val in value:
    print("\t{0}:  {1}".format(val[0], val[1]))

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: Getting a list value from key/value pair

2011-09-18 Thread Vincent Vande Vyvre


  
  
Le 18/09/11 11:39, Kayode Odeyemi a écrit :
items = {'fees':[('status','pending'),
  ('timeout',60)], 'hostel':[('status',
   'pending'), ('timeout','120')]}
Like that:

# -*- coding: utf-8 -*-

items = {'fees':[('status','pending'), ('timeout',60)],
'hostel':[('status',
 'pending'), ('timeout','120')]}

for key, value in items.iteritems():
    print "\n {0}".format(key)
    for val in value:
    print "\t{0}:  {1}".format(val[0], val[1])

for python 2.x

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


Re: Getting a list value from key/value pair

2011-09-18 Thread Thomas Jollans
On 18/09/11 11:39, Kayode Odeyemi wrote:
> Hi all,
> 
> If I have a list with key/value pair, how do I get the value of the key?
> 
> I'm working with this code snippet:

Python 3.2.2 (default, Sep  5 2011, 04:33:58)
[GCC 4.6.1 20110819 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> lst = [ ('key1', 'value1'), ('key2', 'value2') ]
>>> d = dict (lst)
>>> d['key1']
'value1'
>>>


> 
 items = {'fees':[('status','pending'), ('timeout',60)],
> 'hostel':[('status',
>  'pending'), ('timeout','120')]}
 print [items[i] for i in items.keys()]
> [[('status', 'pending'), ('timeout', '120')], [('status', 'pending'),
> ('timeout'
> , 60)]]

> 
> -- 
> Odeyemi 'Kayode O.
> http://www.sinati.com. t: @charyorde
> 
> 
> 

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


Python 2.7.1 64-bit Build on HP-UX11.31 ia64 with aCC - Many modules failed to build

2011-09-18 Thread Wong Wah Meng-R32813
Hello there,

I have posted this in Compiler SIG and re-post here in case anyone who knows 
about this issue is not subscribed to that group. 

I am working on python build on my server using HP-UX ANSI C Compiler. I want 
to be consistent using aCC throughout instead of gcc for my python and 
cx_Oracle build as Oracle is not supporting gcc build much. Here is my aCC 
version.

# swlist -l product | grep Compiler
  ACXX  C.06.26.EVAL   HP C/aC++ Compiler
  C-ANSI-C  C.06.26.EVAL   HP C/aC++ Compiler
  COMPLIBS  B.11.31Compiler Support Libraries

Anyhow, my issue now is when I am building my python in 64-bit, I am 
encountering many modules failed to build issue, despite the python executable 
is successfully built. There are just so many modules that failed, that I would 
conclude my build failed. :P

I followed through the instruction in README file for 64-bit build using HP-UX 
compiler (--without-gcc option is used in configure). I exported and unexported 
the environment variables before configure and make is run, respectively. I 
also removed -O option in the Makefile before running make.

I have a few questions.

1.) Why Makefile is re-generated after python executable is created? I noticed 
the removal of optimization flag in Makefile is gone/restored after python 
binary is generated.

2.) 64-bit option. It seems that this is a bad flag that linker doesn't 
recognize? Many important modules failed to build, and I believe its due to 
this error. When I manually execute ld without passing in +DD64 flag, the 
module is generated successfull.


ld -b +DD64 -lxnet 
build/temp.hp-ux-B.11.31-ia64-2.7/home/r32813/Build/2.7.1/Python-2.7.1/Modules/mathmodule.o
 
build/temp.hp-ux-B.11.31-ia64-2.7/home/r32813/Build/2.7.1/Python-2.7.1/Modules/_math.o
 -L/usr/local/lib -lm -o build/lib.hp-ux-B.11.31-ia64-2.7/math.so
ld: Unrecognized argument: +DD64
Fatal error.

Above is just showing one of the modules that failed to build.

3.) Built in modules, I see the compiler cannot find the bit of information 
required to build _tkinter module. How do I make the configure able to locate 
my tcl/tk source code or binary which I have already installed and built 
separately (and successfully)? So, where do I place the source code if I need 
to put it so that the compiler can find?

To end my question, here is the outcome of my build. For build in modules, I 
just need my _tkinter running. For shared libraries, I think  need most of 
them, those are the basic functions that my application calls.

Thanks in advance for your reply.

Python build finished, but the necessary bits to build these modules were not 
found:
_bsddb _curses_curses_panel  
_sqlite3   _ssl   _tkinter   
bsddb185   bz2dl 
gdbm   imageoplinuxaudiodev  
ossaudiodevreadline   spwd   
sunaudiodevzlib  
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.


Failed to build these modules:
_bisect_codecs_cn _codecs_hk 
_codecs_iso2022_codecs_jp _codecs_kr 
_codecs_tw _collections   _csv   
_ctypes_ctypes_test   _elementtree   
_functools _heapq _hotshot   
_io_json  _locale
_lsprof_md5   _multibytecodec
_multiprocessing   _random_sha   
_socket_struct_testcapi  
array  audioopbinascii   
cmath  cPicklecrypt  
cStringIO  datetime   dbm
fcntl  future_builtinsgrp
itertools  math   mmap   
nisoperator   parser 
pyexpatresource   select 
strop  syslog termios
time   unicodedata  


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


Getting a list value from key/value pair

2011-09-18 Thread Kayode Odeyemi
Hi all,

If I have a list with key/value pair, how do I get the value of the key?

I'm working with this code snippet:

>>> items = {'fees':[('status','pending'), ('timeout',60)],
'hostel':[('status',
 'pending'), ('timeout','120')]}
>>> print [items[i] for i in items.keys()]
[[('status', 'pending'), ('timeout', '120')], [('status', 'pending'),
('timeout'
, 60)]]
>>>

-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde
-- 
http://mail.python.org/mailman/listinfo/python-list