Re: 3.2 can't extract tarfile produced by 2.7

2012-12-27 Thread Steven W. Orr
On 12/26/2012 11:11 AM, Benjamin Kaplan wrote: On Dec 26, 2012 11:00 AM, Antoon Pardon antoon.par...@rece.vub.ac.be mailto:antoon.par...@rece.vub.ac.be wrote: I am converting some programs to python 3. These programs manipulate tarfiles. In order for the python3 programs to be really useful

Re: Computing win/loss records in Python

2012-08-25 Thread Steven W. Orr
On 8/25/2012 10:20 PM, Christopher McComas wrote: Greetings, I have code that I run via Django that grabs the results from various sports from formatted text files. The script iterates over every line in the formatted text files, finds the team in the Postgres database updates their w/l

Re: conditional running of code portion

2012-08-05 Thread Steven W. Orr
On 8/5/2012 12:43 AM, Ramchandra Apte wrote: Try pypreprocessor http://code.google.com/p/pypreprocessor/ . Better idea: You should be using the logging http://docs.python.org/library/logging.html module if you want to print debug information quickly.It uses threads and is optimized to run fast.

Re: Deciding inheritance at instantiation?

2012-08-03 Thread Steven W. Orr
On 8/3/2012 4:48 PM, Tobiah wrote: I have a bunch of classes from another library (the html helpers from web2py). There are certain methods that I'd like to add to every one of them. So I'd like to put those methods in a class, and pass the parent at the time of instantiation. Web2py has a FORM

Use of compile flags in regular expressions.

2012-07-19 Thread Steven W. Orr
I have a problem that I'm solving using a regex. (Yeah, I know, now I have two problems...) ;-) Anyways, the regex is about a couple of pages long and it works just peachy. There's just one thing I'd like to do to make it more elegant. I need to compile the regex with MULTILINE and DOTALL.

Re: How to suppress exception printing to console?

2012-05-31 Thread Steven W. Orr
On 5/31/2012 3:57 AM, Qi wrote: I have an application that embedding Python into C++. When any exception occurred in C++ code, PyErr_SetString will be called to propagate the exception to Python. The problem is, some unit tests trigger exception on intention. So it's OK to have the exceptions.

Re: can I overload operators like =, - or something like that?

2012-04-20 Thread Steven W. Orr
On 4/19/2012 3:28 PM, dmitrey wrote: hi all, can I somehow overload operators like =, - or something like that? (I'm searching for appropriate overload for logical implication if a then b) Thank you in advance, D. This tickled a memory from decades back when I worked in PL/I. They have a bool

Re: Question about collections.defaultdict

2012-03-28 Thread Steven W. Orr
On 3/26/2012 11:52 AM, Robert Kern wrote: On 3/26/12 4:33 PM, Steven W. Orr wrote: On 3/26/2012 9:44 AM, Robert Kern wrote: On 3/26/12 2:33 PM, Steven W. Orr wrote: I created a new class called CaseInsensitiveDict (by stealing from code I found on the web, thank you very much). The new class

Question about collections.defaultdict

2012-03-26 Thread Steven W. Orr
I created a new class called CaseInsensitiveDict (by stealing from code I found on the web, thank you very much). The new class inherits from dict. It makes it so that if the key has a 'lower' method, it will always access the key using lower I'd like to change the place where I previously

Re: Question about collections.defaultdict

2012-03-26 Thread Steven W. Orr
On 3/26/2012 9:44 AM, Robert Kern wrote: On 3/26/12 2:33 PM, Steven W. Orr wrote: I created a new class called CaseInsensitiveDict (by stealing from code I found on the web, thank you very much). The new class inherits from dict. It makes it so that if the key has a 'lower' method

Re: Is there a ConfigParser which keeps comments

2012-03-15 Thread Steven W. Orr
On 3/14/2012 6:07 AM, Gelonida N wrote: Hi, At the moment I use ConfigParser http://docs.python.org/library/configparser.html for one of my applications. Now I'm looking for a library, which behaves like config parser, but with one minor difference. The write() mehtod should keep existing

Questions about the use of descriptors.

2012-03-15 Thread Steven W. Orr
Question 1: I have a class A with one attribute and I define __get__ and __set__ for that class. Then I create another class B that uses it. Why does B require that the instance of A be a class variable in B and not created as an instance variable in __init__? E.g., # This works fine.

Need help with shutils.copytree

2012-02-12 Thread Steven W. Orr
I have a 'master' directory and a collection of 'slave' dirs. I want the master to collect all of the stuff in the slave dirs. The slaves all look like this, . |-- slaveX | `-- archI | | `-- distJ | | | ` -- FILE Where the different slaveX dirs may contain multiple occurrences of

Advise on using logging.getLogger needed.

2011-10-02 Thread Steven W. Orr
I hope I don't sound like I'm ranting :-( I have created a module (called xlogging) which sets up logging the way I want it. I found out that if I set up my logger without a name, then it gets applied to every logger that is referenced by every module that ever gets imported. The problem is that

Trying to learn about metaclasses

2011-07-25 Thread Steven W. Orr
I have been doing a lot of reading. I'm starting to get it. I think it's really cool as well as dangerous, but I plan on being respectful of the construct. I found a web page that I found quite readable. http://cleverdevil.org/computing/78/ So, I tried to run the example code (below), and I

Question about how to get line buffering from paramiko

2011-07-05 Thread Steven W. Orr
I'm writing a program that uses paramiko to run a lot of commands over ssh. Some of the commands take time to run and they write to stdout and stderr as a normal part of their operation so that we can see progress happening. I can't seem to get the output from the remote commands (which is

Re: English Idiom in Unix: Directory Recursively

2011-05-17 Thread Steven W. Orr
On 5/17/2011 6:26 PM, Xah Lee wrote: might be of interest. 〈English Idiom in Unix: Directory Recursively〉 http://xahlee.org/comp/idiom_directory_recursively.html The answer is from compute science 101. From any standard data structures course, you learn the algorithm for how to walk a tree.

Re: Need an example program that implements rpm -pql via import rpm

2011-03-04 Thread Steven W. Orr
On 3/3/2011 11:11 PM, geremy condra wrote: On Thu, Mar 3, 2011 at 7:24 PM, Steven W. Orrste...@syslang.net wrote: I look everywhere but I couldn't find anything. Could someone please point me to a small example program that does an import rpm, takes an rpm file as an argument and gets the list

Re: Need an example program that implements rpm -pql via import rpm

2011-03-04 Thread Steven W. Orr
On 3/4/2011 10:24 AM, Daniel Mahoney wrote: On Thu, 03 Mar 2011 22:24:24 -0500, Steven W. Orr wrote: I look everywhere but I couldn't find anything. Could someone please point me to a small example program that does an import rpm, takes an rpm file as an argument and gets the list of files

Need an example program that implements rpm -pql via import rpm

2011-03-03 Thread Steven W. Orr
I look everywhere but I couldn't find anything. Could someone please point me to a small example program that does an import rpm, takes an rpm file as an argument and gets the list of files contained in the file, the same as if I had used the commandline rpm -pql foo-1.23-4.i586.rpm Much

Re: How to capture all the environment variables from shell?

2010-08-10 Thread Steven W. Orr
On 8/2/2010 4:33 AM, Thorsten Kampe wrote: * Tim Chase (Mon, 26 Jul 2010 21:42:24 -0500) On 07/26/10 21:26, Steven W. Orr wrote: Please! Never export anything from your .bashrc unless you really know what you're doing. Almost all exports should be done in your .bash_profile Could you

Re: I need a starter ptr writing python embedded in html.

2010-08-08 Thread Steven W. Orr
On 08/07/10 23:57, quoth Miki: On Aug 7, 7:42 pm, Steven W. Orr ste...@syslang.net wrote: I'm ok in python but I haven't done too much with web pages. I have a web page that is hand written in html that has about 1000 entries in a table and I want to convert the table from entries like

I need a starter ptr writing python embedded in html.

2010-08-07 Thread Steven W. Orr
I'm ok in python but I haven't done too much with web pages. I have a web page that is hand written in html that has about 1000 entries in a table and I want to convert the table from entries like this tr td Some Date String /td td SomeTag /td td a href=localSubdir A

Re: Get name of file from directory into variable

2010-08-04 Thread Steven W. Orr
On 08/03/10 06:21, quoth loial: In a unix shell script I can do something like this to look in a directory and get the name of a file or files into a variable : MYFILE=`ls /home/mydir/JOHN*.xml` Can I do this in one line in python? Sorry, but I just can't help myself. Yeah, it's one

Re: let optionparse.Optionparser ignore unknown command line switches.

2010-08-01 Thread Steven W. Orr
On 08/01/10 07:27, quoth News123: On 08/01/2010 01:08 PM, News123 wrote: I wondered, whether there's a simple/standard way to let the Optionparser just ignore unknown command line switches. In order to illustrate, what I try to achieve: import optparse parser =

Re: How to capture all the environment variables from shell?

2010-07-27 Thread Steven W. Orr
On 07/26/10 22:42, quoth Tim Chase: On 07/26/10 21:26, Steven W. Orr wrote: Please! Never export anything from your .bashrc unless you really know what you're doing. Almost all exports should be done in your .bash_profile Could you elaborate on your reasoning why (or why-not)? I've found

Re: How to capture all the environment variables from shell?

2010-07-26 Thread Steven W. Orr
On 07/26/10 20:02, quoth Chris Rebert: On Mon, Jul 26, 2010 at 4:36 PM, Peng Yu pengyu...@gmail.com wrote: You need to export R_HOME in bash (probably in your .bashrc or .bash_profile). See http://www.ibm.com/developerworks/library/l-bash.html#N10074 Please! Never export anything from your

Re: Check if a command is valid

2010-07-14 Thread Steven W. Orr
On 07/12/10 21:29, quoth Kenny Meyer: Hello, I have to figure out if a string is callable on a Linux system. I'm actually doing this: def is_valid_command(command): retcode = 100 # initialize if command: retcode = subprocess.call(command, shell=True)

Re: refactoring a group of import statements

2010-06-28 Thread Steven W. Orr
On 06/27/10 23:20, quoth GrayShark: Thanks for the help That was what I was looking for. All the rest, the arguments were unhelpful. Question: If you can't answer the question, why are you talking? I'm American Indian. That's what I was taught. We don't talk that much. But you get an

Need instruction on how to use isinstance

2010-06-27 Thread Steven W. Orr
I need to test an argument for a few different types. I'm calling my function like this arf = MyFunc(list) What I want to do is to test for whether something is a string, tuple, list or function. It's that last one that's causing me a problem. if isinstance(arg, (str, tuple, list)): No

Re: Need instruction on how to use isinstance

2010-06-27 Thread Steven W. Orr
On 6/27/2010 10:25 PM, Stephen Hansen wrote: On 6/27/10 7:09 PM, Steven W. Orr wrote: So, my question is, what value can I use as the 2nd arg to isinstance to see if foo is a function? And while I'm on the subject, what types does isinstance not support? Does it have to be a function

[ANN] AutoRecalcDict 0.1.1 released

2010-06-21 Thread Steven W. Orr
AutoRecalcDict is a subclass of dict that allows programmers to create user defined dependencies and functions on target keys. You can find it at http://pypi.python.org/pypi/AutoRecalcDict/0.1.1 I recently was designing tests for radio frequency analysis (about which, I know nothing). All of

Re: gui doubt

2010-06-17 Thread Steven W. Orr
On 06/17/10 01:40, quoth madhuri vio: if i want to create a button which performs the transcription of dna to rna using tkinter in a gui... can u give me the method... -- madhuri :) Dear Madasahatter. You need to read the description below on how to properly implement and use the

Re: How do subprocess.Popen(ls | grep foo, shell=True) with shell=False?

2010-06-11 Thread Steven W. Orr
On 6/10/2010 11:40 AM, Chris Seberino wrote: Even if zombies are created, they will eventually get dealt with my OS w/o any user intervention needed right? Bad approach. Years ago I inherited a server that didn't do a proper cleanup pf its slaves. After a few days running, people discovered

Re: using reverse in list of tuples

2010-06-10 Thread Steven W. Orr
On 06/10/10 04:41, quoth Marco Nawijn: On Jun 10, 2:39 am, james_027 cai.hai...@gmail.com wrote: hi, I am trying to reverse the order of my list of tuples and its is returning a None to me. Is the reverse() function not allow on list containing tuples? Thanks, James As the others

Re: What does this PyChecker warning mean?

2010-06-01 Thread Steven W. Orr
On 6/1/2010 7:53 AM, Xavier Ho wrote: On 1 June 2010 21:48, Leo Breebaart l...@lspace.org mailto:l...@lspace.org wrote: When fed the following code: def Foo(): class A(object): def __init__(self): pass class B(object): def

problem with Descriptors

2010-05-31 Thread Steven W. Orr
I just discovered descriptors but what I want to do isn't working right. I hope this isn't too long. :-( Here's what I have that works: class C(object): def g(self): print dir(g):,dir(self.g) def f(self, ss): print ss = , ss cc = C() cc.ff = f.__get__(C,cc) cc.ff('Round 3') And

Looking for matlab to python converter.

2010-05-26 Thread Steven W. Orr
I found something on sourceforge called mat2py, but there's nothing there. (It seems to be just a placeholder.) I figure that if anyone would know of something useful, this would be the place to try. TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0.

Re: remove elements incrementally from a list

2010-05-19 Thread Steven W. Orr
On 5/19/2010 6:53 AM, Javier Montoya wrote: I've a list of float numbers and I would like to delete incrementally a set of elements in a given range of indexes, sth. like: for j in range(beginIndex, endIndex+1): print (remove [%d] = val: %g % (j, myList[j])) del myList[j] However,

wxPython scrolling question.

2008-04-09 Thread Steven W. Orr
I just discovered Accelerator entries so my wx app is now able to exit by typing Ctrl-Q. Can someone please tell me what to use to cause a pane to scroll up and down using the middle mouse scroll roller thingy? I looked and found wxCURSOR_MIDDLE_BUTTON but I suspect that's only good for

Re: __init__.py file

2008-04-08 Thread Steven W. Orr
On Tuesday, Apr 8th 2008 at 16:51 -, quoth cesco: =Hi, = =I need to instantiate an object (my_object) whose methods I have to =use in two files (file1.py and file2.py) which are in the same =directory. Is it possible to instantiate such object in the =__init__.py file and then directly use it

Looking for indent advice howto in emacs python-mode

2008-03-31 Thread Steven W. Orr
Here's what I want to do: if ( ( v == 1 ) or ( v == 2 ) or ( v == 3 ) ): pass but emacs (left to its own devices, does this. if ( ( v == 1 ) or ( v == 2 ) or ( v == 3 ) ): pass It works great for me in C-mode. Does anyone know how to jimmie up python-mode so it

Question on importing wxPython

2008-01-28 Thread Steven W. Orr
python-2.3.5 wx-2.6 I just bought the wxPython In Action book and I see that all the examples say to import wx All of our pre-existing code was horribly doing a from wxPython import * I changed all the code so that it was doing an import wx and found that everything was broken. In particular,

class closure question

2008-01-17 Thread Steven W. Orr
I want to indirectly change the value of a variable. #! /usr/bin/python foo = [44] bar = foo bar[0] = 55 print 'bar = ', bar print 'foo = ', foo This works fine. bar = [55] foo = [55] But I want to do the same with a class value. #! /usr/bin/python S = None dd = { 'class': [S] } class

Re: Another dumb scope question for a closure.

2008-01-10 Thread Steven W. Orr
On Wednesday, Jan 9th 2008 at 14:01 -, quoth Fredrik Lundh: =Steven W. Orr wrote: = = So sorry because I know I'm doing something wrong. = = 574 cat c2.py = #! /usr/local/bin/python2.4 = = def inc(jj): = def dummy(): = jj = jj + 1 = return jj = return dummy

Another dumb scope question for a closure.

2008-01-09 Thread Steven W. Orr
So sorry because I know I'm doing something wrong. 574 cat c2.py #! /usr/local/bin/python2.4 def inc(jj): def dummy(): jj = jj + 1 return jj return dummy h = inc(33) print 'h() = ', h() 575 c2.py h() = Traceback (most recent call last): File ./c2.py, line 10, in

Questions about subclassing an int

2008-01-04 Thread Steven W. Orr
class S(int): def __init__(self, value): self.value = value def addStr(self, str): self.doc = str s = S(44) s.addStr('Hello') print 's = ', s print 's.doc = ', s.doc class T(int): def __init__(self, value, str): self.value = value self.doc = str t

Re: Assertion for python scripts

2007-11-23 Thread Steven W. Orr
On Friday, Nov 2nd 2007 at 14:14 -, quoth matthias: =Howdy ! = =I started using the assert() stmt and found it quite useful :-) I =have only one problem: I don't =know how to turn them off again. = =I know that -O turns off assertions in general. However, how do I =pass thus parameter to

Version specific or not?

2007-10-10 Thread Steven W. Orr
We have an app and I'm trying to decide where the app should be installed. The question is whether it should be site-specific or not, as in /usr/lib/python2.3/site-packages or /usr/lib/site-python The latter would solve a lot of problems for me. In the case of emacs, most stuff seems to go

Question about quoting style.

2007-10-01 Thread Steven W. Orr
Python has a number of quoting 'options' to help with times when one way may be more convenient than another. In the world of shell scripting, I use a technique that I call minimal quoting. It works like this: foo=bar # No quotes needed echo $foo # Also none needed

Re: An Editor that Skips to the End of a Def

2007-09-21 Thread Steven W. Orr
On Thursday, Sep 20th 2007 at 18:14 +0100, quoth Paul Rudin: =W. Watson [EMAIL PROTECTED] writes: = = Thanks, but no thanks. The learning curve is way too steep. = =Up to you but, these days emacs comes with all sorts of =pointing-clicky-menu-y type things - you don't really have to learn

Re: 2 daemons write to a single file /w python file IO

2007-09-14 Thread Steven W. Orr
On Tuesday, Sep 11th 2007 at 21:17 -0700, quoth Andrey: =i have a newbie question about the file() function. =I have 2 daemons running on my linux box. = =1 will record the IDs to a file - logs.txt =other 1 will open this file, read the IDs, and then Clean up the =file -logs.txt = =Since these

Re: Python syntax wart

2007-09-10 Thread Steven W. Orr
On Monday, Sep 10th 2007 at 08:34 -, quoth Marc 'BlackJack' Rintsch: =On Mon, 10 Sep 2007 20:19:08 +1200, Lawrence D'Oliveiro wrote: = = In message [EMAIL PROTECTED], Marc 'BlackJack' Rintsch = wrote: = = I see a tree structure here ... = = Good, you're improving. = =Thanks. = = ... but

Re: Need a better understanding on how MRO works?

2007-08-26 Thread Steven W. Orr
On Saturday, Aug 25th 2007 at 22:14 -0700, quoth Alex Martelli: =Steven W. Orr [EMAIL PROTECTED] wrote: = * Also, I'd like to understand what the difference is between = nclass = new.classobj(name,(D1,),globals()) = vs. = def classfactory(): = class somename(object

Need a better understanding on how MRO works?

2007-08-25 Thread Steven W. Orr
Given the following code: (I hope it's as simple as possible) :-) #! /usr/bin/python import new class BASE: def __init__( self ): print 'Hello from BASE init' def m1( self ): print 'M1 Base: Self = ', self def m1replace( self ): print 'm1replace:Self = ', self

Re: Need a better understanding on how MRO works?

2007-08-25 Thread Steven W. Orr
On Saturday, Aug 25th 2007 at 17:19 -0700, quoth Alex Martelli: =Steven W. Orr [EMAIL PROTECTED] wrote: = ... = name = 'C1' = nclass = new.classobj(name,(D1,),globals()) = globals()[name] = nclass = =Here, you're creating a VERY anomalous class C1 whose __dict__ is =globals

How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
In the program below, I want this instance to end up calling repmeth whenever inst.m1 is called. As it is now, I get this error: Hello from init inst = __main__.CC instance at 0x402105ec Traceback (most recent call last): File ./foo9.py, line 17, in ? inst.m1() TypeError: repmeth()

Re: How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
On Friday, Aug 24th 2007 at 09:12 -0700, quoth [EMAIL PROTECTED]: =On Aug 24, 11:02 am, Steven W. Orr [EMAIL PROTECTED] wrote: = In the program below, I want this instance to end up calling repmeth = whenever inst.m1 is called. As it is now, I get this error: = = Hello from init = inst

Re: How to replace a method in an instance.

2007-08-24 Thread Steven W. Orr
On Friday, Aug 24th 2007 at 12:26 -0400, quoth Steven W. Orr: =On Friday, Aug 24th 2007 at 09:12 -0700, quoth [EMAIL PROTECTED]: = ==On Aug 24, 11:02 am, Steven W. Orr [EMAIL PROTECTED] wrote: == In the program below, I want this instance to end up calling repmeth == whenever inst.m1 is called

Problem with dynamic creation of classes.

2007-08-23 Thread Steven W. Orr
I have a base class B and a derived class D which inherits from B. I also have a D2 class which inherits from D. D is used as a base class for most of my generated classes. I have a special class which inherits from D2 because I need to override a couple of its methods. Anything based on D2

Redo: Problem with dynamic creation of classes.

2007-08-23 Thread Steven W. Orr
Sorry, I had a small description problem. It's corrected below. I have a base class B and a derived class D which inherits from B. I also have a D2 class which inherits from D. D is used as a base class for most of my generated classes. I have a special class which inherits from D2 because I need

Problems with dynamic function creation.

2007-08-22 Thread Steven W. Orr
I have some functions I need to create at runtime. The way I'm creating them is by calling a function which returns the string representation. Then I exec the string. Here's the code I use to gen the strings: mkfactfns.py --- import new def mkfactfns( cname ): def auxgen( name,

Redo: How to create a function dynamically.

2007-08-22 Thread Steven W. Orr
I have this which works: #! /usr/bin/python strfunc = def foo( a ): print 'a = ', a exec strfunc globals()['foo'] = foo foo( 'Hello' ) and this which does not: #! /usr/bin/python import new strfunc = def foo( a ): print 'a = ', a co = compile ( strfunc, '', 'exec' ) exec co nfunc

Need to generate some functions.

2007-08-17 Thread Steven W. Orr
Given a list of names ll = (n1, n2, n3, n4) I want to create a pair of functions based off of each name. An example of what I want to happen would look like this: def mkn1dict(address): return {'Address': address, 'Control': SOME_CONST} def mkn1Classobj(address): return Classobj(

Re: Retry: Question about FutureWarning

2007-08-15 Thread Steven W. Orr
is. ;-) On Tuesday, Aug 14th 2007 at 18:49 -0700, quoth Erik Max Francis: =Steven W. Orr wrote: = = M1.py:268: FutureWarning: hex/oct constants sys.maxint will = return positive values in Python 2.4 and up =StartTime = safe_dict_get ( dic, 'starttime', 0x ) = ... = import warnings

Question about FutureWarning

2007-08-14 Thread Steven W. Orr
I have module M1 which has the following line in it: StartTime = safe_dict_get ( dic, 'starttime', 0x ) It gets imported by modules M2 and M3. And finally, M4 imports both M2 and M3. M4 |\M3 | |\M1 |\M2 | |\M1 I'm building a .deb file which means I have to compile the

Retry: Question about FutureWarning

2007-08-14 Thread Steven W. Orr
I'm trying again, since no response indicates that I'm not providing enough info. I have module M1 which has the following line in it: StartTime = safe_dict_get ( dic, 'starttime', 0x ) It gets imported by modules M2 and M3. And finally, M4 imports both M2 and M3. So the idea is

Another question about variable args.

2007-08-07 Thread Steven W. Orr
I have a structure I need to pack. I call struct.pack about a dozen times and each call takes about 53 arguments. I create a sequence of the arguments: a1 = 1 a2 = 2 a3 = 3 etc... a54 = 88 myseq = (a1, a2, a3, a4 etc... a53) Also I made def mpack ( fmt, *ss ): print type(ss) for ii in

Question about how to use cog as a preprocessor :-(

2007-07-18 Thread Steven W. Orr
I have the following module: #! /usr/bin/python COG_DEBUG=1 def wrapper( dd ): if dd == 1: def dfunc( *args ): print print , for ii in args: print repr(ii) print compd dfunc return dfunc else: def nfunc(

Looking to embed python into html like mason

2007-06-21 Thread Steven W. Orr
Does something like that exist? TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What

Re: Indenting in Emacs

2007-06-21 Thread Steven W. Orr
On Thursday, Jun 21st 2007 at 10:11 +0100, quoth Michael Hoffman: =[EMAIL PROTECTED] wrote: = Hello, = Does anyone know how to make python-mode correctly indent nested lists = and dictionaries. I hate indenting Django url patterns and Zope = Archetypes schemas by hand, because python-mode indents

Decorator question

2007-05-23 Thread Steven W. Orr
I just discovered decorators. Very cool. My question is that I can't figure out how to make a decorator not be restricted to a function so it would also work on a method. Here's my code: def g(expr): def rpt(func): def wrapper(t): for ii in range(expr):

Further adventures in array slicing.

2007-05-04 Thread Steven W. Orr
This is more for my education and not so much for practicality. I have a structure that sort of looks like this: mdict = {33:{'name': 'Hello0', 'fields':'fields0', 'valid': 'valid0' 55:{'name': 'Hello1', 'fields':'fields1', 'valid':

What do people use for code analysis.

2007-05-02 Thread Steven W. Orr
Lots of code, calls to, calls by, inheritance, multiple tasks, etc. What do people use to figure out what's happening? TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0

Re: What do people use for code analysis.

2007-05-02 Thread Steven W. Orr
On Wednesday, May 2nd 2007 at 12:48 +0200, quoth Daniel Nogradi: = Lots of code, calls to, calls by, inheritance, multiple tasks, etc. = = What do people use to figure out what's happening? = =This is a pretty cool project just for that: = =http://codeinvestigator.googlepages.com/codeinvestigator

how to create/ref globals in an alternate namespace?

2007-04-27 Thread Steven W. Orr
I have two seperate modules doing factory stuff which each have the similar function2: In the ds101 module, def DS101CLASS(mname,data): cname = mname+'DS101' msg_class = globals()[cname] msg = msg_class(data) return msg and in the fdu module, def FDUCLASS(mname,data):

Re: how to create/ref globals in an alternate namespace?

2007-04-27 Thread Steven W. Orr
On Friday, Apr 27th 2007 at 14:07 -0700, quoth James Stroud: =Steven W. Orr wrote: = I have two seperate modules doing factory stuff which each have the = similar function2: = = In the ds101 module, def DS101CLASS(mname,data): = cname = mname+'DS101' = msg_class = globals()[cname

Re: Shebang or Hashbang for modules or not?

2007-04-23 Thread Steven W. Orr
On Saturday, Apr 21st 2007 at 19:18 +0100, quoth Michael Hoffman: =Chris Lasher wrote: = Should a Python module not intended to be executed have shebang/ = hashbang (e.g., #!/usr/bin/env python) or not? I'm used to having a = shebang in every .py file but I recently heard someone argue that =

Re: Shebang or Hashbang for modules or not?

2007-04-23 Thread Steven W. Orr
On Monday, Apr 23rd 2007 at 17:31 +0100, quoth Michael Hoffman: =Steven W. Orr wrote: = On Saturday, Apr 21st 2007 at 19:18 +0100, quoth Michael Hoffman: = = =Chris Lasher wrote: = = Should a Python module not intended to be executed have shebang/ = = hashbang (e.g., #!/usr/bin/env python

Can __init__ not return an object?

2007-04-21 Thread Steven W. Orr
When I go to create an object I want to be able to decide whether the object is valid or not in __init__, and if not, I want the constructor to return something other than an object, (like maybe None). I seem to be having problems. At the end of __init__ I say (something like) if

I need a string/list/generator/comprehension incantation.

2007-04-20 Thread Steven W. Orr
I really tried. I give up. I got this one last time (for which I'm very grateful). import calendar months = dict([(month,ii) for ii,month in enumerate(calendar.month_abbr)][1:]) Now I want something that's going to give me a string whose value is the set of all of the first letters of months.

Re: Nested dictionaries trouble

2007-04-18 Thread Steven W. Orr
On Wednesday, Apr 18th 2007 at 12:16 -0700, quoth IamIan: =I am using the suggested approach to make a years list: = =years = [199%s % x for x in range(0,10)] =years += [200%s % x for x in range(0,10)] = =I haven't had any luck doing this in one line though. Is it possible? I'm so green that I

How to initialize a table of months.

2007-04-15 Thread Steven W. Orr
I'm reading a logfile with a timestamp at the begging of each line, e.g., Mar 29 08:29:00 I want to call datetime.datetim() whose arg2 is a number between 1-12 so I have to convert the month to an integer. I wrote this, but I have a sneaky suspicion there's a better way to do it. mons =

Re: Prevent Modification of Script?

2007-04-06 Thread Steven W. Orr
On Wednesday, Apr 4th 2007 at 18:04 -0700, quoth ts-dev: =Is it possible to prevent modification of a python file once its been =deployed? File permissions of the OS could be used..but that doesn't =seem very secure. = =The root of my question is verifying the integrity of the application =and

elementary tuple question. (sorry)

2007-04-05 Thread Steven W. Orr
I have a tuple that I got from struct.unpack. Now I want to pass the data from the returned tuple to struct.pack fmt 'l 10l 11i h 4h c 47c 0l' struct.pack(fmt, tup) Traceback (most recent call last): File stdin, line 1, in ? struct.error: required argument is not an integer What's the idiom

Re: exit to interpreter?

2007-03-27 Thread Steven W. Orr
On Friday, Mar 23rd 2007 at 10:52 -0700, quoth belinda thom: =I'm writing a function that polls the user for keyboard input, =looping until it has determined that the user has entered a valid =string of characters, in which case it returns that string so it can =be processed up the call

Is every number in a list in a range?

2007-03-05 Thread Steven W. Orr
I have a list ll of intergers. I want to see if each number in ll is within the range of 0..maxnum I can write it but I was wondering if there's a better way to do it? TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this.

Question about raise and exceptions.

2007-02-28 Thread Steven W. Orr
In my class I have class Error(Exception): Base class for exceptions in this module. pass class TransitionError(Error): Raised when an operation attempts a state transition that's not allowed. Attributes: previous -- state at

Re: Question about raise and exceptions.

2007-02-28 Thread Steven W. Orr
On Wednesday, Feb 28th 2007 at 22:03 +0100, quoth Bruno Desthuilliers: =Daniel Klein a ?crit : = On Wed, 28 Feb 2007 13:48:54 -0500 (EST), Steven W. Orr = [EMAIL PROTECTED] wrote: = = =When I run it I get this: = =884 ./t_fsm.py =Traceback (most recent call last): = File ./t_fsm.py, line 3

Question about idiomatic use of _ and private stuff.

2007-02-23 Thread Steven W. Orr
I understand that two leading underscores in a class attribute make the attribute private. But I often see things that are coded up with one underscore. Unless I'm missing something, there's a idiom going on here. Why do people sometimes use one leading underscore? TIA -- Time flies like the

Solved: Question about idiomatic use of _ and private stuff.

2007-02-23 Thread Steven W. Orr
On Friday, Feb 23rd 2007 at 11:12 -0500, quoth Steven W. Orr: =I understand that two leading underscores in a class attribute make the =attribute private. But I often see things that are coded up with one =underscore. Unless I'm missing something, there's a idiom going on here. = =Why do people

Question about classes and possible closure.

2007-02-21 Thread Steven W. Orr
This is all an intro learning experience for me, so please feel free to explain why what I'm trying to do is not a good idea. In the Cookbook, they have a recipe for how to create global constants. - class _const: class ConstError(TypeError): pass def

Can I reverse eng a .pyc back to .py?

2007-02-20 Thread Steven W. Orr
The short story is that someone left, but before he left he checked in a .pyc and then both the directory was destroyed and the backups all got shredded (don't ask*). Is there anything that can be extracted? I looked on the web and the subject seems to get different answers, all old. Any joy?

How do I create an array of functions?

2007-02-18 Thread Steven W. Orr
I have a table of integers and each time I look up a value from the table I want to call a function using the table entry as an index into an array whose values are the different functions. I haven't seen anything on how to do this in python. TIA -- Time flies like the wind. Fruit flies

Question about optparse/OptionParser callback.

2007-02-09 Thread Steven W. Orr
I'm new to python and I have a need to do this. The Cookbook almost takes me there with: def check_order(option, opt_str, value, parser): if parser.values.b: raise OptionValueError(can't use %s after -b % opt_str) setattr(parser.values, option.dest, 1) but warns that the it

Retry:Question about optparse/OptionParser callback.

2007-02-09 Thread Steven W. Orr
I decided I could be more articulate. I hope this helps. I'm writing a program that needs to process options. Due to the nature of the program with its large number of commandline options, I would like to write a callback to be set inside add_option. Something like this: parser.add_option(-b,

Question about a single underscore.

2007-02-01 Thread Steven W. Orr
I saw this and tried to use it: --8--- const.py- class _const: class ConstError(TypeError): pass def __setattr__(self,name,value): if self.__dict__.has_key(name): raise self.ConstError, Can't rebind const(%s)%name

Re: Question about a single underscore.

2007-02-01 Thread Steven W. Orr
On Thursday, Feb 1st 2007 at 09:25 -0800, quoth Bart Ogryczak: =On Feb 1, 5:52 pm, Steven W. Orr [EMAIL PROTECTED] wrote: = I saw this and tried to use it: = = --8--- const.py- =[...] = sys.modules[__name__]=_const() = =__name__ == 'const', so you?re

Re: Question about a single underscore.

2007-02-01 Thread Steven W. Orr
On Thursday, Feb 1st 2007 at 10:36 -0800, quoth Paul Rubin: =Steven W. Orr [EMAIL PROTECTED] writes: = to cause a different instantiation a la = foo = _const() = The goal would be to create different instances of consts. = =The idea of putting it in sys.modules is so it's visible in all modules

Re: Question about a single underscore.

2007-02-01 Thread Steven W. Orr
On Thursday, Feb 1st 2007 at 21:45 +0100, quoth Bruno Desthuilliers: =Steven W. Orr a écrit : = I saw this and tried to use it: = = --8--- const.py- = class _const: = class ConstError(TypeError): pass = def __setattr__(self,name,value

  1   2   >