Boost Python tutorial needs MSVC?

2006-12-20 Thread Max Wilson
fied Jamfile/Jamrules straight from the Boost subdirectory, and as you can see I'm using the sTOOLS=gcc option. 4. So why is it looking for Visual Studio and how do I stop it? Any ideas much appreciated. -Max Wilson -- http://mail.python.org/mailman/listinfo/python-list

Re: Boost Python tutorial needs MSVC?

2006-12-20 Thread Max Wilson
y case I simply copied bjam.exe to my working directory, for now. -Max Wilson -- http://mail.python.org/mailman/listinfo/python-list

Re: scopes of local and global variable

2006-12-22 Thread Max Wilson
Pyenos wrote: > does class WORK inherit t_len=0 from line1? > > does def getwork() inherit t_len=0 from line1? > > does def formattable(table_to_process,type) inherit t_len=0 from line1? > > does def format_t() inherit t_len=0 from line1? Not really, no. The global t_len is different than the loca

Re: Question about idioms for clearing a list

2006-02-06 Thread Mel Wilson
Fredrik Lundh wrote: > (del doesn't work on dictionaries) ... or rather [:] doesn't work on dictionaries ... Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d={'a':1, 'b':2, 'c':3} >>> print d {'a': 1, 'c

Re: Another try at Python's selfishness

2006-02-08 Thread Ben Wilson
"But the point is, the current situation is not newbie-friendly (I can tell, I am a newbie)" I will agree to that, as I consider myself still new. _But_, it's a stumbling stone only briefly. Get enough nagging error messages, and you learn and move on. I agree with the grandparent poster that it i

Ternary Operator Now?

2006-02-08 Thread Ben Wilson
I read somewhere else that Python was getting a ternary operator (e.g. x = (true/false) ? y : z). I read the PEP about it and that the PEP had been approved this past Fall. Has this been released into the wild yet? IIRC, the operator is like: x = y if C : else z -- http://mail.python.org/mailma

Newbie Q: dynamically assigning object attribute

2006-02-09 Thread Ben Wilson
I would like to dynamically assign object attributes: dict = { a : 1, b : 2, } for key,val in dict : obj.key = val To get: print obj.a 1 I've googled to no effect, or maybe I'm needing to be hit with the appropriately sized clue-by-four. Any assistance would be appreciated. Regards, Ben

Re: Newbie Q: dynamically assigning object attribute

2006-02-09 Thread Ben Wilson
That's it. I should spend more time R-ingTFM. I kept looking for some class-based solution and there was a built in. Perfectly logical. Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: dynamically assigning object attribute

2006-02-10 Thread Ben Wilson
Well, my Perl way of doing it would be to have all attributes in a dict (hash), then create the accessor vi a dynamic function. I knew Python would have a right way to do it for Python, but when I went looking I neglected to look at the core of the language. I suppose I'm just too accustomed to the

Re: how do you pronounce 'tuple'?

2006-02-13 Thread Ben Wilson
Yeah, I was going to say it's "I-66," not "Route 66," which has been replaced in pertainent parts by I-40. tuh-ple. -- http://mail.python.org/mailman/listinfo/python-list

Re: pop line from file

2006-02-15 Thread Dylan Wilson
Try open.readline() >>>help(open) ... -- http://mail.python.org/mailman/listinfo/python-list

Re: - Copy dictionary entries to attributes

2006-02-18 Thread Ben Wilson
Perhaps: def dictionary_make_attributes(self, settings): for k,v in settings: setattr(self, k, v) http://ftp.python.org/doc/lib/built-in-funcs.html#l2h-64 -- http://mail.python.org/mailman/listinfo/python-list

Re: editor for Python on Linux

2006-02-20 Thread Ben Wilson
He said "IDE." That means "vim" -- http://mail.python.org/mailman/listinfo/python-list

Re: editor for Python on Linux

2006-02-24 Thread Ben Wilson
You know, I have that for Perl, but seem never to have set up folding for Python. I must remedy this tonight. Ben -- http://mail.python.org/mailman/listinfo/python-list

Trolling for New Web Host . . .

2006-02-24 Thread Ben Wilson
way I can run a python script is by using the .cgi extension. I'm not sure if I want to stick with my host and just call my apps index.cgi, or if I should move to a new server. If I were to move to a new server, which would you recomend, and why? Regards, Ben Wilson -- http://mail.python.org/mai

Re: Trolling for New Web Host . . .

2006-02-26 Thread Ben Wilson
Thanks for your suggestions. I've Python on both my Win32 and Linux partitions of my laptop. Although, I suppose I should develop my CGI on the laptop (running Apache) first. Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list

Re: type = "instance" instead of "dict"

2006-02-28 Thread Mel Wilson
James Stroud wrote: > Fredrik Lundh wrote: > >> James Stroud wrote: >> >> >>> Perhaps you did not know that you can inheret directly from dict, which >>> is the same as {}. For instance: >>> >>> class Dict({}): >>> pass > > > I must have been hallucinating. I swear I did this before and it wor

Re: Number 1 can't use!

2005-05-25 Thread John Wilson
On 5/23/05, <潍坊风筝> <[EMAIL PROTECTED]> wrote: > After I installed python 2.4.1 , I found my keyborad Number 1 can't > work,but ! is still working How did you type the message then ;) -- http://mail.python.org/mailman/listinfo/python-list

Itertools question: how to call a function n times?

2007-07-19 Thread Matthew Wilson
I want to write a function that each time it gets called, it returns a random choice of 1 to 5 words from a list of words. I can write this easily using for loops and random.choice(wordlist) and random.randint(1, 5). But I want to know how to do this using itertools, since I don't like manually d

Re: List of Objects

2007-04-19 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Howdy, a (possibly) quick question for anyone willing to listen. > I have a question regarding lists and Classes; I have a class called > "gazelle" with several attributes (color, position, etc.) and I need > to create a herd of them. I want to simulate motion of individu

Re: When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?

2007-04-23 Thread Mel Wilson
Neil Cerutti wrote: > The interpreter explains it: "A list is not a hashable object." > Choosing a hash table instead of some kind of balanced tree seems > to be just an optimization. ;) Even with a balanced tree, if a key in a node changes value, you may have to re-balance the tree. Nothing in

Re: Numbers and truth values

2007-04-28 Thread Mel Wilson
John Nagle wrote: > "True", "False", and "None" should be reserved words in Python. > "None" already is. The permissiveness makes it less painful to upgrade to new versions of Python. True and False only recently got assigned conventional values, but you can still import old modules withou

Re: [python 2.4] unable to construct tuple with one item

2007-05-06 Thread Mel Wilson
Vyacheslav Maslov wrote: > So, the main question is why using syntax like [X] python constuct list > with > one item, but when i try to construct tuple with one item using similar > syntax (X) python do nothing? Because `(` and `)` are used in expressions to bracket sub-expressions. a = (4 + 3)

Re: this must be a stupid question ...

2007-07-28 Thread David Wilson
On 28/07/07, Stef Mientki <[EMAIL PROTECTED]> wrote: > but I can;t find the answer ;-) > > As searching for the '$' sign doesn't work well in the help files, > I can not find out, where is the '$' sign used for. > > If I try to use it in names, > I get a compiler error, > so it probably has some sp

Re: Events: The Python Way

2007-07-28 Thread David Wilson
Hi there, Python has no built-in way of doing this. You may consider writing your own class if you like this pattern (I personally do): class Event(object): def __init__(self): self.subscribers = set() def __iadd__(self, subscriber): self.subscribers.add(subscriber)

Re: number generator

2007-03-10 Thread Mel Wilson
Gerard Flanagan wrote: > On Mar 9, 4:17 pm, "cesco" <[EMAIL PROTECTED]> wrote: >> On Mar 9, 3:51 pm, Paul Rubin wrote: >> >>> "cesco" <[EMAIL PROTECTED]> writes: I have to generate a list of N random numbers (integer) whose sum is equal to M. If, for example, I

Re: How to get the previous line in a file?

2007-03-18 Thread Mel Wilson
Qilong Ren wrote: > Hi, Shane, > > Thanks for fast reply. > > What I used is : >for line in open(FILE): > > I don't want to store all lines in a list because sometimes the file is very > large. We need to store the value of the previous line in a variable. Is that > right?

Re: exit to interpreter?

2007-03-23 Thread Mel Wilson
belinda thom wrote: > On Mar 23, 2007, at 11:04 AM, [EMAIL PROTECTED] wrote: > >> On Mar 23, 12:52 pm, belinda thom <[EMAIL PROTECTED]> wrote: >>> Hi, >>> >>> I'm writing a function that polls the user for keyboard input, >>> looping until it has determined that the user has entered a valid >>> st

Re: Fortran vs Python - Newbie Question

2007-03-28 Thread Mel Wilson
Terry Reedy wrote: > "Tim Roberts" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Once upon a time, > | Basic enthusiasts would have used the word "tokenized" to describe .pyc > files. > > Perhaps, but they would, I think, have been wrong. Tokenized Basic to the > best of my

Re: Need help on reading line from file into list

2007-04-03 Thread Mel Wilson
bahoo wrote: [ ... ] > Thanks, this helped a lot. > I am now using the suggested > map(str.strip, open('source.txt').readlines()) > > However, I am a C programmer, and I have a bit difficulty > understanding the syntax. > I don't see where the "str" came from, so perhaps the output of > "open('sou

Re: [optparse] Problem with getting an option value

2007-04-06 Thread Mel Wilson
Peter Otten wrote: > Lucas Malor wrote: > >> Hello all. I'm trying to do a little script. Simply I want to make a list >> of all options with them default values. If the option is not specified in >> the command line, the script must try to read it in a config.ini file. If >> it's not present also

Re: tuples, index method, Python's design

2007-04-08 Thread Mel Wilson
7stud wrote: > On Apr 7, 8:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote: >> Adding useless features always makes a product worse. What's your use >> case for tuple.index? > I'll trade you an index method for tuples for the whole complex number > facility. Actually, I've found the use cases for

Re: Lists and Tuples and Much More

2007-04-12 Thread Mel Wilson
Scott wrote: > Now I read somewhere that you could change the list inside that tupple. But > I can't find any documentation that describes HOW to do it. The only things > I CAN find on the subject say, "Don't do it because its more trouble than > it's worth." But that doesn't matter to me, be

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Mel Wilson
jamadagni wrote: > OK fine. It is clear that this feature must be implemented if at all > only on a per-module basis. So can we have votes for per-module > implementation of this feature? The only way that can work is if the API to the module doesn't expose ANY sequence indices. It would be a gr

Re: Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

2007-04-14 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > In Visual Basic there is the keyword "with" which allows an object- > name to be declared as governing the following statements. For > example: > > with quitCommandButton > .enabled = true > .default = true > end with > > This is syntactic sugar for: > > quitCommandB

Re: generating list of sub lists

2007-09-17 Thread Ross Wilson
cesco wrote: > Hi, > > is there a one-liner to accomplish the following task? >>From the list > l = ['string1', 'string2', 'string3'] > generate the list of lists > l = [['string1'], ['string1', 'string2'], ['string1', 'string2', > 'string3']] > > Any help would be appreciated. > > Thanks > Fran

Using closures and partial functions to eliminate redundant code

2007-09-26 Thread Matthew Wilson
I wrote some code to create a user and update a user on a remote box by sending emails to that remote box. When I was done, I realized that my create_user function and my update_user function were effectively identical except for different docstrings and a single different value inside: ### V

Need recommendations on mock object packages

2007-10-17 Thread Matthew Wilson
What are the most popular, easiest to use, and most powerful mock object packages out there? Thanks in advance. Matt -- http://mail.python.org/mailman/listinfo/python-list

I can't get minimock and nosetests to play nice

2007-10-18 Thread Matthew Wilson
I'm curious if anyone has ever tried using nosetests along with minimock. I'm trying to get the two to play nice and not making progress. I also wonder if I'm using minimock incorrectly. Here's the code I want to test, saved in a file dtfun.py. class Chicken(object): "I am a chicke

python logging config file doesn't allow filters?

2007-10-26 Thread Matthew Wilson
The python logging module is a beautiful masterpiece. I'm studying filters and the config-file approach. Is it possible to define a filter somehow and then refer to it in my config file? TIA Matt -- http://mail.python.org/mailman/listinfo/python-list

assertions to validate function parameters

2007-01-25 Thread Matthew Wilson
Lately, I've been writing functions like this: def f(a, b): assert a in [1, 2, 3] assert b in [4, 5, 6] The point is that I'm checking the type and the values of the parameters. I'm curious how this does or doesn't fit into python's duck-typing philosophy. I find that when I detect inv

Can I undecorate a function?

2007-01-29 Thread Matthew Wilson
The decorator as_string returns the decorated function's value as string. In some instances I want to access just the function f, though, and catch the values before they've been decorated. Is this possible? def as_string(f): def anon(*args, **kwargs): y = f(*args, **kwargs)

Re: Help Required for Choosing Programming Language

2007-02-17 Thread Max Wilson
On Feb 17, 1:35 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > But I've done extensive, cross-platform development with Qt. And can > assert that it is unmatched in productivity and feature richness, > especially when combined with python. And certainly beat VB, and most > probably even delphi

Need help writing coroutine

2007-11-07 Thread Matthew Wilson
I'm working on two coroutines -- one iterates through a huge stream, and emits chunks in pieces. The other routine takes each chunk, then scores it as good or bad and passes that score back to the original routine, so it can make a copy of the stream with the score appended on. I have the code wo

Re: michael lalonde

2007-12-19 Thread wilson . smith9
http://wanderer.artificial-stupidity.net/ On Dec 16, 1:26 am, Michael Lalonde <[EMAIL PROTECTED]> wrote: > x-no-archive: yes > Michael Lalonde saw a movie made by Mr Harnwell on an ironing board > and got locked in a room full of greasy meat because he felt like it > and chased a bunnywhich got

Re: mike lalonde

2007-12-25 Thread wilson . smith9
http://wanderer.artificial-stupidity.net/ On Dec 15, 3:21 am, Michael Lalonde <[EMAIL PROTECTED]> wrote: > Michael Lalonde traveled with Mr Harnwell in an icy cave and went > around killing rats with a jackhammer because his leg hurt and fell > violently ill. Michael Lalonde just dodged three bul

Better way to sift parts of URL . . .

2006-04-18 Thread Ben Wilson
I am working on a script that splits a URL into a page and a url. The examples below are the conditions I expect a user to pass to the script. In all cases, "http://www.example.org/test/"; is the URL, and the page comprises parts that have upper case letters (note, 5 & 6 are the same as earlier exa

Re: Better way to sift parts of URL . . .

2006-04-18 Thread Ben Wilson
Here is what I came up with: def siftUrl(s): s = s.split('//')[1] bits = s.split('/') if '' in bits: bits.remove('') if len(bits) > 1: group = bits[-2] page = bits[-1] group.strip('/') page.strip('/') else

Re: Better way to sift parts of URL . . .

2006-04-18 Thread Ben Wilson
mention having tried > the urlparse module, so I thought I should ask: have you tried using > urlparse? > > Skip > -- Ben Wilson " Mundus vult decipi, ergo decipiatur" -- http://mail.python.org/mailman/listinfo/python-list

Re: Better way to sift parts of URL . . .

2006-04-19 Thread Ben Wilson
This is what I ended up with. Slightly different approach: import urlparse def sUrl(s): page = group = '' bits = urlparse.urlsplit(s) url = '//'.join([bits[0],bits[1]]) + '/' query = bits[2].split('/') if '' in query: query.remove('') if len(query) > 1: page = quer

Re: Better way to sift parts of URL . . .

2006-04-19 Thread Ben Wilson
In practice, I had to change this: if len(query) > 0 and query[-1] == query[-1].capitalize(): group = query.pop() to this: if len(query) > 0 and query[-1][0] == query[-1].capitalize()[0]: group = query.pop() This is because I only wanted to test the case of the first letter of the string. --

Re: lambda

2006-04-21 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Hello, > > I need your help understanding lambda (and doing it a better way > without). > > f = lambda x : x*x [ ... ] > # the idea is now to give the definition of the multiplication of > functions and integers > # (f * c)(xx) := f(x)*c > [lambda xx: f(xx)*y for y in

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-21 Thread Mel Wilson
Anthony Liu wrote: > I am at my wit's end. > > I want to generate a certain number of random numbers. > This is easy, I can repeatedly do uniform(0, 1) for > example. > > But, I want the random numbers just generated sum up > to 1 . > > I am not sure how to do this. Any idea? Thanks. number

Re: simultaneous assignment

2006-05-02 Thread Mel Wilson
Roger Miller wrote: > Steve R. Hastings wrote: > > >>a = 0 >>b = 0 >>a is b # always true > > > Is this guaranteed by the Python specification, or is it an artifact of > the current implementation? AFAIK it's an artifact. The performance hit it Python stopped sharing small integers could b

Re: Tuple assignment and generators?

2006-05-05 Thread Mel Wilson
vdrab wrote: > I guess the take-away lesson is to steer clear from any reliance on > object identity checks, if at all possible. Are there any other such > "optimizations" one should like to know about? Object identity checks are just the thing/numero uno/ichiban for checking object identity. A

Re: printing list

2006-05-07 Thread Mel Wilson
Tim Chase wrote: > compboy wrote: > >> How do you print elements of the list in one line? >> >> alist = [1, 2, 5, 10, 15] >> >> so it will be like this: >> 1, 2, 5, 10, 15 > > > >>> print ', '.join(alist) > 1, 2, 5, 10, 15 ??? Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Typ

Re: Complex evaluation bug

2006-05-18 Thread Mel Wilson
of wrote: > a = 1+3j > complex(str(a)) > > Why does this not work ? It should It would be nice. Looks like str(1+3j) is returning an expression in string form. Maybe there is no actual complex literal. eval (str(1+3j)) works. Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [GCC 3.3.4] on linux2 Type

Re: [silly] Does the python mascot have a name ?

2006-05-18 Thread Mel Wilson
Steve wrote: > Carl J. Van Arsdall wrote: >> John D Salt wrote: >> hon-list/2003-September/185612.html > "Odi" must be the Dutch for "Monty". Nope. If it was Dutch it would probably be Odie >>> Damn. >>> >> Odi(e) was a punk. I'm gonna be a rebel without a cause and stay with >> M

Re: Question about exausted iterators

2006-05-19 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Consider this example: > X = range(5) Y = iter(X) Z = iter(Y) > > As you can see, X is a container, and Y is an iterator. > They are simliar in that "iter" works on them both. > > Cristoph claims that this causes confusion. > Why? Because "iter" doesn't

Re: [silly] Does the python mascot have a name ?

2006-05-19 Thread Mel Wilson
John D Salt wrote: > Mel Wilson <[EMAIL PROTECTED]> wrote in news:_s2bg.8867$aa4.296233 > @news20.bellglobal.com: > > [Snips] >> Just reinforces the central truth. The mascot doesn't >> *have* a name. Most things don't. > > Most things don'

Re: "Thinking like CS" problem I can't solve

2006-05-23 Thread Mel Wilson
Alex Pavluck wrote: > Hello. On page 124 of "Thinking like a Computer Scientist". There is > an exercise to take the following code and with the use of TRY: / > EXCEPT: handle the error. Can somone help me out? Here is the code: > [ ... ] What error? Python 2.4.2 (#1, Jan 23 2006, 21:24:54) [

Re: John Bokma harassment

2006-05-24 Thread Ian Wilson
[EMAIL PROTECTED] wrote: > Xah Lee schreef: > >> > off-topic postings> Which reminds me of http://www.catb.org/~esr/faqs/smart-questions.html#not_losing > We seem to have strayed a long way from Voltaire's > "I do not agree with what you say, but I will defend to the death your > right to say it.

Re: list comprehensions put non-names into namespaces!

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Lonnie> List comprehensions appear to store their temporary result in a > Lonnie> variable named "_[1]" (or presumably "_[2]", "_[3]" etc for > Lonnie> nested comprehensions) > > Known issue. Fixed in generator comprehensions. Dunno about plans to fix > it

Re: genexp surprise (wart?)

2006-05-26 Thread Mel Wilson
Paul Rubin wrote: > "Paul Du Bois" <[EMAIL PROTECTED]> writes: >> The second is that you don't like the late-binding behavior of >> generator expressions. PEP 289 has this to say: >> >>> After much discussion, it was decided that the first (outermost) >>> for-expression should be evaluated immediat

Re: "Learning Python" 2nd ed. p479 error?

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > Hello all. > > On page 479, the 2nd edition of the "Learning Python" book, this code > appears > > class Derived(Base): > def __init__(self, arg, *args, **kw): > self.__init__(self, *args, **kw) > > Surely self.__init__ should be > >

Re: how to clear up a List in python?

2006-05-26 Thread Mel Wilson
[EMAIL PROTECTED] wrote: > The original post only mentions deleting the values in the list, not > the list itself. Given that you want to keep the list and just ditch > the values it contains I'd go with: > > list1 = [] Depends what you mean by "keep the list". Consider class C (object):

I don't understand what is happening in this threading code

2008-01-18 Thread Matthew Wilson
In this code, I tried to kill my thread object by setting a variable on it to False. Inside the run method of my thread object, it checks a different variable. I've already rewritten this code to use semaphores, but I'm just curious what is going on. Here's the code: import logging, threading,

Python 2.6 json & encoding of datetime.

2008-10-10 Thread David Wilson
Hi there, I've been playing with Python's new json library, and found myself facing a seemingly simple problem: encoding of datetime objects. Some 'jsonlib' that I was using previously was unable to do this, and the new built-in json module shares the same limitation. A bit of googling around bro

PyYAML: How to register my yaml.YAMLObject subclasses?

2008-10-11 Thread Matthew Wilson
I suspect the solution to my problem is something really trivial. I wrote a module called pitz that contains a class Issue: >>> pitz.Issue.yaml_tag u'ditz.rubyforge.org,2008-03-06/issue' Then I try to load a document with that same tag, but I get a ConstructorError: ConstructorError

Need advice on python importing

2008-10-17 Thread Matthew Wilson
I started with a module with a bunch of classes that represent database tables. A lot of these classes have methods that use other classes inside, sort of like this: class C(object): @classmethod def c1(cls, a): return a class D(object): def d1(self, a

Re: Need advice on python importing

2008-10-17 Thread Matthew Wilson
On Fri 17 Oct 2008 04:52:47 PM EDT, Steve Holden wrote: > Matthew Wilson wrote: >> I started with a module with a bunch of classes that represent database >> tables. A lot of these classes have methods that use other classes >> inside, sort of like this: >

Very simple WSGI question

2008-11-16 Thread Matthew Wilson
I want to write some middleware to notice when the inner app returns a 500 status code. I'm sure there are already sophisticated loggers that do this sort of thing, but I'm using this as a learning exercise. Right now, I wrapped the start_response callable. So when the WSGI application calls the

Minimilistic Python on Linux?

2009-03-11 Thread Royce Wilson
I'm working on a minimilistic linux project and would like to include Python. However, since Python is around 17MB (compressed) and previous releases of this linux distro are under 100MB (compressed) standard Python releases are much to large. I just need the runtime libs of Python, the absoulute

Re: Minimilistic Python on Linux?

2009-03-11 Thread Royce Wilson
On Wed, Mar 11, 2009 at 9:33 PM, Royce Wilson wrote: > Thanks for the quick responses. When I view sys.modules I get this: > > sre_compile _collections locale _sre functools encodings site operator io > __main__ copyreg _weakref abc builtins encodings.cp437 errno sre_co

Re: Minimilistic Python on Linux?

2009-03-12 Thread Royce Wilson
Thanks, much better. What exactly do I lose when I launch python without site.py? On Wed, Mar 11, 2009 at 10:27 PM, Gabriel Genellina wrote: > En Thu, 12 Mar 2009 00:41:18 -0200, Royce Wilson > escribió: > >> On Wed, Mar 11, 2009 at 9:33 PM, Royce Wilson wrote: >> >

Re: Minimilistic Python on Linux?

2009-03-12 Thread Royce Wilson
Is there a way to veiw the modules without import sys? Thanks again. On Thu, Mar 12, 2009 at 1:52 PM, Royce Wilson wrote: > Thanks, much better. What exactly do I lose when I launch python without > site.py? > > > On Wed, Mar 11, 2009 at 10:27 PM, Gabriel Genellina < > g

Can I import from a directory that starts with a dot (.) ?

2009-04-13 Thread Matthew Wilson
I want to have .foo directory that contains some python code. I can't figure out how to import code from that .foo directory. Is this even possible? TIA Matt -- http://mail.python.org/mailman/listinfo/python-list

Need help with setup.py and data files

2009-04-21 Thread Matthew Wilson
I'm working on a package that includes some files that are meant to be copied and edited by people using the package. My project is named "pitz" and it is a bugtracker. Instead of using a config file to set the options for a project, I want to use python files. When somebody installs pitz, I wan

How to walk up parent directories?

2009-05-03 Thread Matthew Wilson
Is there already a tool in the standard library to let me walk up from a subdirectory to the top of my file system? In other words, I'm looking for something like: >>> for x in walkup('/home/matt/projects'): ... print(x) /home/matt/projects /home/matt /home / I know I

Re: How to walk up parent directories?

2009-05-04 Thread Matthew Wilson
On Sun 03 May 2009 09:24:59 PM EDT, Ben Finney wrote: > Not every simple function belongs in the standard library :-) Thanks for the help with this! Maybe I'm overestimating how often people need this walkup function. Matt -- http://mail.python.org/mailman/listinfo/python-list

How should I use grep from python?

2009-05-07 Thread Matthew Wilson
I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir that contain

Re: How should I use grep from python?

2009-05-07 Thread Matthew Wilson
On Thu 07 May 2009 09:09:53 AM EDT, Diez B. Roggisch wrote: > Matthew Wilson wrote: >> >> As of May 2009, what is the recommended way to run an external process >> like grep and capture STDOUT and the error code? > > subprocess. Which becomes pretty clear when readi

Re: How should I use grep from python?

2009-05-07 Thread Matthew Wilson
On Thu 07 May 2009 09:25:52 AM EDT, Tim Chase wrote: > While it doesn't use grep or external processes, I'd just do it > in pure Python: Thanks for the code! I'm reluctant to take that approach for a few reasons: 1. Writing tests for that code seems like a fairly large amount of work. I think I

I need help building a data structure for a state diagram

2009-05-24 Thread Matthew Wilson
I'm working on a really simple workflow for my bug tracker. I want filed bugs to start in an UNSTARTED status. From there, they can go to STARTED. >From STARTED, bugs can go to FINISHED or ABANDONED. I know I can easily hard-code this stuff into some if-clauses, but I expect to need to add a lo

Re: I need help building a data structure for a state diagram

2009-05-24 Thread Matthew Wilson
On Sun 24 May 2009 03:42:01 PM EDT, Kay Schluehr wrote: > > General answer: you can encode finite state machines as grammars. > States as non-terminals and transition labels as terminals: > > UNSTARTED: 'start' STARTED > STARTED: 'ok' FINISHED | 'cancel' ABANDONED > ABANDONED: 'done' > FINISHED: 'd

How can I get access to the function called as a property?

2009-05-24 Thread Matthew Wilson
I use a @property decorator to turn some methods on a class into properties. I want to be able to access some of the attributes of the original funtion, but I don't know how to get to it. Any ideas? Matt -- http://mail.python.org/mailman/listinfo/python-list

How to test python snippets in my documents?

2009-05-26 Thread Matthew Wilson
I'm using a homemade script to verify some code samples in my documentation. Here it is: #! /usr/bin/env python2.6 # vim: set expandtab ts=4 sw=4 filetype=python: import doctest, os, sys def main(s): "Run doctest.testfile(s, None)" return doctest.testfile(s, No

In metaclass, when to use __new__ vs. __init__?

2008-05-12 Thread Matthew Wilson
I have been experimenting with metaclasses lately. It seems possible to define a metaclass by either subclassing type and then either redefining __init__ or __new__. Here's the signature for __init__: def __init__(cls, name, bases, d): and here's __new__: def __new__(meta, classname,

defaultdict.fromkeys returns a surprising defaultdict

2008-06-03 Thread Matthew Wilson
I used defaultdict.fromkeys to make a new defaultdict instance, but I was surprised by behavior: >>> b = defaultdict.fromkeys(['x', 'y'], list) >>> b defaultdict(None, {'y': , 'x': }) >>> b['x'] >>> b['z'] -

proposal: give delattr ability to ignore missing attribute

2008-06-10 Thread Gary Wilson
I would like to propose that functionality be added to delattr to handle the case when the attribute does not exist. First off, getattr handles this nicely with the default parameter: value = getattr(obj, 'foo', False) instead of: try: value = getattr(obj, 'foo') except AttributeError:

Mutually referencing imports -- impossible?

2008-07-13 Thread Matthew Wilson
I started off with a module that defined a class Vehicle, and then subclasses Car and Motorcycle. In the Car class, for some bizarre reason, I instantiated a Motorcycle. Please pretend that this can't be avoided for now. Meanwhile, my Motorcycle class instantiated a Car as well. Then I moved th

How to package a logging.config file?

2008-07-13 Thread Matthew Wilson
I'm working on a package that uses the standard library logging module along with a .cfg file. In my code, I use logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in the logging config file. However, it seems really obvious to me that this won't work when I share this package wit

Re: How to package a logging.config file?

2008-07-15 Thread Matthew Wilson
On Mon 14 Jul 2008 09:25:19 AM EDT, Vinay Sajip wrote: > Is your package a library or an application? If it's a library, you > should avoid configuring logging using a config file - this is because > logging configuration is process-wide, and if multiple libraries use > fileConfig to configure thei

file()

2008-07-18 Thread Dylan Wilson
well, I'm in the beginings of making a random sentence generator for a mod my friend makes, but I want the nouns, verbs pastverbs, etc. to be easily customizable by editing a file, but, last night file() worked fine and today it's saying " line 1: `read_who = file('who.ini', 'r')'" here's what

How to get the version of a file

2008-04-14 Thread J Wilson
Does anyone know how to get the version of an application on OS X (i.e. the version string that appears in the "Version" field in the "Get Info" window for an application)? I'm running OS 10.4.11, python 2.5. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get the version of a file

2008-04-14 Thread J Wilson
I'm not clear on how to use this to read the version resource. Specially, I need to get the version of Palm Conduit, which is, I guess, a "carbonized" shared library... or something. ? [EMAIL PROTECTED] wrote: > you need appscript "that allows you to control scriptable Mac OS X > applications

Re: Factory for Struct-like classes

2008-08-14 Thread Matthew Wilson
f k in self.arglist: object.__setattr__(self, k, v) else: raise ValueError("%s ain't in %s" % (k, list(self.arglist))) return C And here it is in action: In [97]: Employee

Parsing and Editing Source

2008-08-15 Thread Paul Wilson
Hi all, I'd like to be able to do the following to a python source file programmatically: * Read in a source file * Add/Remove/Edit Classes, methods, functions * Add/Remove/Edit Decorators * List the Classes * List the imported modules * List the functions * List methods of classes And the

Re: inserting into a list

2006-03-07 Thread Mel Wilson
John Salerno wrote: > Christoph Haas wrote: >> L[2:2]=[3] [ ... ] What if you wanted to insert an actual list into that slot? Would > you have to wrap it in double brackets? Yep. It's a strong-typing thing. Slices of lists are lists, and therefore what you assign to one has got to be a list,

IOS-style command line interface module?

2006-03-11 Thread David Wilson
Hi folks, I seem to remember seeing a module some time in the distant past that provided an API for implementing Cisco IOS-like command line interfaces. I can't for the life of me find a reference to it on Google now. Does anyone know what I'm talking about? Thanks, David. -- http://mail.pyt

<    1   2   3   >