Jacob S. wrote:
Ahh, my pitiful form of flattening a list that cheats...
def flatten(li):
li = str(li)
li = li.replace("[","")
li = li.replace("]","")
li = li.replace("(","")
li = li.replace(")","")
li = "[%s]"%li
return eval(li)
It works! It's probably just a bit slower
Jacob S. wrote:
This will get a random record
I hope you do not think the comments are patronising
but you did say you are new so I did not want to give
naked code.
import random
#the above gives the program the ability to get a
#pseudo random number
file = open('test.rantxt')
listcontents = file.r
Ahh, my pitiful form of flattening a list that cheats...
def flatten(li):
li = str(li)
li = li.replace("[","")
li = li.replace("]","")
li = li.replace("(","")
li = li.replace(")","")
li = "[%s]"%li
return eval(li)
It works! It's probably just a bit slower.
Jacob Schmidt
This will get a random record
I hope you do not think the comments are patronising
but you did say you are new so I did not want to give
naked code.
import random
#the above gives the program the ability to get a
#pseudo random number
file = open('test.rantxt')
listcontents = file.readlines()
#give
On Sat, 22 Jan 2005, Ali Polatel wrote:
>I want to ask you something that I am really curious about.
>Can I design web-pages with python or use py files to write html?
Hi Ali,
Almost every programming language allows us to write strings into files,
so from an academic standpoint, 'yes
On Sat, 22 Jan 2005, Kent Johnson wrote:
> Jay Loden wrote:
> > One simple solution is to do:
> >
> > fle = open(file)
> > contents = file.readlines()
> > file.close()
> > print contents[x] #or store this in a variable, whatever
>
> That is the simplest solution. If your file gets bigger and yo
Hi all tutors,
I want to ask you something that I am really curious about.
Can I design web-pages with python or use py files to write html?
if the answer is yes and if I upload some scripts to the web-site with* .py
does someone have to ahve python interepreter in his computer to b
This will get a random record
I hope you do not think the comments are patronising
but you did say you are new so I did not want to give
naked code.
import random
#the above gives the program the ability to get a
#pseudo random number
file = open('test.rantxt')
listcontents = file.readlines()
#gi
Max Noel wrote:
On Jan 22, 2005, at 13:53, Kent Johnson wrote:
That is the simplest solution. If your file gets bigger and you don't
want to read it all at once, you can use enumerate to iterate the
lines and pick out the one you want:
f = open(...)
for i, line in enumerate(f):
if i==targetLin
I have a threaded python ( Python 2.3.4 ) script that runs perfectly on
Windows 2000 Server SP4 when it is executed from IDLE ( i.e. press 'F5' from
the editor ), the threads do their work, halt, and the 'join' command picks
them up. When I run the same script from windows command line ( cmd.exe ),
For anyone who doesn't like lambda, how about
import os
def get_fles(exts, upd_dir):
return [i for i in os.listdir(upd_dir) if i.split('.')[-1] in exts]
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Behalf Of Javier
> Ruere
> Sent: 22
Jay Loden wrote:
> Thanks! That's exactly the kind of feedback I was looking for. If
it's not
> too much trouble, do you think you could explain how lambda works, or
just
> point me towards a lambda explanation/tutorial that a new programmer can
> understand? It seems to give you some great power
Filter can be replaced with IMHO the more readable list comprehensions.
I would try
def get_fles(exts,upd_dir):
"return list of all the files matching any extensions in list exts"
fle_list = []
for each in exts:
ext_ls = glob.glob("%s*.%s" % (upd_dir,each))
fle_list.extend(ex
Javier Ruere wrote:
Jay Loden wrote:
I have the following code in my updates script (gets the five most recent
updated files on my site)
def get_fles(exts, upd_dir):
'''return list of all the files matching any extensions in list exts'''
fle_list = []
for each in exts:
cmd = upd_dir + "*." + ea
On Jan 22, 2005, at 13:53, Kent Johnson wrote:
That is the simplest solution. If your file gets bigger and you don't
want to read it all at once, you can use enumerate to iterate the
lines and pick out the one you want:
f = open(...)
for i, line in enumerate(f):
if i==targetLine:
print lin
Jay Loden wrote:
One simple solution is to do:
fle = open(file)
contents = file.readlines()
file.close()
print contents[x] #or store this in a variable, whatever
That is the simplest solution. If your file gets bigger and you don't want to read it all at once,
you can use enumerate to iterate t
16 matches
Mail list logo