Re: making my extensions work together

2011-08-03 Thread Stefan Behnel
Mathew, 04.08.2011 03:19: This isn't exactly a Python question but maybe someone here has run into this. I have 2 extensions With "extensions", I assume you mean extension modules for the CPython runtime that are written in C? It would help if you were more specific in your problem descripti

Re: Inconsistencies with tab/space indentation between Cygwin/Win32?

2011-08-03 Thread Thorsten Kampe
* Christian Gelinek (Thu, 4 Aug 2011 13:55:37 +0930) > Any ideas on how to get the thing to run under (real) Windows, > hopefully without having to edit existing sources of people who left > our company ages ago? python -t "Issue a warning when a source file mixes tabs and spaces for indentation i

Re: python module to determine if a machine is idle/free

2011-08-03 Thread Chris Rebert
On Wed, Aug 3, 2011 at 9:06 PM, Danny Wong (dannwong) wrote: > Hi all, > >     I have 5 server machines that are using to process > information. I would like to write a quick server python script that > determines which of the machines are not in use. Any recommendations on > which pyt

Inconsistencies with tab/space indentation between Cygwin/Win32?

2011-08-03 Thread Christian Gelinek
Hi all, I have a problem running some python program using version 2.6.4 (or version 2.7.2, I tried both) from the Win7 command line - it never finishes due to an infinite loop. The thing is, when I run the same program through Cygwin which uses Python version 2.6.5, it exits the loop at some poin

HID Device Drivers for OS X

2011-08-03 Thread chrisallick
Hi, I spent almost all day trying to figure out how to capture a click from this button: http://www.dreamcheeky.com/big-red-button I tried libusb, PyUSB, HIDAPI and probably a couple other things. No luck. My understanding is that libusb won't allow me to get at the interface and the example

python module to determine if a machine is idle/free

2011-08-03 Thread Danny Wong (dannwong)
Hi all, I have 5 server machines that are using to process information. I would like to write a quick server python script that determines which of the machines are not in use. Any recommendations on which python module I should use to detect if a machine is not performing idle (ex

Re: parsing in python

2011-08-03 Thread John L. Stephens
Depending on what you want to do, you might try looking at the pyparsing module. I have used it to successfully parse sentences looking for keywords and structures. On 8/3/2011 9:26 AM, Jayron Soares wrote: Hi folks, I've created a simple method to grab files texts from directory by words r

Re: Notifications when process is killed

2011-08-03 Thread chrisallick
On Aug 1, 5:56 am, Andrea Di Mario wrote: > Hi, i've created a twisted server application and i want that the > server send me a message when someone stops or kills the process. > I want to override reactor.stop(), but do this way send me message > when the process is stopped by a system kill? > C

Re: Notifications when process is killed

2011-08-03 Thread chrisallick
On Aug 1, 11:39 am, Andrea Di Mario wrote: > Thanks Thomas, it is what i'm looking for. > > Regards > > -- > Andrea Di Mario Catch a Kill: def signal_handler(signal, frame): print "Received exit command." #server.running = False sys.exit() signal.signal(signal.SIGINT, si

Re: making my extensions work together

2011-08-03 Thread John Gordon
In "Mathew" writes: > This isn't exactly a Python question but maybe someone here has run into > this. > I have 2 extensions and they both access a function in a (static) library. > The function maintains state information using a static variable. I'm not sure what you mean by "extension", b

Community Involvement

2011-08-03 Thread Steve Holden
[Ccs appreciated] After some three years labor I (@holdenweb) at last find myself approaching the completion of the Python Certificate Series with O'Reilly School of Technology (@OReillySchool). At OSCON last week the team fell to talking about the final assignment (although the Certificate is

Re: range() vs xrange() Python2|3 issues for performance

2011-08-03 Thread Steven D'Aprano
harrismh777 wrote: > def perf(n): > sum = 0 > for i in range(1, n): > if n % i == 0: > sum += i > return sum == n A more effective way to speed that up is with a better algorithm: def isperfect(n): if n < 2: return False total = 1 for i in range(

making my extensions work together

2011-08-03 Thread Mathew
This isn't exactly a Python question but maybe someone here has run into this. I have 2 extensions and they both access a function in a (static) library. The function maintains state information using a static variable. This doesn't work. When one of my extensions changes the variable value, th

Re: Inconsistent SMTP/Gmail connection drop

2011-08-03 Thread Dan Stromberg
Some things to consider: 1) You might see if there's something about the size of the message - is it bigger after collecting data all night? Is google disconnecting after a maximum amount of data is transferred? 2) You might try sending a tiny test message at the beginning, just to yourself, and

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 2:54 PM, Thomas Jollans wrote: > > On 03/08/11 23:25, Dan Stromberg wrote: > > > Interesting. Of course, it's probably readily available to you. > What > > > *ix are you seeing that doesn't include cpio by default? > > > > Arch Linux - the base install is quit

Re: Equality check

2011-08-03 Thread Chris Angelico
On Wed, Aug 3, 2011 at 8:15 PM, Dave Angel wrote: > If one is complex, ... The situation is complex enough without bringing complex numbers into it! OP, I recommend reading this page and then re-asking your question: http://www.catb.org/~esr/faqs/smart-questions.html ChrisA -- http://mail.pyth

Re: Inconsistent SMTP/Gmail connection drop

2011-08-03 Thread Astley Le Jasper
Not sure how I'd test or determine that. I've set smtp debug to true and the output looks all good. I suppose I could try sending an email before the report is sent, as well as the email that is sent after it. On Thu, Aug 4, 2011 at 12:17 AM, David Stanek wrote: > On Wed, Aug 3, 2011 at 5:46 PM,

Re: Early binding as an option

2011-08-03 Thread Chris Angelico
On Wed, Aug 3, 2011 at 8:51 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> Ah! I was not aware of this, and thought that locals were a dictionary >> too. Of course, it makes a lot of sense. In that case, the classic >> "grab it as a local" isn't just loading down the locals dictionary >>

Re: Inconsistent SMTP/Gmail connection drop

2011-08-03 Thread David Stanek
On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper wrote: > > Any ideas? > Is it possible that the first email is sent before the network connection has been properly established? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek www: http://dstanek.com -- http://mail.

Inconsistent SMTP/Gmail connection drop

2011-08-03 Thread Astley Le Jasper
I have a laptop that wakes up and then runs a script that collects info and sends an email with a spreadsheet (zipped and about 350KB) report to a number of people. However, every time I get the following error: File "/usr/lib/python2.7/smtplib.py", line 343, in getreply raise SMTPServerDisco

Re: Hardlink sub-directories and files

2011-08-03 Thread Thomas Jollans
On 03/08/11 23:25, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans > wrote: > > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux -

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 11:49 AM, Thomas Jollans wrote: > > > Interesting. Of course, it's probably readily available to you. What > > *ix are you seeing that doesn't include cpio by default? > > Arch Linux - the base install is quite minimal. I just discovered that I > have a program called bsd

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Terry Reedy
On 8/3/2011 11:29 AM, Phlip wrote: This is either a code snippet, if you like it, or a request for a critique, if you don't. A learning exercise but pretty useless otherwise. As others pointed out, immediately stripping off \n is a bug relative to *your* function description. Also, you yours

Re: Early binding as an option

2011-08-03 Thread Alain Ketterlin
Chris Angelico writes: [...] > The only actual data I have on the subject is the perfect-numbers > search the other day; Pike managed the same task in a fraction of the > time that Python spent on it. Pike has a single integer type that > quietly switches from small to large at 2**32, with a noti

Re: Hardlink sub-directories and files

2011-08-03 Thread Ned Deily
In article , Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: > > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: > >> > >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: > >>> > >>> On 02/08/11 11:32, loial wrote: > >>> > I am trying to hardlink all files in a directory

Re: Early binding as an option

2011-08-03 Thread Steven D'Aprano
Chris Angelico wrote: >> In CPython at least, local lookups are faster >> than globals: locals are stored in a fixed array, and the function knows >> the numeric offset of each variable. > > Ah! I was not aware of this, and thought that locals were a dictionary > too. Of course, it makes a lot of

Re: Equality check

2011-08-03 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Abhishek Jain wrote: How to check equality of two nos. in python Python doesn't have numbers, it has various numeric data types. If all you're concerned with are int types, then just use the obvous: if a == b: dosomething If one or both might

Re: Hardlink sub-directories and files

2011-08-03 Thread Thomas Jollans
On 03/08/11 18:29, Dan Stromberg wrote: > > On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans > wrote: > > Is it more portable? I don't actually have cpio installed on this > system. > > > Interesting. Of course, it's probably readily available to you. What > *i

RE: parsing function parameters

2011-08-03 Thread Lee Harr
Needed to make one change... for functions with no default args: def pdict(f):     parameter_defaults = {}     defaults = f.func_defaults     if defaults is not None:     defaultcount = len(defaults)     else:     defaultcount = 0     argcount = f.func_code.co_argcount     for i in xrang

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Phlip
> flatten() being defined as...? Python Cookbook recipe 4.6 def flatten(sequence): # CONSIDER: Reconcile with utils... for item in sequence: if isinstance(item, (list, tuple)): for subitem in flatten(list(item)): yield subitem else: y

RE: parsing function parameters

2011-08-03 Thread Lee Harr
>> I am trying to get some information about a function >> before (and without) calling it. > how about def pdict(f):     parameter_defaults = {}     defaults = f.func_defaults     defaultcount = len(defaults)     argcount = f.func_code.co_argcount     for i in xrange(f.func_code.co_argco

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Chris Rebert
On Wed, Aug 3, 2011 at 8:29 AM, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically >

Re: parsing in python

2011-08-03 Thread Jayron Soares
Hi Dan, Thank you a lot =) Cheers Jayron 2011/8/3 Dan Stromberg > > To just split lines into words, you could probably just use a regex. > > If you need to match things, like quotes or brackets or parens, pyparsing > is pretty nice. > > On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > >>

Re: parsing function parameters

2011-08-03 Thread Peter Otten
Lee Harr wrote: > I am trying to get some information about a function > before (and without) calling it. If you allow for the function arguments to be evaluated it's easy (requires Python 2.7): >>> import inspect >>> def get_args(*args, **kw): ... return args, kw ... >>> argstr = "1, 2, z=

Re: Equality check

2011-08-03 Thread Thomas Jollans
On 03/08/11 18:22, Abhishek Jain wrote: > How to check equality of two nos. in python > > http://docs.python.org/py3k/reference/expressions.html#not-in http://docs.python.org/py3k/tutorial/index.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Thomas Jollans
On 03/08/11 17:29, Phlip wrote: > Groupies: > > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want to do it as application-specifically > as possible

Re: how to sort a hash list without generating a new object?

2011-08-03 Thread Daniel Stutzbach
On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert wrote: > If you /really/ need a sorted mapping datatype, google for > "sorteddict" (which is quite distinct from OrderedDict). > Or look for a binary search tree or skip list implementation of some > sort; but these aren't commonly used in Python, so i

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 12:04 AM, Nobody wrote: > On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > > > However I do not think it is possible to hard link directories ? > > Modern Unices disallow hard links to directories, as it makes the > directory "tree" not a tree, so anything which performs

Re: Hardlink sub-directories and files

2011-08-03 Thread Dan Stromberg
On Wed, Aug 3, 2011 at 2:47 AM, Thomas Jollans wrote: > Is it more portable? I don't actually have cpio installed on this > system. Interesting. Of course, it's probably readily available to you. What *ix are you seeing that doesn't include cpio by default? > Which implementations of cp don

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Peter Otten
Phlip wrote: > Groupies: I smell a slight misperception of the audience you are addressing ;) > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want

Re: parsing function parameters

2011-08-03 Thread Stefan Behnel
Lee Harr, 03.08.2011 18:02: I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) Can't you just use runtime introspection? Take a look at the inspect module. Stef

Equality check

2011-08-03 Thread Abhishek Jain
How to check equality of two nos. in python -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing in python

2011-08-03 Thread Dan Stromberg
To just split lines into words, you could probably just use a regex. If you need to match things, like quotes or brackets or parens, pyparsing is pretty nice. On Wed, Aug 3, 2011 at 6:26 AM, Jayron Soares wrote: > Hi folks, > > I've created a simple method to grab files texts from directory by w

[job] multiple openings for CS, CE, EE, IT majors / graduates

2011-08-03 Thread AJ ONeal
I know of some job openings. Contact me off list for more details. The positions are full-time (or at least 30hrs / week) paid internships that should lead to a full-time salaried position in near future. If a *mix of any* of the bullet points below *describes you* or *someone you know*, please

parsing function parameters

2011-08-03 Thread Lee Harr
I am trying to get some information about a function before (and without) calling it. Here is what I have so far. I chose to go with a regular expression, so now I have 2 problems :o) def pdict(f, pstr):     '''given a function object and a string with the function parameters,     return a dic

Re: python distributed computing

2011-08-03 Thread Chris Angelico
On Wed, Aug 3, 2011 at 4:37 PM, julien godin wrote: > I have a HUGE(everything is relative) amount of data coming from UDP/514 > ( good old syslog), and one process alone could not handle them ( it's > full of regex, comparison and counting. all this at about 100K lines of data > per seconds a

python distributed computing

2011-08-03 Thread julien godin
Hello the list, I have a, let say 'special' , request. I would like to make a very specific type of distributed computing. Let me explain myself : I have a HUGE(everything is relative) amount of data coming from UDP/514 ( good old syslog), and one process alone could not handle them ( it's fu

Re: Hardlink sub-directories and files

2011-08-03 Thread Thomas Jollans
On 03/08/11 16:22, Grant Edwards wrote: > On 2011-08-03, Kushal Kumaran wrote: >> I suppose it is a good thing systems don't allow that now. > > It wouldn't be a problem, except there are some important places in > Unix where it is assume that filesystems are trees. Hard linking > directories ca

Re: Hardlink sub-directories and files

2011-08-03 Thread Grant Edwards
On 2011-08-03, Kushal Kumaran wrote: > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg wrote: >> >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans wrote: >>> >>> On 02/08/11 11:32, loial wrote: >>> > I am trying to hardlink all files in a directory structure using >>> > os.link. >>> > >>> > Howeve

Re: attach cString to memoryview?

2011-08-03 Thread Peter Otten
Phlip wrote: > q = cStringIO.StringIO() > p = Popen(cmd, shell=True, stdout=q, bufsize=4096) > The Subject line problem refers to how to get rid of this: > > AttributeError: 'cStringIO.StringO' object >has no attribute 'fileno' What's wrong wi

parsing in python

2011-08-03 Thread Jayron Soares
Hi folks, I've created a simple method to grab files texts from directory by words random, however I figure out that I need extract the content inside of each file, in fact I believe I have to create a parsing, nonetheless I don't know how to create a parser. Please some could share some tips to

Re: with statement and context managers

2011-08-03 Thread Thomas Rachel
Am 03.08.2011 04:15 schrieb Steven D'Aprano: > I'm not greatly experienced with context managers and the with > statement, so I would like to check my logic. > > Somebody (doesn't matter who, or where) stated that they frequently > use this idiom: > > spam = MyContextManager(*args) > for ham in m

timeout issue with modules dbus & gobject

2011-08-03 Thread Makiavelik
Hi, Here is a sample code that reproduces the issue : [code] import logging import unittest import signal import gobject import dbus from functools import wraps from dbus.mainloop.glib import DBusGMainLoop class TimeoutException(Exception): pass def timeout(timeout_time=1800): """ dec

Re: Early binding as an option

2011-08-03 Thread Stefan Behnel
Thomas Jollans, 03.08.2011 12:00: JavaScript JITs are smart enough, so a good Python JIT could be as well. Why "could"? There's PyPy if you need it. Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Tim Chase
On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote: On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote: a, b, c, d, e = [dict() for i in range(5)] I think this is good code -- if you want five different dicts, then you should call dict five times. Otherwise Python will magically call your ex

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Tim Chase
On 08/03/2011 03:25 AM, Steven D'Aprano wrote: gc wrote: Target lists using comma separation are great, but they don't work very well for this task. What I want is something like a,b,c,d,e = *dict() a, b, c, d, e = [dict() for i in range(5)] Unfortunately there is no way of doing so withou

Re: Early binding as an option

2011-08-03 Thread Chris Angelico
On Wed, Aug 3, 2011 at 11:16 AM, Steven D'Aprano wrote: > Chris Angelico wrote: >> Of course; that's a different issue altogether. No, I'm talking about >> the way a tight loop will involve repeated lookups for the same name. > > It's not really a different issue. The "standard" approach for perfo

Re: Early binding as an option

2011-08-03 Thread Steven D'Aprano
Chris Angelico wrote: > On Tue, Aug 2, 2011 at 9:23 PM, Terry Reedy wrote: >> On 8/2/2011 12:55 PM, Chris Angelico wrote: >>> >>> As I understand it, Python exclusively late-binds names; when you >>> define a function, nothing is ever pre-bound. >> >> By 'pre-bound' you presumably mean bound at d

Re: Early binding as an option

2011-08-03 Thread Thomas Jollans
On 03/08/11 00:08, Chris Angelico wrote: > With the local-variable-snapshot technique ("len = len"), can anything > be optimized, since the parser can guarantee that nothing ever > reassigns to it? If not, perhaps this would be a place where something > might be implemented: > [...] Yes, it can. T

Re: PyWart: os.path needs immediate attention!

2011-08-03 Thread Gelonida N
On 07/29/2011 11:43 PM, Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:44 AM, Corey Richardson wrote: >> Excerpts from rantingrick's message of Fri Jul 29 13:22:04 -0400 2011: >>> * New path module will ONLY support one path sep! >> >> People who use windows are used to \ being their pathsep.

Re: Hardlink sub-directories and files

2011-08-03 Thread Thomas Jollans
On 03/08/11 03:59, Dan Stromberg wrote: > > On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans > wrote: > > On 02/08/11 11:32, loial wrote: > > I am trying to hardlink all files in a directory structure using > > os.link. > > > > However I do not think it

Text to image with same results on any platform

2011-08-03 Thread Gelonida N
Hi, >From within a django application I'd like create a small image file (e.g. .png) which just contains some text. I wondered what library would be appropriate and would yield the same result independent of the OS (assuming the versions of the python libraries are the same) Images should be pix

Re: Early binding as an option

2011-08-03 Thread Stefan Behnel
Chris Angelico, 03.08.2011 00:08: So... Would this potentially produce wrong results? Would it be of any use, or would its benefit be only valued in times when the whole function needs to be redone in C? Note that, in most cases, you do not need to "redo the whole function in C". You can just

Re: Early binding as an option

2011-08-03 Thread Chris Angelico
On Wed, Aug 3, 2011 at 5:46 AM, Dennis Lee Bieber wrote: >        Horrors... That looks like some MUF code I've seen (I never had a > MUF flag on my old characters, so had no privilege to write in MUF -- > MPI was available to all, and even it had some links to MUF operations > using similar magic

Dynamically linking python into my vc project - help required

2011-08-03 Thread mrinalini
Hi, I am trying to embed python into my MFC application. I have done this before by statically linking to the python lib. But I want to change this now. The idea is to take the information from the registry for the installed version of python on the target machine. Then load python using load

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Katriel Cohn-Gordon
On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > gc wrote: > > > Target lists using comma separation are great, but they don't work > > very well for this task. What I want is something like > > > > a,b,c,d,e = *dict() > > a, b, c, d, e = [dict() for

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Gregory Ewing
gc wrote: Alternatively, is there a version of iterable multiplication that creates new objects rather than just copying the reference? You can use a list comprehension: a, b, c, d, e = [dict() for i in xrange(5)] or a generator expression: a, b, c, d, e = (dict() for i in xrange(5)) -

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Steven D'Aprano
gc wrote: > Target lists using comma separation are great, but they don't work > very well for this task. What I want is something like > > a,b,c,d,e = *dict() a, b, c, d, e = [dict() for i in range(5)] Unfortunately there is no way of doing so without counting the assignment targets. While sl

Re: python import error, what's wrong?

2011-08-03 Thread Ben Finney
Ulrich Eckhardt writes: > > the directory structure is as follows: > > > > src > > org.test > > A.py > > org.lab > > B.py > > Python uses a dot as separator between different parts of nested > structures, like e.g. the directories during import. More generally, the name of a mod

Re: python import error, what's wrong?

2011-08-03 Thread Ulrich Eckhardt
smith jack wrote: > I am using pydev plugin in eclipse, all things works just as well > but now i have confronted with a confusing problem, that is i can > import a module write by myself successfully, but when i try to run > this program, > error just shows up, what's wrong? > > the directory str

Re: Hardlink sub-directories and files

2011-08-03 Thread Nobody
On Tue, 02 Aug 2011 02:32:54 -0700, loial wrote: > However I do not think it is possible to hard link directories ? Modern Unices disallow hard links to directories, as it makes the directory "tree" not a tree, so anything which performs a recursive walk must explicitly check for cycles to avoid