Re: Parsing a search string

2004-12-31 Thread M.E.Farmer
token() File ".\shlex.py", line 100, in read_token nextchar = self.instream.read(1) AttributeError: 'str' object has no attribute 'read' M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a dictionary?

2005-03-21 Thread M.E.Farmer
This comes up so often on this list that there are many examples and recipes. You are looking for a dictionary sort by value. search strategy: Python sorting dictionary 44,000+ hits on google. First entry: http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52306 hth, M.E.Farmer -- http

Re: Please help for Python programming

2005-03-22 Thread M.E.Farmer
ot;--out"]: output = a if o in ["-i", "--input", "--in"]: input = a if input in [".", "cwd"]: input = os.getcwd() Notice the 'fixed font / proportional font' link in the top r

Re: Please help for Python programming

2005-03-22 Thread M.E.Farmer
ult, so no need to click it. Proportional still retains spaces but is less tidy. M.E.Farmer >> Terry, >> This was posted from google groups, can you see the indents? >Yes, looks good >> # code snippet >>convertpage = 0 >>form = None >>f

Re: left padding zeroes on a string...

2005-03-25 Thread M.E.Farmer
', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] Py> help(''.zfill) Help on built-in function zfill: zfill(...) S.zfill(width) -> string Pad a numeric string S with zeros on the left, to fill a field of the specified width. The string S is never truncated. Hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Need Help: Server to pass py objects

2005-03-29 Thread M.E.Farmer
jects hth, M.E.Farmer Sells, Fred wrote: > I have a legacy system with data stored in binary files on a remote server. > I need to access and modify the content of those files from a webserver > running on a different host. (All Linux) > > I would like to install a server on the l

Re: Controling the ALU

2005-03-31 Thread M.E.Farmer
h more content and detail. Py> you = 'Cesar Andres Roldan Garcia' Py> answer = PyAnswers(you) Py> print answer For further help please repost answer or the error message ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Search-and-delete text processing problem...

2005-04-01 Thread M.E.Farmer
Lines = theInFile.readlines() theInFile.close() outLines = [] for line in allLines: if not line.startswith('Bill'): outLines.append(line) theOutFile.writelines(outLines) theOutFile.close() # hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Search-and-delete text processing problem...

2005-04-01 Thread M.E.Farmer
'abc\n'] Notice that it does not modify the list in any way. You are trying to loop thru the list and modify the items in place, it just won't work. When you rebind the item name to a new value ' ' it does not rebind the element in the list just the current item. It is also

Re: Docorator Disected

2005-04-02 Thread M.E.Farmer
to be a nested function, it really depends on what you are trying to achieve. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

whitespace , comment stripper, and EOL converter

2005-04-13 Thread M.E.Farmer
sends multiline strings and comments as a single token. ## # python comment and whitespace stripper :) ###### import keyword, os, sys, traceback i

Re: Compute pi to base 12 using Python?

2005-04-14 Thread M.E.Farmer
t believe GNU "bc" is available for Windows, is it? > > Thanks, > > Dick Moores > [EMAIL PROTECTED] Nice collection of unix tools, Cygwin not needed. http://unxutils.sourceforge.net/ hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Pyrex colorizer please review

2005-04-15 Thread M.E.Farmer
tokens missing that should be added, or extra tokens that should be removed please comment. If all is well I will post the updated PySourceColor module and PyrexColor script to my website for download. http://bellsouthpwp.net/m/e/mefjr75/python/PyrexTest_XHTML2.htm M.E.Farmer -- http

Re: Compute pi to base 12 using Python?

2005-04-15 Thread M.E.Farmer
Sounds good should work fine ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: whitespace , comment stripper, and EOL converter

2005-04-16 Thread M.E.Farmer
method so tokenize sends really sends the five part info to __call__ for every token. If this was obvious then ignore it ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: whitespace , comment stripper, and EOL converter

2005-04-16 Thread M.E.Farmer
## import os import sys import token import keyword import StringIO import tokenize import traceback __credits__ = ''' Jürgen Hermann M.E.Farmer Jean Brouwers ''' __version__ = '.8' __author__ = 'M.E.Farmer' __date__ = 'Apr 1

Re: whitespace , comment stripper, and EOL converter

2005-04-17 Thread M.E.Farmer
hanges. > ## > > # Python source stripper > > > ## > > > > import os > > import sys > > import token > >

Re: whitespace , comment stripper, and EOL converter

2005-04-17 Thread M.E.Farmer
Google has now 'fixed' there whitespace issue and now has an auto-quote issue argggh! The script is located at: http://bellsouthpwp.net/m/e/mefjr75/python/stripper.py M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: whitespace , comment stripper, and EOL converter

2005-04-17 Thread M.E.Farmer
... Updates available at > The script is located at: > http://bellsouthpwp.net/m/e/mefjr75/python/stripper.py > > M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding name of running script

2005-04-17 Thread M.E.Farmer
ys import argv > > print argv[0].split(sep)[-1] > # or > print locals()['__file__'].split(sep)[-1] > # or > print globals()['__file__'].split(sep)[-1] M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding name of running script

2005-04-17 Thread M.E.Farmer
I have the feeling that I came a cross some very simple way to extract > the filename, but I can't find my mental note ;-) Maybe you found some black magic ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Compute pi to base 12 using Python?

2005-04-17 Thread M.E.Farmer
in.isatty(): "direct" else: "redirected" This snippet can determine if you have redirected IO. I just found this and it looks informative. http://www.jpsdomain.org/windows/redirection.html hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie question

2005-04-19 Thread M.E.Farmer
uses Python for it's scripting. You can create a game and never touch a piece of code if you use the builtin actuators and sensors, or you can script with Python. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Python instances

2005-04-20 Thread M.E.Farmer
e names are not shared. Also this next bit can bite you. Don't use list it is builtin name and can cause problems when you rebind it. Others to avoid are keywords and file, dict, tuple, object, etc... They can be tempting to use, resist, it will save you debug time later. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: whitespace , comment stripper, and EOL converter

2005-04-22 Thread M.E.Farmer
## u'People do this sometime for a block comment type of thing' \ r"This type of string should be removed also" \ """ and this one too! """ # did I forget anything obvious ? # When the docstring is removed it should also consume the blank line that is left behind. Got to go to work, I'll think about it over the weekend. If anyone else wants to play you are welcome to join. Can pyparsing do this easily?( Paul probably has a 'six-line' solution tucked away somewhere ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: PDF Printing support from Python

2005-04-23 Thread M.E.Farmer
> You're use of the word "driver" is one with which I'm not > familiar. But I don't really "do windows" so it's probably a > Widnowism. It is a windowism but not exclusively ;). http://www.collaborium.org/onsite/romania/UTILS/Printing-HOWTO/winprinters.html This is the first link I found that men

Re: Pickle an image?

2005-04-25 Thread M.E.Farmer
t; im = Image.open(c) >>> im.show() Alternatively you can create a StringIO object and pickle that in your dictionary so you can just load it later with PIL. Pickling will bloat the size of your file so you might want to use some compression, although most formats will compress very little the pickling overhead can __mostly__ be avoided. There are boundless ways to do this and this just one of them. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: about Frame.__init__(self)

2005-04-27 Thread M.E.Farmer
def __init__(self): """Python calls me if I am defined""" base.__init__(self) You will see this in more than GUI code, it is part of Python's OO design. I first saw this in some threading code , thru me for a loop too ;) search strategy: Python OO Python i

Re: names of methods, exported functions

2005-04-27 Thread M.E.Farmer
se? > > I think we don't need the mro, or any of the magic methods inherited > from the builtin. > -- > Michael Hoffman The help code is part of pydoc, IIRC, feel free to have a go at it ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: names of methods, exported functions

2005-04-27 Thread M.E.Farmer
Appears that most of the relevant code is in the Helper and TextDoc classes of pydoc also might need the doc() function. My head hurts every time I stare at the internals of pydoc ;) I guess it is time for a lunch break. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to write CGI script with python...

2005-04-29 Thread M.E.Farmer
Just in case you don't have a clue what they are talking about ;) import traceback try: #your stuff here except: traceback.print_exc() That should return any exceptions you may be throwing. -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to write CGI script with python...

2005-04-29 Thread M.E.Farmer
I found an excellent example that was posted by the F-bot. Fredrik Lundh May 26 2000 From: "Fredrik Lundh" <[EMAIL PROTECTED]> Date: 2000/05/26 richard_chamberl...@ wrote: > I'm having great difficulties getting Python to work via CGI. > Is there anyway I can get the traceback on to the web p

Re: Micro-PEP: str.translate(None) to mean identity translation

2005-04-29 Thread M.E.Farmer
What's wrong with : s = s.replace('badchars', "") It seems obvious to replace a char ( to me anyway ) with a blank string, rather than to 'translate' it to None. I am sure you have a reason what am I missing ? M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: interactive web graphics

2005-04-30 Thread M.E.Farmer
eventually be revamped when the 'new' game engine is stable. Until then you might be able to use the old one but I have had many problems getting it to work reliably on Firefox or Mozilla, it works well with I.E. but Have fun and experiment. M.E.Farmer -- http://mail.python.o

Re: Micro-PEP: str.translate(None) to mean identity translation

2005-04-30 Thread M.E.Farmer
er ! For what it is worth +1 ;) On another note why is maketrans in the string module I was a bit lost finding it the first time should it be builtin? transtable = "abcdefg".maketrans("qwertyu") Probably missing something. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: compare two voices

2005-05-01 Thread M.E.Farmer
l signals. """ Be sure to check out the examples. Might be worth a look: http://www.speech.kth.se/projects/speech_projects.html http://www.speech.kth.se/cost250/ You might also have luck with Windows using Microsoft Speech SDK ( it is huge ). Combined with Python scrtiptng you can go far

Re: Webbrowser On Windows

2005-05-01 Thread M.E.Farmer
t open a new window. Have not looked into it but you can probably do this easily with win32api . Search MSDN and then translate that into win32api for Python. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple threads in a GUI app (wxPython), communication between worker thread and app?

2005-05-01 Thread M.E.Farmer
Look inthe demo that comes with wxPython it is in tree process and events -> threads . There is a nice demo of PostEvent(). Another way would be to use Queues as others have mention . You can create a new frame and have it call the queue for data. M.E.Farmer -- http://mail.python.org/mail

Re: sys.stdout question

2005-05-01 Thread M.E.Farmer
bsequent expressions are printed to this file object. If the first expression evaluates to None, then sys.stdout is used as the file for output. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: MRO problems with diamond inheritance?

2005-05-01 Thread M.E.Farmer
Your answer lies somewhere in this page ;) http://www.python.org/2.2.2/descrintro.html M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: MRO problems with diamond inheritance?

2005-05-01 Thread M.E.Farmer
. Michele Simionato wrote: > > M.E.Farmer: > > >Your answer lies somewhere in this page ;) > >http://www.python.org/2.2.2/de­scrintro.html > > Yes, when it refers to > > http://www.python.org/2.3/mro.html > > (section Bad Method Resolution

Re: Webbrowser On Windows

2005-05-01 Thread M.E.Farmer
Awesome! works perfectly on win2k -> I.E 6 Python makes COM almost readable ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Webbrowser On Windows

2005-05-01 Thread M.E.Farmer
amp;lr=') webbrowser('http://python.org') ##### M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: MRO problems with diamond inheritance?

2005-05-02 Thread M.E.Farmer
oved from the language; a part for that consideration, > the typical > use for classmethods is as object factories, to provide alternative > constructors. > >Michele Simionato Thank you, I had a feeling that it was just extra fluff. But I felt/feel that way about list comprehensions and decorators too ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: MRO problems with diamond inheritance?

2005-05-02 Thread M.E.Farmer
No book just these lectures that cover everything you want ' I knew I was asking the right person ;) Now I just need to read your lectures...but first I am going to wrap my head in duct tape. ( prevents/contains explosions ) Thanks for your time, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get compression in Python zip script.

2005-05-02 Thread M.E.Farmer
n overwrite the original. You can have mulitple files with the same name! Obviusly that can cause problems. This can be very confusing. hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get compression in Python zip script.

2005-05-02 Thread M.E.Farmer
ot;C:\Python22\Lib\zipfile.py", line 169, in __init__ raise RuntimeError, "That compression method is not supported" RuntimeError: That compression method is not supported >>> a = zipfile.ZipFile('c:\tmp\z.zip', 'w', compression=8) I saw compression=0 and assumed that 1 would mean true, but no! zipfile.ZIP_DEFLATED = 8, defies logic, it is the only compression type why not accept any non zero as compression. Got any answers to the problems I outlined or have they been fixed yet ? M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get compression in Python zip script.

2005-05-02 Thread M.E.Farmer
Thank you! """ZIP_DEFLATED The numeric constant for the usual ZIP compression method. This requires the zlib module. No other compression methods are currently supported.""" That is where I got the 'only compression type'. It all makes sense

Re: sys.stdout question

2005-05-02 Thread M.E.Farmer
ring.','\n'] It would be hard to get to the next prompt after a print "dsfdfdssd", if the shell didn't add the \n to get it there. Also note most shells use repr or str behind the scenes for output to sys.stdout sys.stderr. >>> def g(): ... pass ... &g

Re: Can't get compression in Python zip script.

2005-05-02 Thread M.E.Farmer
't logical till you see the full issue. In plain english: I couldn't refuse the temptation to guess( and guessed wrong ). +1 on the bzip2 Thanks, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: Mouseclick

2005-05-02 Thread M.E.Farmer
This could be fun! # random clicks # play with values to maximize annoyance if __name__ == "__main__": import random for i in range(1000): x = random.randint(0,800) y = random.randint(0,600) Click(x,y) time.sleep(random.randint(0,20)) -- http://mail.python.

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
abc(x,y,0,0,0) > print 'Calling function abc' > print 'Array X:',abcinfo[0] > print 'Array Y:',abcinfo[1] > print 'Dot Product of X and Y:',abcinfo[2] > print 'Sum of array X:',abcinfo[3] > print 'Max value of array Y:',abcinfo[4] Or you could use a dictionary, or etc... The possibilities are endless. Be sure to study up on namespaces, it will ease your Python woes. Namespaces are the most fundamental part of Python that new users don't understand. Namespace mastery will take you far. Just remember there are only two scopes local and global ;) http://docs.python.org hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
(x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv) This will only create a tuple in memory that has no name to reference it by! How would you access the returned value? If you want a tuple you need to assign all the return vales to a single name. mytup = abc(x,y,dotp,sumx,maxv) M.E.Farmer -- http

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
ltins__', '__doc__', '__name__', 'a', 'b', 'c', 'd', 'f', 'shell'] >>> del a,b,c,d >>> # Where is the tuple (a,s,d,f)? There isn't one. >>> # assign to a single name ( don't do tuple

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
27;__name__', 'a', 'b', 'c', 'd', 'f', 'shell'] >>> del a,b,c,d >>> # Where is the tuple (a,b,c,d)? There isn't one. >>> # assign to a single name ( don't do tuple unpacking ) >>> tup=f(1,2,3,4) >>> dir() ['__builtins__', '__doc__', '__name__', 'f', 'shell', 'tup'] Now there is. Steve since you are closer to expert than novice you understand the difference. I feel this can be confusing to newbies, maybe you disagree. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
. The problem is why should this be the same: a,b,c=(1,2,3) (a,b,c)=(1,2,3) Seems weird, non-intuitive that a tuple unpacking and tuple creation have the same bytecode. So why is this done? What is the reason, I am sure there are a few ;) p.s. I am leaving out for a while and will read/followup later if needed. Thank you all for your time. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
es sense >>> w = 1,2,3 >>> w.__doc__ """tuple() -> an empty tuple tuple(sequence) -> tuple initialized from sequence's items If the argument is a tuple, the return value is the same object.""" Thanks for your time Bengt! M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-14 Thread M.E.Farmer
I think they that should be avoided for clarity. Steve thanks for your time. I always learn a little from you ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: incorrect(?) shlex behaviour

2005-05-14 Thread M.E.Farmer
t; sh.get_token() etc... Python 2.2 and maybe lower: >>> import shlex >>> import StringIO >>> s = StringIO.StringIO('$(which sh)') >>> sh = shlex.shlex(s) >>> sh.get_token() '$' >>> sh.get_token() '(' >>> sh.get_token() 'which' >>> sh.get_token() 'sh' >>> sh.get_token() ')' >>> sh.get_token() etc... Hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: incorrect(?) shlex behaviour

2005-05-15 Thread M.E.Farmer
s is not ordinarily a useful entry point, and is documented here only for the sake of completeness.) # Just like in my first post >>> from StringIO import StringIO >>> from shlex import shlex >>> t = shlex(StringIO("2>&1")) >>> t.get_token() '2' >>> t.get_token() '>' >>> t.get_token() '&' >>> t.get_token() '1' >>> t.get_token() '' # Your way >>> t = shlex(StringIO("2>&1")) >>> t.read_token() '2' >>> t.read_token() '&' >>> t.read_token() '1' >>> t.read_token() '' >>> Hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-15 Thread M.E.Farmer
etting overloaded. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-15 Thread M.E.Farmer
Fredrik and Bengt: Thank you for the time. I will study the docs and play with the shell till this is firm. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: A new to Python question

2005-05-15 Thread M.E.Farmer
It looks like the docs could use some examples of the various assignments it refers to. I think something like Bengt posted would be a nice addition if it included assignments with slices and dicts too. Just a thought. M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: string.lstrip stripping too much?

2005-05-16 Thread M.E.Farmer
q ('D:\\music\\D', 'Daniel Lanois') >>> q = os.path.split(q[0]) >>> q ('D:\\music', 'D') And another idea might be to do a split using os.sep: >>> import os >>> d = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> d.split(os.sep) ['D:', 'music', 'D', 'Daniel Lanois', 'For the beauty of Wynona'] Hth, M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

<    1   2