Re: How to timeout when waiting for raw_input from user ?

2009-12-05 Thread Maxim Khitrov
On Sat, Dec 5, 2009 at 9:11 AM, Rune Strand wrote: > On Dec 5, 3:07 pm, Maxim Khitrov wrote: >> >> Doesn't work on Windows. >> >> - Max > > Yes, it does. I've used it a lot, also in Py2Exe apps.  Try the > documentation example yourself > >

Re: How to timeout when waiting for raw_input from user ?

2009-12-05 Thread Maxim Khitrov
On Sat, Dec 5, 2009 at 9:01 AM, Rune Strand wrote: > The easiest wasy is to use the Timer object in the threading module. > > > from threading import Timer Doesn't work on Windows. - Max -- http://mail.python.org/mailman/listinfo/python-list

Re: How to timeout when waiting for raw_input from user ?

2009-12-04 Thread Maxim Khitrov
On Fri, Dec 4, 2009 at 6:55 PM, northof40 wrote: > On Dec 5, 12:52 pm, northof40 wrote: >> Hi - I'm writing a *very* simple program for my kids. It asks the user >> to give it the answer to a maths question and says "right" or "wrong" >> >> They now want a timed version where they would only get

Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-10 Thread Maxim Khitrov
On Tue, Nov 10, 2009 at 6:32 AM, Ognjen Bezanov wrote: > Hey, > > Thanks for all the responses guys. In hindsight I probably should have > explained why on earth I'd need the physical address from an interpreted > language. > > I'm trying to see if there is any way I can make Python share data bet

Re: comparing alternatives to py2exe

2009-11-03 Thread Maxim Khitrov
On Tue, Nov 3, 2009 at 3:50 PM, iu2 wrote: > On Nov 3, 5:58 pm, Jonathan Hartley wrote: >> Hi, >> >> Recently I put together this incomplete comparison chart in an attempt >> to choose between the different alternatives to py2exe: >> >> http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxV

Re: comparing alternatives to py2exe

2009-11-03 Thread Maxim Khitrov
On Tue, Nov 3, 2009 at 10:58 AM, Jonathan Hartley wrote: > Hi, > > Recently I put together this incomplete comparison chart in an attempt > to choose between the different alternatives to py2exe: > > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html > > Columns represent m

Re: Inconsistent raw_input behavior after Ctrl-C

2009-10-20 Thread Maxim Khitrov
On Tue, Oct 20, 2009 at 6:09 PM, Maxim Khitrov wrote: > Hello all, > > I ran into a rather strange problem when interrupting a raw_input call > with Ctrl-C. This is with python 2.6.3 on Windows 7. When the call is > interrupted, one of two things happen - either a KeyboardInterrupt

Inconsistent raw_input behavior after Ctrl-C

2009-10-20 Thread Maxim Khitrov
Hello all, I ran into a rather strange problem when interrupting a raw_input call with Ctrl-C. This is with python 2.6.3 on Windows 7. When the call is interrupted, one of two things happen - either a KeyboardInterrupt exception is raised or raw_input raises EOFError, and KeyboardInterrupt is rais

Re: How can I get the line number ?

2009-07-24 Thread Maxim Khitrov
On Fri, Jul 24, 2009 at 2:51 PM, kk wrote: > Hello > > I am writing some Python code that runs in another application(has > wrapper functions). Due to lack of debugging I am printing out alot of > outputs and manual messages. I want to be able to create a function > that would let me print the curr

Re: Override a method but inherit the docstring

2009-07-16 Thread Maxim Khitrov
On Thu, Jul 16, 2009 at 9:13 PM, Jean-Paul Calderone wrote: > On Fri, 17 Jul 2009 11:01:49 +1000, Ben Finney > wrote: >> >> Howdy all, >> >> The following is a common idiom:: >> >>   class FooGonk(object): >>       def frobnicate(self): >>           """ Frobnicate this gonk. """ >>           basic

Re: no return value for threading.Condition.wait(timeout)?

2009-07-16 Thread Maxim Khitrov
On Thu, Jul 16, 2009 at 5:00 PM, Carl Banks wrote: > On Jul 16, 8:12 am, Gabriel Rossetti > wrote: >> Hello everyone, >> >> I am using threading.Condition.wait(timeout) and was surprised to see >> that there is no return value nor an exception when wait() is used w/ a >> timeout. How am I supposed

Re: Efficient bits manipulation in Python

2009-04-28 Thread Maxim Khitrov
On Tue, Apr 28, 2009 at 7:26 AM, Li Wang wrote: > Hi: > > I have a bit-code :'1011011', how can I reverse it to '1101101'? > > Another question is I know how to transform the string '110' into > integer 6, does anyone know how to transform integer 6 to a string > '110'? > > Thank you very much:)

Re: OpenGL win32 Python

2009-04-17 Thread Maxim Khitrov
On Fri, Apr 17, 2009 at 9:27 AM, gintare statkute wrote: > Hello, > > i found an example for OpenGL in windows. > It is incredibly helpful, but how to rewrite it to be useful in Python. > > How to give address of pfd in Python?: > iFormat = ChoosePixelFormat( hDC, &pfd ); > SetPixelFormat( hDC, iF

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 8:57 PM, Istvan Albert wrote: > Does it not bother you that a module that uses relative imports cannot > be run on its own anymore? $ python --help -m mod : run library module as a script (terminates option list) $ python -m some.module.name Works perfectly fine with re

Re: Unit testing frameworks

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 8:06 AM, wrote: > I am looking for a unit testing framework for Python. I am aware of > nose, but was wondering if there are any others that will > automatically find and run all tests under a directory hierarchy. Have you already looked at the unittest module? Below is t

Re: Relative Imports, why the hell is it so hard?

2009-03-24 Thread Maxim Khitrov
On Tue, Mar 24, 2009 at 5:05 AM, CinnamonDonkey wrote: > Thanx Max - your explanation sorted it :-), and a big thank you to > everyone else also! > > >From the various posts, Python considers any directory containing the > __init__.py file to be a package. The top level package is the highest > di

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 12:19 PM, CinnamonDonkey wrote: > My applogies if this is a silly question... but what makes something a > package? and does that mean that what I am trying to do is not > possible ? A package is a directory that has an __init__.py file. That file can be empty, or contain

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 11:22 AM, CinnamonDonkey wrote: > Looking at http://www.python.org/dev/peps/pep-0328/#guido-s-decision > would suggest, unless I am completely miss-understanding the example, > that '.' refers to the current level and '..' pops up a level. That is correct, but you cannot j

Re: Relative Imports, why the hell is it so hard?

2009-03-23 Thread Maxim Khitrov
On Mon, Mar 23, 2009 at 10:16 AM, CinnamonDonkey wrote: > Hi All, > > I'm fairly new to Python so I still have a lot to learn. But I'd like > to know how to correectly use relative imports. > > Please, please... please! don't go off on rants about why you think > relative imports should not be use

Re: How Get Name Of Working File

2009-03-22 Thread Maxim Khitrov
On Sun, Mar 22, 2009 at 10:58 AM, Christian Heimes wrote: > Victor Subervi schrieb: >> Hi; >> If I am writing a script that generates HTML, how do I grab the name of the >> actual file in which I am working? For example, let us say I am working in >> test.py. I can have the following code: >> >> i

Re: Script for a project inside own directory

2009-03-22 Thread Maxim Khitrov
2009/3/22 Filip Gruszczyński : > I am having a project built like this: > > project >   module1.py >   module2.py >   packages1/ >     module3.py > > etc. > > I have script that uses objects from those modules/packages. If I keep > this script inside project directory it's ok and it works. But I wo

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 5:38 PM, Matthew Woodcraft wrote: > Gary Herron writes: > I think this code is in poor taste: it's clear that it will confuse > people (which is what Maxim was asking about in the first place). Yes, I see that now, thanks :) - Max -- http://mail.python.org/mailman/listin

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 4:31 PM, Gary Herron wrote: >> Perhaps a different example would help explain what I'm trying to do: >> >> class Case1(object): >>        def __init__(self): >>                self.count = 0 >>                self.list  = [] >> >>        def inc(self): >>                sel

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 2:07 PM, Gary Herron wrote: > Maxim Khitrov wrote: >> >> Very simple question on the preferred coding style. I frequently write >> classes that have some data members initialized to immutable values. >> For example: >> >> clas

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 12:50 PM, MRAB wrote: > Maxim Khitrov wrote: >> >> Very simple question on the preferred coding style. I frequently write >> classes that have some data members initialized to immutable values. >> For example: >> >> clas

Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def __init__(self): self.some_value = 0 self.another_value = None Similar effect can be achieved by defi

Re: py2exe automatic upgrades of a program while it is running, is that possible?

2009-03-02 Thread Maxim Khitrov
On Mon, Mar 2, 2009 at 9:18 PM, William Heath wrote: > Hi All, > I am using py2exe to create a windows executable.  I am curious if anyone > knows a way to automatically upgrade a py2exe windows executable while it is > running.  Is that possible?  If so how?  If it isn't possible, what is the > n

Re: What functions, other than sleep(), can be interrupted by Ctrl-C?

2009-02-27 Thread Maxim Khitrov
On Thu, Feb 26, 2009 at 3:47 PM, Gabriel Genellina wrote: >> I'm looking for a function in the standard library or pywin32 package >> that will block until a certain condition is met or it is interrupted >> by Ctrl-C. For example, time.sleep() would have been perfect for my >> needs if thread.inte

What functions, other than sleep(), can be interrupted by Ctrl-C?

2009-02-26 Thread Maxim Khitrov
Greetings, I'm looking for a function in the standard library or pywin32 package that will block until a certain condition is met or it is interrupted by Ctrl-C. For example, time.sleep() would have been perfect for my needs if thread.interrupt_main() could interrupt the call from another thread i

Using clock() in threading on Windows

2009-02-20 Thread Maxim Khitrov
Greetings, The threading module uses time.time in _Condition and _Thread classes to implement timeouts. On Windows, time() typically has a resolution of 15.625ms. In addition, if the system clock is changed (though ntp, for example) it would reflect that change, causing the timeout to last longer

Re: Strange array.array performance

2009-02-20 Thread Maxim Khitrov
On Fri, Feb 20, 2009 at 2:42 AM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> ... Here's the function that I'll be using from now on. It gives me >> exactly the behavior I need, with an int initializer being treated as >> array size. Still not as

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 10:06 PM, David Cournapeau wrote: > On Fri, Feb 20, 2009 at 11:43 AM, Maxim Khitrov wrote: >> >> Yes, I may have a case where one thread is still sending data, while >> another tries to close the connection, or two threads trying to close >>

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 9:15 PM, John Machin wrote: > On Feb 20, 6:53 am, Maxim Khitrov wrote: >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: >> > On 2009-02-19 12:52, Maxim Khitrov wrote: >> >> >> Hello all, >> >> >> I'm curr

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 9:34 PM, David Cournapeau wrote: > On Fri, Feb 20, 2009 at 4:53 AM, Maxim Khitrov wrote: >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: >>> On 2009-02-19 12:52, Maxim Khitrov wrote: >>>> >>>> Hello all, >>&

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 7:01 PM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern >> wrote: >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other fea

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 7:01 PM, Scott David Daniels wrote: > Maxim Khitrov wrote: >> >> On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern >> wrote: >> I have, but numpy is not currently available for python 2.6, which is >> what I need for some other fea

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 2:23 PM, Gabriel Genellina wrote: > En Thu, 19 Feb 2009 16:52:54 -0200, Maxim Khitrov > escribió: > >> input = array('B', range(256) * 1) >> >> # Case 1 >> start = clock() >> data1 = array('B', input) >>

Re: Strange array.array performance

2009-02-19 Thread Maxim Khitrov
On Thu, Feb 19, 2009 at 2:35 PM, Robert Kern wrote: > On 2009-02-19 12:52, Maxim Khitrov wrote: >> >> Hello all, >> >> I'm currently writing a Python<-> MATLAB interface with ctypes and >> array.array class, using which I'll need to push large a

Strange array.array performance

2009-02-19 Thread Maxim Khitrov
Hello all, I'm currently writing a Python <-> MATLAB interface with ctypes and array.array class, using which I'll need to push large amounts of data to MATLAB. Everything is working well, but there was one strange performance-related issue that I ran into and wanted to ask about. Here's some exam