Rhamphoryncus wrote:
I've run into this problem a few times, and although many solutions
have been presented specifically for printing I would like to present a
more general alternative.
[snip interesting istep function]
Would anybody else find this useful? Maybe worth adding it to
OriginalBrownster wrote:
i want this because using python I am pulling in filenames from a
mac..thus they are / in the pathways..and i want to .split it at the
/ to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.
sounds like you want
import posixpath
Alistair King wrote:
Hei all,
im trying to create a list of variables for further use:
[snip]
this works to a certain extent but gets stuck on some loop. Im a
beginner and am not sure where im going wrong.
You are trying to do too much in one function. Split those loops up
into a few little
[EMAIL PROTECTED] wrote:
I've narrowed down the problem. All the problems start when I try to
eliminate the hidden files and directories. Is there a better way to
do this?
Well you almost have it, but your problem is that you are trying to do
too many things in one function. (I bet I am
[EMAIL PROTECTED] wrote:
I do appreciate the advice, but I've got a 12 line function that does
all of that. And it works! I just wish I understood a particular line
of it.
You miss the point. The functions I posted, up until get_files_by_ext
which is the equivalent of your getFileList,
Petr Jake wrote:
I have a standard 12-key mobile phone keypad connected to my Linux
machine as a I2C peripheral. I would like to write a code which allows
the text entry to the computer using this keypad (something like T9 on
the mobile phones)
According to the
danielx wrote:
I'm surprised no one has mentioned neat-er, more pythonic ways of doing
this. I'm also surprised no one mentioned regular expressions. Regular
expressions are really powerful for searching and manipulating text.
[snip]
I'm surprised you don't count my post as a neat and pythonic
Jim wrote:
Could somebody tell me why I need the elif char == '\n' in the
following code?
This is required in order the pick up lines with just spaces in them.
Why doesn't
the else: statement pick this up?
No idea. Look at the profile of your program: for.. if.. for.. if..
else.. if.. This
[EMAIL PROTECTED] wrote:
Im trying to iterate through values in a dictionary so i can find the
closest value and then extract the key for that valuewhat ive done so far:
[snip]
short time. I was trying to define a function (its my first!) so that i
could apply to several 'dictionary's and
Ritesh Raj Sarraf wrote:
I'd like to put my understanding over here and would be happy if people can
correct me at places.
ok :-)
So here it goes:
Firstly the code initializes the number of threads. Then it moves on to
initializing requestQueue() and responseQueue().
Then it moves on to
Ritesh Raj Sarraf wrote:
[snip]
for item in list_items:
download_from_web(item)
This way, one items is downloaded at a time.
I'm planning to implement threads in my application so that multiple
items can be downloaded concurrently. I want the thread option to be
user-defined.
[snip]
faulkner wrote:
er,
...|\[[^\]]*\]|...
^_^
That's why it is nice to use re.VERBOSE:
def splitup(s):
return re.findall('''
\( [^\)]* \) |
\[ [^\]]* \] |
\S+
''', s, re.VERBOSE)
Much less error prone this way
--
- Justin
--
Paul McGuire wrote:
Comparitive timing of pyparsing vs. re comes in at about 2ms for pyparsing,
vs. 0.13 for re's, so about 15x faster for re's. If psyco is used (and we
skip the first call, which incurs all the compiling overhead), the speed
difference drops to about 7-10x. I did try
Josiah Manson wrote:
I just did some timings, and found that using a list instead of a
string for tok is significantly slower (it takes 1.5x longer). Using a
regex is slightly faster for long strings, and slightly slower for
short ones. So, regex wins in both berevity and speed!
I think the
Bruno Desthuilliers wrote:
Justin Azoff a écrit :
if len(tok) 0:
should be written as
if(tok):
actually, the parenthesis are useless.
yes, that's what happens when you edit something instead of typing it
over from scratch :-)
--
- Justin
--
http://mail.python.org/mailman
[EMAIL PROTECTED] wrote:
What is the idiomatically appropriate Python way to pass, as a function-type
parameter, code that is most clearly written with a local variable?
For example, map takes a function-type parameter:
map(lambda x: x+1, [5, 17, 49.5])
What if, instead of just having
Simon Forman wrote:
That third option seems to work fine.
Well it does, but there are still many things wrong with it
if len(tok) 0:
should be written as
if(tok):
tok = ''
tok = toc + c
should be written as
tok = []
tok.append(c)
and later
''.join(toc)
anyway, the
Brian Elmegaard wrote:
for a, e in l[-2].iteritems():
# Can this be written better?
if a+c in l[-1]:
if l[-1][a+c]x+e:
l[-1][a+c]=x+e
else:
l[-1][a+c]=x+e
#
I'd start with something like
for a, e in l[-2].iteritems():
keytotal =
Phoe6 wrote:
Hi all,
I had a filesystem crash and when I retrieved the data back
the files had random names without extension. I decided to write a
script to determine the file extension and create a newfile with
extension.
[...]
but the problem with using file was it recognized
Steve Holden wrote:
I'm quessing because (s)he wants to test programs on less recent
versions of Python. Ubuntu 5.10 was already up to Python 2.4.2, so I
can't imagine there's anything older on Ubuntu 6.06.
regards
Steve
Both are avaiaible...
--
- Justin
--
I have this iterthreader module that I've been working on for a while
now. It is similar to itertools.imap, but it calls each function in
its own thread and uses Queues for moving the data around. A better
name for it would probably be ithreadmap, but anyway...
The short explanation of it is if
Py PY wrote:
(Apologies if this appears twice. I posted it yesterday and it was held
due to a 'suspicious header')
I'm having a hard time trying to get a couple of tests to pass when
compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's
not too far removed from the desktop
Tom Plunket wrote:
I'm using this package that I can't import on startup, instead needing
to wait until some initialization takes place so I can set other
things up so that I can subsequently import the package and have the
startup needs of that package met.
[...]
So as y'all might guess, I
Tom Plunket wrote:
boilerplate = \
[big string]
return boilerplate % ((module,) * 3)
My question is, I don't like hardcoding the number of times that the
module name should be repeated in the two return functions. Is there
an straight forward (inline-appropriate) way to
John Blogger wrote:
That I want a particular tag value of one of my HTML files.
ie: I want only the value after 'href=' in the tag
'link href=mystylesheet.css rel=stylesheet type=text/css'
here it would be 'mystylesheet.css'. I used the following regex to get
this value(I dont know if it
Justin Azoff wrote:
from BeautifulSoup import BeautifulSoup
html='link href=mystylesheet.css rel=stylesheet type=text/css'
page=BeautifulSoup(html)
page.link.get('href')
'mystylesheet.css'
On second thought, you will probably want something like
[link.get('href') for link in page.fetch
Thomas Nelson wrote:
This is exactly what I want to do: every time I encounter this kind of
value in my code, increment the appropriate type by one. Then I'd like
to go back and find out how many of each type there were. This way
I've written seems simple enough and effective, but it's very
Gregory Piñero wrote:
Hi Guys,
I'm sure this is documented somewhere, I just can't locate it. Say I
have this code:
try:
myfile=file('greg.txt','r')
except IOError, error:
[...]
So basically I'm looking for the document that tells me what possible
errors I can catch and their
Noah Gift wrote:
[snip]
a = long(time.time() * 256) # use fractional seconds
TypeError: 'module' object is not callable
Part of your program includes a file or directory that you called
'long'. You should not re-use names of built-ins in your programs..
they cause you to get errors like
Jeethu Rao wrote:
You need to use httplib.
http://docs.python.org/lib/httplib-examples.html
Jeethu Rao
Not at all. They need to read the documentation for urrlib:
http://docs.python.org/lib/module-urllib.html
http://docs.python.org/lib/node483.html
The following example uses the POST method
manstey wrote:
Hi,
Is there a clever way to see if two strings of the same length vary by
only one character, and what the character is in both strings.
E.g. str1=yaqtil str2=yaqtel
they differ at str1[4] and the difference is ('i','e')
something like this maybe?
str1='yaqtil'
John Salerno wrote:
If I want to make a list of four items, e.g. L = ['C', 'A', 'D', 'B'],
and then figure out if a certain element precedes another element, what
would be the best way to do that?
Looking at the built-in list functions, I thought I could do something like:
if L.index('A')
John Salerno wrote:
Ok, I'm stuck on another Python challenge question. Apparently what you
have to do is search through a huge group of characters and find a
single lowercase character that has exactly three uppercase characters
on either side of it. Here's what I have so far:
pattern =
Bruno Desthuilliers wrote:
And of course, I was right. My solution seems to be faster than Paul's
one (but slower than bearophile's), be it on small, medium or large lists.
Your version is only fast on lists with a very small number of unique
elements.
changing mklist to have
items = range(64)
Dylan Moreland wrote:
I would look into one of the many Vim scripts which automatically fold
most large blocks without the ugly {{{.
Who needs a script?
set foldmethod=indent
works pretty well for most python programs.
--
http://mail.python.org/mailman/listinfo/python-list
Magnus Lycka wrote:
orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())]
orderedListOfTuples = sorted(mydict.items())
It's great that many people try to help out on comp.lang.python,
the community won't survive otherwise, but I think it's important
to test answers before
[EMAIL PROTECTED] wrote:
I need to look at two-byte pairs coming from a machine, and interpret the
meaning based on the relative values of the two bytes. In C I'd use a switch
statement. Python doesn't have such a branching statement. I have 21
comparisons to make, and that many if/elif/else
[EMAIL PROTECTED] wrote:
I need to look at two-byte pairs coming from a machine, and interpret the
meaning based on the relative values of the two bytes. In C I'd use a switch
statement. Python doesn't have such a branching statement. I have 21
comparisons to make, and that many if/elif/else
You could use IPy...
http://svn.23.nu/svn/repos/IPy/trunk/IPy.py is one location for it...
I wonder where you get O(n) and O(n^2) from... CIDR blocks are all
sequential.. All you need to store is the starting and ending address
or length. Then any set operation only has to deal with 4 numbers,
Heiko Wundram wrote:
Union of two IP4Ranges is simply normalizing a concatenated list of both
IP4Range ranges. Normalizing takes O(log n)+O(n) = O(n) steps, where n is
the number of ranges in the combined IP4Range.
I see now :-) If the ranges are sorted, I bet you could just iterate
through
Justin Azoff wrote:
Yes.. if they are sorted, something like this should work:
Oops, that was almost right, but it would skip some ranges.
This should always work:
...
while 1:
try :
if a.intersects(b):
ret.append(a.intersection(b
Tim Hochberg wrote:
Note that in principle it's possible to encode the data for how to
display a digit in one byte. Thus it's at least theoretically possible
to condense all of the information about the string into a string that's
10 bytes long. In practice it turns out to be hard to do that,
Tim Hochberg wrote:
In the 130's is definately possible, but I haven't heard of anyone doing
better than that.
I have a version that is 127, but only if you strip extra whitespace
:-(
--
- Justin
--
http://mail.python.org/mailman/listinfo/python-list
c=open(seven_seg.py).read()
len(c)
251
len(c.replace( ,))
152
:-)
Knowing me, I'll forget to submit it.
--
http://mail.python.org/mailman/listinfo/python-list
How much ram does your machine have?
the main point is except when a very large range is used on a
memory-starved machine
run
x = range(10 ** 6)
and look at the memory usage of python..
what happens when you run this program:
import time
def t(func, num):
s = time.time()
for x in
45 matches
Mail list logo