[Tutor] Shared FIFO?

2009-05-17 Thread Allen Fowler
Hello, I have several CGI scripts that I would like coordinate via a "First In / First Out" style buffer.That is, some processes are adding work units, and some take the oldest and start work on them. What is the right way to do this?I suppose I could use an SQL server or SQlite , but

Re: [Tutor] Shared FIFO?

2009-05-18 Thread Allen Fowler
> "Allen Fowler" wrote > > I have several CGI scripts that I would like coordinate via a "First In / > First Out" style buffer.That is, some processes are adding work units, > and > some take the oldest and start work on them. > > > >

[Tutor] Mapping to an equivalent / similar object?

2009-05-28 Thread Allen Fowler
Hello, Imagine the relationship between an Ice Cream retail store and the several manufactures that supply it's flavors. The retail store has a single list of flavors and any given flavor can be made by one or more manufactures. (Most are made by several.) The store's stock monitoring system

Re: [Tutor] Mapping to an equivalent / similar object?

2009-05-30 Thread Allen Fowler
> The difference between objects is measeured by their interfaces not their > data > so provided the supplier objects all use the same operations of a Flavor then > its not too bad. You can either create subclasses of Flavor for each > manufacturer that retuirns the requisite list of attrib

[Tutor] Sample python file/module templates?

2009-05-31 Thread Allen Fowler
Hello, In terms of in-code documentation of function / section headers, change logs, etc. Are there well-done sample files I can use as inspiration? Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listi

[Tutor] Spell checking source code?

2009-06-01 Thread Allen Fowler
Hello, Are there any utilities to help "spell check" source code? (Docstrings, etc) Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Suggested source code folder layout

2009-06-02 Thread Allen Fowler
Hello, I'm looking for some suggestions as to the filesystem source code layout for a new project. Here is what I am thinking so far: root_folder/ - app/ -- Code for our pylons/django/TG/etc web app - web/ -- Public static web files (and wsgi / fastCGI connector files) - db/ -- SQlite DB - scr

Re: [Tutor] Suggested source code folder layout

2009-06-08 Thread Allen Fowler
> > My 2 cents... > > 1) Since you are describing your source code layout, any virtual > environment should be outside. A virtual environment (virtualenv) is > part of deployment and not part of source. If you need to make a > reproducible deployment environment, then you need a deployment syst

[Tutor] Configuaration files and paths?

2009-08-05 Thread Allen Fowler
Hello, What is the recommended way to configure my application find the various database and/or configuration files it needs? For instance my folder layout: /path_to_app/app.py /path_to_app/lib/ /path_to_app/database/ /path_to_app/config/ /path_to_app/photos and so on. (app.py being th

Re: [Tutor] Configuaration files and paths?

2009-08-05 Thread Allen Fowler
> > What is the recommended way to configure my application find the various > database and/or configuration files it needs? > > Recommemded by whom? A lot depends on the OS. Apple for example have one set > of > recommendations for MacOS, Windows has another and Linux has several to > cho

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
> > Assuming the application could be invoked in odd ways that may alter the > notion of the current working directory, how do I unambiguously find the > absolute path to the current python source file? (So I can load the nearby > .ini) > > I use a helper function that calculates the absol

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
> Martin Walsh > > Allen Fowler wrote: > > > > > > > As a follow-up question, how do give my modules stored under ./lib access > > to > the data in my ConfigParser object? (For instance, database connection > string, > storage path, etc.)

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
> > Something like this ... > > # lib/mypaths.py > # -- > > import os > > def script_path(base): > return os.path.realpath(os.path.abspath(base)) > > def script_dir(base): > return os.path.dirname(script_path(base)) > > def join_relative(base, path): > return os.pa

Re: [Tutor] Configuaration files and paths?

2009-08-07 Thread Allen Fowler
> > > > FWIW: > > > > When using relative paths I got extra ../../ terms, so I changed > join_relative() to: > > > > def join_relative(base, path): > > return os.path.normpath(os.path.join(script_dir(base), path)) > > > > > > Seems to work... > > > Yeah, good catch ... looks great,

[Tutor] Fixing "nearly ASCII" data file?

2009-08-10 Thread Allen Fowler
Hello, I have some CSV data from Office / OpenOffice in "nearly ASCII" format. This is just basic text but it it stored as UTF-8, and has curly quotes, etc. Is there a way to easily read the file as ASCII by forcing these to the standard ASCII equivalents? Thank you ___

[Tutor] string.title(): correct?

2009-08-11 Thread Allen Fowler
Hello, "He's a great guy".title() Gives me: "He'S A Great Guy" I expected: "He's A Great Guy" Did i miss something here? Thank you, :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] multiprocessing: Correct usage of pool & queue?

2009-09-03 Thread Allen Fowler
Hello, I have a list of tasks/items that I want handed off to threads/processes to complete. (I would like to stick with process if I could, since there is some CPU work here. ) Each task involves some calculations and a call to a remote server over urllib2/HTTP. The time to complete each

[Tutor] Exceptions: Logging TB and local variables?

2007-10-09 Thread Allen Fowler
Hi, My code looks like this: for item in bigset: self.__sub1(item) self.__sub2(item) self.__sub3(item) # the subX functions, in turn, use various 3rd party modules. Now, I would like to do this: for item in bigset: try: self.__sub1(item) self.__sub2(item)

[Tutor] __getattr__(): Is this right?

2007-10-15 Thread Allen Fowler
I seem to be having an issue with __getattr__() being called even if the proporite already exists... I thought that this was not supposed to happen. Is there a typo somewhere, or I do i misunderstand things? class someclass(object): def __init__(self, **kargs): self.val

Re: [Tutor] __getattr__(): Is this right?

2007-10-15 Thread Allen Fowler
Eric Brunson <[EMAIL PROTECTED]> wrote: Allen Fowler wrote: > I seem to be having an issue with __getattr__() being called even if > the proporite already exists... I thought that this was not supposed > to happen. I think you've misunderstood. __getattr__() should

Re: [Tutor] __getattr__(): Is this right? [w/ new code]

2007-10-15 Thread Allen Fowler
What did you try? What happened? What did you expect? Kent Narrowed things down a bit. Given this class: --- class sc(object): def __init__(self, **kargs): self.valid_props = [ 'foo', 'bar', 'baz' ] for prop in self.valid_props:

Re: [Tutor] __getattr__(): Is this right?

2007-10-15 Thread Allen Fowler
> "Note that if the attribute is found through the normal mechanism, > __getattr__() is not called. (This is an intentional asymmetry between > __getattr__() and __setattr__().) This is done both for efficiency > reasons and because otherwise __setattr__() would have no way to > access other

Re: [Tutor] __getattr__(): Is this right? [w/ new code]

2007-10-15 Thread Allen Fowler
Umm... well. obviously I left out an __setattr__() call.. sigh. thanks anyway... Allen Fowler <[EMAIL PROTECTED]> wrote: What did you try? What happened? What did you expect? Kent Narrowed things down a bit. Given this class: --- class sc(

[Tutor] Pythonic way to "try a few times, then raise exception"?

2007-10-26 Thread Allen Fowler
Hello, I have a block of code buried deep in a module that I expect to fail periodically. (Calls to other machines over slow network, and such.) Generally, though, trying it a second / third will work. Is there clean way to write this on Python? Thanks _

[Tutor] run in "deamon" mode?

2008-01-09 Thread Allen Fowler
Hello, How can a make a python script run in "deamon mode"? (on a linux box) That is, I want to run the program via "python myfile.py" and have it drop me back to the command line. The program should continue running until I kill it via it's PID, the machine shuts down, or the program itself d

Re: [Tutor] run in "deamon" mode?

2008-01-10 Thread Allen Fowler
Thank you for all the great tips... I'll try a few and see what works. I must say that I'm a bit surprised that the Python Std library does not have a module for this. Are all python scripts expected to be small user-mode utilities? _

[Tutor] Video file metadata? (MP4/WMV)

2008-03-04 Thread Allen Fowler
Hello, I have several hundred WMV video files with bad embedded author/title/date information. However, the correct information is correctly encoded in the file name.. i.e. "title-author-date.wmv" Seems like the a great job for Python. :) Also, I am about to convert these fiiles to MP4 f

Re: [Tutor] Video file metadata? (MP4/WMV)

2008-03-04 Thread Allen Fowler
nt: Tuesday, March 4, 2008 7:32:01 PM > Subject: Re: [Tutor] Video file metadata? (MP4/WMV) > > > "Allen Fowler" wrote in > > > 1) Does these exist a python module I can use to > > programatically edit the metadata in MP4 > > files? > > I don;

[Tutor] Simple reg-ex syntax?

2008-03-12 Thread Allen Fowler
Hello, I have code that looks something like: self.aString = "abc123xyz" self.theNumber = int(re.search('(\d+)',self.aString).group()) Is there a more Pythonic way of doing this? (Both the reg-ex and the Int coercion.) How about when I will need to extract more than one substring? Thank you,

[Tutor] Correct way to call an outside program?

2008-03-12 Thread Allen Fowler
Hello, I need to call an external command line .exe utility from my Python script. What is the best way to capture the output (if any) and (optionally) direct it to my normal standard output? There seem to be many options... Thank you, :) _

Re: [Tutor] Correct way to call an outside program?

2008-03-13 Thread Allen Fowler
Thank you for the help. :) - Original Message simplest way to run external commands ! import os cmd="/usr/bin/ssh 10.0.0.20 uptime" os.popen(cmd) my cmd is just an example, use any cmd you want & its output will be displayed to you. hope this helps [SNIP] subprocess.Popen().com

Re: [Tutor] Simple reg-ex syntax?

2008-03-13 Thread Allen Fowler
s. > > To convert, use a list comprehension: > self.allNumbers = [int(i) for i in self.digit_extractor.findall(self.aString)] > > Cheers > > On Wednesday 12 March 2008 21:59, Allen Fowler wrote: > > Hello, > > > > I have code that looks something like: > >

[Tutor] Calling super classs __init__?

2008-03-18 Thread Allen Fowler
Hello, Now, perhaps this not the best way write code, but I have a few questions regrading calling the super classes constructor: I have a super class that accepts many arguments to it's constructor, and a subclass that should define one additional argument. What's the most "pythonic" way to m

[Tutor] kwargs to object proporties?

2008-03-18 Thread Allen Fowler
Hello, What's the best way convert keyword arguments to object properties? Basically, I have a defined list of valid object properties that I'd like to optionally specify in the call to the constructor. I've got ideas about using __getattr__ but I'm not sure if that's the right way. Plus, tha

Re: [Tutor] Calling super classs __init__?

2008-03-18 Thread Allen Fowler
> > class MySubClass(MySuperClass): > > > > def __init__(self, just_a_sub_option): # what about other args? **args? > > I think I would go ahead and list the superclass parameters and put the > new one at the end: > def __init__(self, opt_1, opt_2, opt_3, opt_n, just_a_sub_option): >

Re: [Tutor] Calling super classs __init__?

2008-03-18 Thread Allen Fowler
> > What's the most "pythonic" way to make this work? > > class BaseClass(object): > def __init__(self, x, y, z, foo='foo'): # whatever > # etc > > class SubClass(BaseClass): > def __init__(self, t, *args, **kw): > BaseClass.__init__(self, *args, **kw) > # do something with t >

Re: [Tutor] Calling super classs __init__?

2008-03-19 Thread Allen Fowler
> Nowadays the best practice for invoking a method from all superclasses > (yes, multiple inheritance) is this: > > class SubClass(BaseClass): > def __init__(self, t, *args, **kw): > super(SubClass, self).__init__(*args, **kw) > # do something with t > > That way you let Pyth