Process tuple contents on the fly

2013-04-15 Thread Gnarlodious
Say I have a tuple I want to expand assigning to variables: tup = *func() var = tup[0] lst.append(tup[1]) Or could I do it in one line? var, lst.append() = *func() So I want to append one variable to a list on the fly, is it possible? -- Gnarlie http://gnarlodious.com --

Re: Process tuple contents on the fly

2013-04-15 Thread Gnarlodious
On Monday, April 15, 2013 2:35:10 PM UTC-6, Tobiah wrote: tup = *func() What is the asterisk for? I assume it's a python 3 Not Python 3, pseudocode. I should have said as such, sorry. Supposed to indicate an expanded tuple. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get time.strptime()?

2012-12-27 Thread Gnarlodious
Graham Dumpleton has informed me that the the relevant bug reports are: http://bugs.python.org/issue8098 http://bugs.python.org/issue9260 To quote: All the problems derive from a stupid function in Python internals called PyImport_ImportModuleNoBlock(). It was designed to avoid lockups of the

Re: How to get time.strptime()?

2012-12-27 Thread Gnarlodious
Thank you for a reasonable discussion of the problem, although I don't really understand what you said. This is a WSGI webapp configured for one-process and one-thread. I can imagine my unorthodox handling of imported modules is suspect. To explain, my webapp first loads modules from a dict of

How to get time.strptime()?

2012-12-26 Thread Gnarlodious
Error: AttributeError: 'module' object has no attribute '_strptime' This problem is driving me crazy. It only happens in Python 3.3.0, while on my server running 3.1.3 it behaves as expected. When I try to access time.strptime() it errors with AttributeError: 'module' object has no attribute

Re: How to get time.strptime()?

2012-12-26 Thread Gnarlodious
Thanks for the help. This error only occurs on my devbox which is running Py 3.3.0: print(time.__file__, file=sys.stderr) /usr/local/python-3.3.0/frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload/time.so which looks normal to me. The server box, which is running Py 3.1.3, says

Re: How to get time.strptime()?

2012-12-26 Thread Gnarlodious
Nick Cash wrote: I was able to work around this by simply importing _strptime myself at server startup time. THANK YOU! That fixed it, I simply put import _strptime in my *.wsgi script. It feels like a kludgy solution, but it works. I should also mention that I had a similar problem with

Re: How to get time.strptime()?

2012-12-26 Thread Gnarlodious
Chris Angelico wrote: The problem here is that Python doesn't have any magical way to deal with messy imports in multiple threads But couldn't Py 3.3.1 at least raise an error mentioning threading as a possible cause? Because No module named _strptime is pretty cryptic. -- Gnarlie --

Re: Delete dict and subdict items of some name

2012-12-18 Thread Gnarlodious
On Tuesday, December 18, 2012 3:31:41 AM UTC-7, Hans Mulder wrote: On 18/12/12 06:30:48, Gnarlodious wrote: This problem is solved, I am so proud of myself for figuring it out! After reading some of these ideas I discovered the plist is really lists underneath any Children key

Delete dict and subdict items of some name

2012-12-17 Thread Gnarlodious
Hello. What I want to do is delete every dictionary key/value of the name 'Favicon' regardless of depth in subdicts, of which there are many. What is the best way to do it? -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Delete dict and subdict items of some name

2012-12-17 Thread Gnarlodious
This problem is solved, I am so proud of myself for figuring it out! After reading some of these ideas I discovered the plist is really lists underneath any Children key: from plistlib import readPlist def explicate(listDicts): for dict in listDicts: if 'FavIcon' in

pydoc links prepend a domain

2012-12-05 Thread Gnarlodious
The pydoc.html.docmodule sends a page with clickable links relative to the script location. Is there a way to tell pydoc to prepend a string to those URLs? -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Get named module's file location

2011-12-23 Thread Gnarlodious
Given a module's name, how do I get the file path without importing it? Searched all over, can't find any such info. Is it possible to ask if a named module exists before attempting an import? Or are we forced to import first and catch any failure? -- Gnarlie --

Re: Get named module's file location

2011-12-23 Thread Gnarlodious
Roy Smith wrote: import imp imp.find_module() Oh yeah that works. I am getting a list of modtimes using List Comprehension, from a list of modules, which will be compared to an older list to see if mod_wsgi needs to be restarted. Maybe thee is an easy way to get the modtimes, I'd be

Re: Get named module's file location

2011-12-23 Thread Gnarlodious
I am rolling my own, and learning Python at the same time. One more question. Say I want to assemble a list of tuples like this: modules = ['wsgiref', 'http'] import imp [(imp.find_module(module)[1], os.path.getmtime(imp.find_module(module)[1])) for module in modules] Can I in some way assign

Transform two tuples item by item

2011-12-19 Thread Gnarlodious
What is the best way to operate on a tuple of values transforming them against a tuple of operations? Result can be a list or tuple: tup=(35, '34', 0, 1, 31, 0, '#26082;#28639;') from cgi import escape [tup[0], span class='H'{}/span.format(tup[1]), bool(tup[2]), bool(tup[3]), tup[4],

Re: Transform two tuples item by item

2011-12-19 Thread Gnarlodious
Wow, that is so elegant. Python is awesome. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Referencing module.instance

2011-12-03 Thread Gnarlodious
HA! After much experimenting I hit upon getattr(__import__(page), page): for page in self.allowedPages: scriptPath = '{}/{}.py'.format(os.path.dirname(__file__), page) if os.path.exists(scriptPath): self.modules[page] = getattr(__import__(page), page) Then in __call_ I just say:

Referencing module.instance

2011-12-02 Thread Gnarlodious
What I am doing is importing modules that have an identical instance name. So I say: import Grid Grid has its instance: Grid.Grid() and this is the same for all modules of my webapp. allowedPages is a list of modules to import, so they are quoted strings: for page in self.allowedPages:

Re: Referencing module.instance

2011-12-02 Thread Gnarlodious
To explain my reasoning, this scheme will allow me to run the script three ways, as shell, as one-shot CGI or as a persistent mod_wsgi module. So to be more exhaustive: In __init__ I can say: import Grid self.Grid = Grid.Grid self.Grid is now the instance of Grid inside the module Grid. then

Re: Python 2 or 3

2011-12-02 Thread Gnarlodious
If you are writing your own scripts, I would recommend Py3 for learning. But if you are studying existing scripts to learn, Py2 might be better. I have been doing Python for about 2 years and started learning Py3 with no regrets. Py2 is not going to be obsolete for quite a while. It is almost

Re: Help catching error message

2011-11-08 Thread Gnarlodious
On Nov 8, 3:16 pm, Steven D'Aprano wrote: content = Data.Dict.SaveEvents(Data.Plist.Events) or content This will leave content unchanged if no error is returned, otherwise it will replace the value. Ah, the 'or' operator does it. Thank you, that is exactly what I was looking for. I should

Help catching error message

2011-11-08 Thread Gnarlodious
What I say is this: def SaveEvents(self,events): try: plistlib.writePlist(events, self.path+'/Data/Events.plist') # None if OK except IOError: return IOError: [Errno 13] Apache can't write Events.plist file Note that success returnsNone while failure returns a string. I catch

Assign values from list to list of instances

2011-11-01 Thread Gnarlodious
I want to assign a list of variables: locus=[-2, 21, -10, 2, 12, -11, 0, 3] updating a list of objects each value to its respective instance: for order in range(len(Orders)): Orders[order].locus=locus[order] This works, even though it reads like doggerel. Is there a more pythonesque way

Re: Assign values from list to list of instances

2011-11-01 Thread Gnarlodious
On Nov 1, 3:33 pm, Terry Reedy wrote: for obj, val in zip(Orders, locus): obj.locus = val I'm not sure how worthwhile it is converting the above to a list comprehension (when the list would just be thrown away). Having said that the call to zip creates an unnecessary list. Not in Py

__init__ with multiple list values

2011-10-30 Thread Gnarlodious
Initializing a list of objects with one value: class Order: def __init__(self, ratio): self.ratio=ratio def __call__(self): return self.ratio ratio=[1, 2, 3, 4, 5] Orders=[Order(x) for x in ratio] But now I want to __init__ with 3 values: class Order: def __init__(self, ratio, bias,

Re: __init__ with multiple list values

2011-10-30 Thread Gnarlodious
On Oct 30, 9:15 am, Chris Angelico wrote: Orders=[Order(x,y,z) for x,y,z in zip(ratio, bias, locus)] Brilliant, thanks! -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

How to isolate a constant?

2011-10-22 Thread Gnarlodious
Say this: class tester(): _someList = [0, 1] def __call__(self): someList = self._someList someList += X return someList test = tester() But guess what, every call adds to the variable that I am trying to copy each time: test()

Re: How to isolate a constant?

2011-10-22 Thread Gnarlodious
On Oct 22, 6:41 pm, Chris Rebert c...@rebertia.com wrote: The line `someList = self._someList` does NOT copy the list. It make `someList` point to the same existing list object. Thanks for all those explanations, I've already fixed it with a tuple. Which is more reliable anyway. -- Gnarlie --

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
On Oct 15, 5:53 pm, PoD p...@internode.on.net wrote: data = {     'Mobile': 'string',     'context': 'malicious code',     'order': '7',     'time': 'True'} types={'Mobile':str,'context':str,'order':int,'time':bool} for k,v in data.items():     data[k] = types[k](v) Thanks for the tip,

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
On Oct 16, 5:25 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: How do you sanitize user input? Thanks for your concern. This is what I now have, which merely expands each value into its usable type (unquotes them): # filter each value try: var=int(var) except ValueError:

Re: Loop through a dict changing keys

2011-10-17 Thread Gnarlodious
Steven: Thanks for those tips, I've implemented all of them. Also only allowing whitelisted variable names. Feeling much more confident. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Loop through a dict changing keys

2011-10-15 Thread Gnarlodious
What is the best way (Python 3) to loop through dict keys, examine the string, change them if needed, and save the changes to the same dict? So for input like this: {'Mobile': 'string', 'context': 'malicious code', 'order': '7', 'time': 'True'} I want to booleanize 'True', turn '7' into an

CGI input: Filter dict.update() unwanted variables

2011-08-22 Thread Gnarlodious
In my last post I learned of the necessity of filtering CGI input, so what I want to do is set a dict of allowable variable names: allowedVariables = {'eeny':None, 'meeny':None, 'miny':None, 'mo':None} # Set up a FieldStorage object: import cgi inputVariables = cgi.FieldStorage() for name, value

Re: CGI input: Filter dict.update() unwanted variables

2011-08-22 Thread Gnarlodious
On Aug 22, 9:39 am, Miki Tebeka wrote: HTH Yes it helps, thank you! -- Gnarlie http://Gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list

CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get name2 -

CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get name2 -

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ[QUERY_STRING] = name1=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie --

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ[QUERY_STRING] = name1=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie --

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
On Aug 17, 3:25 am, Chris Angelico wrote: You do NOT want end users having the power to set variables. Thanks for the warning, I can see I will need to quarantine the form input. And update() is out of the question. -- Gnarlie http://Gnarlodious.com/ --

Set run vars with each call

2011-07-12 Thread Gnarlodious
Question. Is there a special method or easy way to set default values with each call to an instance? Any ideas to make it easier? What I want to do is have a constantly updating set of values which can be overridden. Just thought there was an easy way to set that up. -- Gnarlie --

Re: Set run vars with each call

2011-07-12 Thread Gnarlodious
On Jul 12, 8:46 am, Alister Ware wrote: I thought that was the role of the __init__ function class Something:         def __init__(self):                 self.value=some value OK, that sets a value at init time. But is there a similar built-in to run whenever the class instance is called?

Re: Set run vars with each call

2011-07-12 Thread Gnarlodious
On Jul 12, 6:44 pm, Steven D'Aprano wrote: All the words are in English, but the sentences make no sense :) LOL, impressive powers of mind-reading! Exactly what I needed: import time class Event: epoch=time.time() def doSomething(self, epoch=None): if epoch is None:

Extracting property getters from dir() results

2011-07-06 Thread Gnarlodious
Using introspection, is there a way to get a list of property getters? Does this: vars=property(getVars(), Dump a string of variables and values) have some parsable feature that makes it different from other functions? Or would I need to use some naming scheme to parse them out? -- Gnarlie --

Re: Extracting property getters from dir() results

2011-07-06 Thread Gnarlodious
On Jul 6, 3:35 am, Christian Heimes wrote: Thank you! Exactly what I wanted. -- Gnarlie http://Gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Project-wide variable...

2011-06-24 Thread Gnarlodious
On Jun 24, 12:27 am, Terry Reedy wrote: 1) Can I tell Executable.py to share Data with ModuleTest.py? After the import is complete, yes. import ModuleTest ModuleTest.Data = Data This works if the use of Data is inside a function that is not called during import, not if the use of Data is

Project-wide variable...

2011-06-23 Thread Gnarlodious
Is there a way to declare a project-wide variable and use that in all downstream modules? -- Gnarlir -- http://mail.python.org/mailman/listinfo/python-list

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 7:59 am, Noah Hall wrote: from a import x I'm doing that: import Module.Data as Data However I end up doing it in every submodule, so it seems a little redundant. I wish I could load the variable in the parent program and have it be available in all submodules. Am I missing

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 8:42 am, Peter Otten wrote: from Module import Data There, you saved three more characters . OK I get it, LOL. But I don't think it's a good idea. Remember that explicit is better than implicit. Thanks, now I know what that means. -- Gnarlie --

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 11:42 am, Noah Hall wrote: What about using an environment variable? Yes, that's fine, but only if the data is suitable for it. In this case, the variable is a namespace containing the property of a folder full of plist files. I access any dictionary item anywhere in my webapp

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
On Jun 23, 12:10 pm, Terry Reedy wrote: from test import ftest,itest def test_main(): if __name__ == '__main__':      test_main() I don't understand this. Can you explain, or refer me to some documentation? -- Gnarlie http://Gnarlodious.com --

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
Let me restate my question. Say I have a script Executable.py that calls all other scripts and controls them: #!/usr/local/bin/python from Module import Data import ModuleTest ModuleTest.py has this: print(Data.Plist.Structure) Running Executable.py gives me this: NameError: name 'Data' is not

Re: Project-wide variable...

2011-06-23 Thread Gnarlodious
Idea: It occurs to me that my application class inherits object. Can I set that to inherit an object that already includes data? So every subsequent class would start off with data loaded (except for class Data). Seems like it should already be invented. -- Gnarlie --

Boolean result of divmod

2011-06-20 Thread Gnarlodious
What is the easiest way to get the first number as boolean? divmod(99.6, 30.1) Or do I have to say: flote, rem=divmod(99.6, 30.1) bool(flote) -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Run Python script from JS

2011-06-16 Thread Gnarlodious
Is there any way to call a Py script from Javascript in a webpage? I don't have to tell you how messy JS is… -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

CGI: remove variable from Tuple Object query

2011-06-05 Thread Gnarlodious
Say I send a request like this: http://0.0.0.0/Sectrum/Gnomon?see=Gnomonorder=7epoch=1303541219 This makes for a CGIform of the CGI Tuple Object type: FieldStorage(None, None, [MiniFieldStorage('see', 'Gnomon'), MiniFieldStorage('order', '7'), MiniFieldStorage('epoch', '1303541219.58')]) So the

Unescaping formatted Terminal text

2011-06-03 Thread Gnarlodious
characters from output for CGI rendering? -- Gnarlodious -- http://mail.python.org/mailman/listinfo/python-list

Re: Unescaping formatted Terminal text

2011-06-03 Thread Gnarlodious
Thanks, it looks like the appropriate incantation is: import pydoc pydoc.html.docmodule(sys.modules[__name__]) -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Updated now can't scroll uparrow

2011-06-02 Thread Gnarlodious
After copious headscratching I took Ned's advice and went for 3.2 which includes built-in interactive arrow key support. To any Mac OSX readers, save yourself the trouble and don't even try Python 3.1.3. -- Gnarlie http://Gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list

Updated now can't scroll uparrow

2011-06-01 Thread Gnarlodious
I updated Python to 3.1.3 on Mac OSX. Now suddenly in the Interactive interpreter I get all this instead of scrolling the history: ^[[A^[[A^[[A What's wrong and how to fix it? -- Gnarlie http://Gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Updated now can't scroll uparrow

2011-06-01 Thread Gnarlodious
Like so: ./configure MACOSX_DEPLOYMENT_TARGET=10.6 \ --enable-framework=/usr/local/python-3.1/frameworks \ --prefix=/usr/local/python-3.1 \ --enable-universalsdk=/ \ --with-universal-archs=intel Is there some directive to enable Readline? -- Gnarlie http://Gnarlodious.com --

TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Gnarlodious
Can someone please explain what I am doing wrong? Calling script: from Gnomon import GnomonBase Gnomon=GnomonBase(3) Called script: class GnomonBase(object): def __init__(self, bench): # do stuff But all I get is: TypeError: __init__() takes exactly 1 positional argument (2

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Gnarlodious
I don't have a trace because I am using mod_wsgi under Apache. Maybe there is a way to debug using mod_wsgi but I haven't been able to figure out how. My problem is that in order to run mod_wsgi I had to downgrade to Python 3.1.3 which may be causing the problem. This website was running fine in

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Gnarlodious
Well, I have a whole lot of scripts where I could say something like this: def __init__(self, var1, var2, var3...): Now suddenly I have to change them all to run in Python 3.1.3? This is apparently not a bug. And I rebooted still getting the same behavior. Can someone explain it? -- Gnarlie

Re: TypeError: __init__() takes exactly 1 positional argument (2 given)

2011-05-15 Thread Gnarlodious
Thanks for all the help, this looks like a bug in mod_wsgi. I tried it interactively under Py3.1.3 and it behaves normally. I'll take this over to the mod_wsgi group. -- Gnarlie http://Gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list

Py 3.2: sqlite can't operate on a closed cursor

2011-05-07 Thread Gnarlodious
I installed Python 3.2, suddenly getting an error on my sqlite pages (CGI): ProgrammingError: Cannot operate on a closed cursor Works normally in interactive mode. Seems to error when the sqlite statement is in a function. Are sqlite objects now required to be declared global? -- Gnarlie --

Re: Py 3.2: sqlite can't operate on a closed cursor

2011-05-07 Thread Gnarlodious
It turns out Python 3.2 now honors closing sqlite connections opened in another module. Previous versions allowed you to have identically named sqlite connections open in other modules. Python 3.2 apparently treats them all as the same connection. Hopefully some other victim will find this,

Need to solve the Stateless HTTP problem

2011-05-05 Thread Gnarlodious
My scripting has grown to the point where the Apache server is a problem. My Python websites run and quit, which means I need to save data and recreate everything next page load. Bulky and slow. What is the simplest solution? I am running Py3 on OSX Server with Apache 2. Essentially I want

Re: De-tupleizing a list

2011-04-26 Thread Gnarlodious
On Apr 25, 10:59 pm, Steven D'Aprano wrote: In Python 3, map becomes lazy and returns an iterator instead of a list, so you have to wrap it in a call to list(). Ah, thanks for that tip. Also works for outputting a tuple: list_of_tuples=[('0A',), ('1B',), ('2C',), ('3D',)] #WRONG: (x for (x,)

De-tupleizing a list

2011-04-25 Thread Gnarlodious
I have an SQLite query that returns a list of tuples: [('0A',), ('1B',), ('2C',), ('3D',),... What is the most Pythonic way to loop through the list returning a list like this?: ['0A', '1B', '2C', '3D',... -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: De-tupleizing a list

2011-04-25 Thread Gnarlodious
On Apr 25, 9:42 pm, CM wrote: flat_list = [item[0] for item in returned_list] HA! So easy. Thanks. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: renaming files in OS X

2011-04-20 Thread Gnarlodious
Not a Python question. You should go over to http://groups.google.com/group/comp.sys.mac.system/ and ask. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: is python 3 better than python 2?

2011-04-05 Thread Gnarlodious
On Apr 5, 6:42 am, neil neilharper300...@gmail.com wrote: what are the advantages? if it wasn't for python 3 breaking backwards compatibility would it be the better choice? I adopted Py3 because of support of OrderedDict and many new features. Since mine was a new project using no existing

Get subprocess error output from shell command

2011-04-02 Thread Gnarlodious
I'm running a shell command like: plutil -convert xml1 ~/Library/Preferences/iCab/iCab 4 Bookmarks Getting error: ~/Library/Preferences/iCab/iCab 4 Bookmarks: Permission denied How would I capture this error using a method of subprocess? I read the doc at

Re: Get subprocess error output from shell command

2011-04-02 Thread Gnarlodious
OK I get it, and that seems like it should work. But when I simulate a permissions error by setting the file to unwritable I get an error: outdata, errdata = process.communicate() Traceback (most recent call last): File stdin, line 1, in module File

Re: Get subprocess error output from shell command

2011-04-02 Thread Gnarlodious
I get it, you instantiate an object, call a method and get a tuple in response. However, here is what I see: process.communicate() (b'~/Library/Preferences/iCab/iCab 4 Bookmarks: Permission denied\n', b'') So all I get is the string and no error message, which is the same thing I get with the

Re: Get subprocess error output from shell command

2011-04-02 Thread Gnarlodious
On Apr 2, 9:29 pm, Chris Rebert wrote: if proc.returncode: # non-zero exit status, indicating error     print(Encountered error:)     print(error_output) # output the error message Like in my previous post, this only outputs an empty string. Apparently plutil doesn't communicate well. --

Sudden error: SyntaxError: Non-ASCII character '\xc2' in file

2011-03-30 Thread Gnarlodious
RSS script runs fine on my dev machine but errors on the server machine. Script was last run 3 days ago with no problem. Possible clue: dev machine is (Mac OSX) running Python 3.1.1 while server is running Python 3.1.3. I have not updated anything that should suddenly cause this error starting

Re: Sudden error: SyntaxError: Non-ASCII character '\xc2' in file

2011-03-30 Thread Gnarlodious
On Mar 30, 9:28 am, Peter Otten wrote: You are trying to run your 3.x code with Python 2.x... You're right. Exactly why this started happening I don't know. Thanks. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Various behaviors of doctest

2011-03-02 Thread Gnarlodious
On Feb 28, Peter Otten wrote: Are you using Python 2.x? Then you cannot redefine print. Instead you have to redirect stdout. The following example should run as a cgi script: #!/usr/bin/env python import cgi import sys from cStringIO import StringIO ... That works! Except for Py3 I had to

Various behaviors of doctest

2011-02-27 Thread Gnarlodious
Using the doctest module, I get three different outputs: 1) From the Terminal shell, I see a full report: python ~/Sites/Sectrum/Filter.py -v 2) From the Terminal interactive session, I see an abbreviated report of only the failures: from doctest import testmod; testmod(Filter) 3) From a

Re: Various behaviors of doctest

2011-02-27 Thread Gnarlodious
Yeah, I just spent about 2 hours trying everything I could think of... without success. Including your suggestions. Guess I'll have to skip it. But thanks for the ideas. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Print docstrings to shell

2011-02-01 Thread Gnarlodious
Can I run a script in bash and print out its docstrings to the bash shell? I tried this at the end: print(help(__file__)) Runnig the script: python ~/Sites/Sectrum/Harmonics.py but all it spit out was: no Python documentation found for '~/Sites/Sectrum/Harmonics.py' However in the interactive

Re: Print docstrings to shell

2011-02-01 Thread Gnarlodious
On Feb 1, 5:30 pm, André Roberge andre.robe...@gmail.com wrote: test.py== import pydoc '''this is a test''' class A(object):         '''docstring'''         pass print(pydoc.help(__file__[:-3])) = python test.py OK that works, but only if I cd into the

Re: Print docstrings to shell

2011-02-01 Thread Gnarlodious
Thank you for the help, I learned a few things. The André solution renders the colors but needs q-q to quit. The Carl solution 1 prints colors and requires q to quit. The Carl solution 2 prints colorlessly, it looks good for exporting to a file. Everything I need. -- Gnarlie

Print recent CGI error

2010-12-04 Thread Gnarlodious
I have a serious error that causes the process to crash. Apache refuses to log the error and it only happens on the server, not on the dev machine. Problem is, I can't figure out how to get the most recent error. I can find all sorts of pages telling how to print a specific error, but how to get

Re: Print recent CGI error

2010-12-04 Thread Gnarlodious
What you posted doesn't work, I don't know why. All I get is a blank page and no Apache error report. There are two problems with this. I am really trying to figure out how to trap an error on the server without exposing my innards to the world, which import cgitb; cgitb.enable() does. The other

Re: Which non SQL Database ?

2010-12-04 Thread Gnarlodious
I use sqlite3, it is fairly simple, fast and not too strict. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Print recent CGI error

2010-12-04 Thread Gnarlodious
After many curse words I figured it out. A two-stage filter was needed. The 5th line solves the problem of colliding domain cookies: NowCookie=http.cookies.SimpleCookie() # Instantiate a SimpleCookie object savedCookie=os.environ.get('HTTP_COOKIE') # get the cookie string if savedCookie: #

Re: Change one list item in place

2010-12-01 Thread Gnarlodious
On Dec 1, 6:23 am, Jean-Michel Pichavant jeanmic...@sequans.com wrote: what about def query():     return [Formating only {0} into a string.format(sendList()[0])] + sendList()[1:] However this solution calls sendList() twice, which is too processor intensive. Thanks for all the ideas, I've

Change one list item in place

2010-11-30 Thread Gnarlodious
This works for me: def sendList(): return [item0, item1] def query(): l=sendList() return [Formatting only {0} into a string.format(l[0]), l[1]] query() However, is there a way to bypass the l=sendList() and change one list item in-place? Possibly a list comprehension operating

Re: Programming games in historical linguistics with Python

2010-11-30 Thread Gnarlodious
Have you considered entering all this data into an SQLite database? You could do fast searches based on any features you deem relevant to the phoneme. Using an SQLite editor application you can get started building a database right away. You can add columns as you get the inspiration, along with

Re: Change one list item in place

2010-11-30 Thread Gnarlodious
Thanks. Unless someone has a simpler solution, I'll stick with 2 lines. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.1.3

2010-11-28 Thread Gnarlodious
Don't know why, but in Terminal the uparrow now gives me: ^[[A which means I no longer have history scrolling. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.1.3

2010-11-28 Thread Gnarlodious
Ah yes, sorry. This is Mac OSX 10.6.5, I did it build from the file at http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tgz -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.1.3

2010-11-28 Thread Gnarlodious
Well I don't know what a readline is, but I upgraded from 3.1.1 and it was working fine. I might also add that the downarrow is also broken: ^[[B -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: CGI FieldStorage instances?

2010-11-24 Thread Gnarlodious
On Nov 23, 7:22 pm, Ian Kelly wrote: Try Django[1] or TurboGears[2]. [1]http://www.djangoproject.com/ [2]http://www.turbogears.org/ Thanks, never understood what those programs were for. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: CGI FieldStorage instances?

2010-11-23 Thread Gnarlodious
On Nov 22, 11:32 pm, Dennis Lee Bieber wrote:         Or upgrade to some modernistic framework wherein the application is a monolithic program and the name/ portion maps to methods/functions within the application... Yes, that describes what I am looking for! Is there such a modernistic

Re: CGI FieldStorage instances?

2010-11-22 Thread Gnarlodious
Let me rephrase the question. Say I have a query string like this: ?view=Dataitem=9875 What I want to do is simply invoke process view with variable Data. This would replace my existing query string mess which looks like this: if 'view' in form and 'item' in form: HTML=view(Data,

CGI FieldStorage instances?

2010-11-20 Thread Gnarlodious
I'm having a hard time understanding this, can someone explain? Running a CGI with query string: ?action=Findpage=Data Script includes these lines: form=cgi.FieldStorage(keep_blank_values=1) print(Content-type:text/html\n\n) print(cgi.print_form(form)) Output: Form Contents: action: class

  1   2   >