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
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
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
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
', '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
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
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
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
'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
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
sends multiline strings and comments as a single token.
##
# python comment and whitespace stripper :)
######
import keyword, os, sys, traceback
i
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
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
Sounds good should work fine ;)
M.E.Farmer
--
http://mail.python.org/mailman/listinfo/python-list
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
##
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
hanges.
>
##
> > # Python source stripper
> >
>
##
> >
> > import os
> > import sys
> > import token
> >
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
...
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
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
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
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
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
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
##
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
> 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
.
Michele Simionato wrote:
> > M.E.Farmer:
>
> >Your answer lies somewhere in this page ;)
> >http://www.python.org/2.2.2/descrintro.html
>
> Yes, when it refers to
>
> http://www.python.org/2.3/mro.html
>
> (section Bad Method Resolution
Awesome! works perfectly on win2k -> I.E 6
Python makes COM almost readable ;)
M.E.Farmer
--
http://mail.python.org/mailman/listinfo/python-list
amp;lr=')
webbrowser('http://python.org')
#####
M.E.Farmer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
'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
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.
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
(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
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
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
.
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
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
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
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
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
etting
overloaded.
M.E.Farmer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
101 - 164 of 164 matches
Mail list logo