Hello,
The way I do it is as follows.
def open():
a = open('myfile.txt','r')
di = a.read()
a.close()
di = eval(di)
return di
def save(di):
a = open('myfile.txt','w')
a.write(str(di))
a.close()
def dosomethingwithdi(di):
'''You can put whatever you want in her
> > execute the scripts using python24. However, the "Edit with IDLE"
> command in
> > the shorcut menu (right-click pull down menu) no longer worked. So I
> went to
> > the registry (I know the risks involved)
>
> BUt entirely unnecesary here!
> The way to check/fix the context(right-click) menu o
> I am fairly new to programming and I have started to learn programming
> then stopped out of frustration several times in the past. I guess my
> frustration stems from not being able to understand when to use certain
> aspects of programming such as functions or classes.
Use functions when you
I thought that the '.py ' in this import statement would make the
interpreter think that newline was a package and therefore try to recognize
py as a module in the newline package.
from newline.py import newline
Perhaps you said this to help explain what's going on?
Jacob Schmidt
>
> If so that
If you or anybody else is interested, I've written a script for codes like
kids in junior high use to write notes to each other with... It will cipher
and decipher mixed letters (encryption), turn words inside out (try it and
see), date code (mixed letters that changes with the date), morse code,
p
Wow! I never thought of using dictionaries to store function objects like
that! The "table-driven" approach is much better than my own! Thanks a lot!
Jacob Schmidt
>
>
> On Thu, 2 Dec 2004, Jacob S. wrote:
>
> > If you or anybody else is interested, I've written
You know, since time.sleep() builds up errors, this is what I do to keep it
purely pythonic... (not tested)
from time import gmtime
alarmhr = 8
alarmmin = 5
alarmsec = 0
while 1:
t = gmtime()
hour = t[3]
min = t[4]
sec = t[5]
if (alarmhr,alarmmin,alarmsec) == (hour,min,sec):
I did something like this about three or four months ago...
This is what I did. Notice the use of the built-in str() and eval()
functions to write and receive data to and from Telephone.cfg...
from __future__ import division
tel = {}
try:
file = open('Telephone.cfg', 'r')
except:
file = op
ther suggestion. Comment out the file writing part and print everything
to the screen to verify that the output is what you want. "When in doubt,
print it out." - Jacob Schmidt
HTH,
Jacob
> Quoting "Jacob S." <[EMAIL PROTECTED]>:
>
> > Hi!
> >
> > Ca
Hi!
Can I ask a few questions? (Other than this one...)
What output did you expect? A string, tuple, or what? I'm not strong with
cgi stuff.
Also, you don't need the string module 1) because you don't use it 2)
because you can use string methods.
Jacob Schmidt
> Hello!
>
> I am having some probl
Hi all.
Nothing I can do can fix my problem. It appears as though pythonw.exe is
not working properly in the python 2.4 distribution. I have tried numerous
things to try and fix it. The only way I can run Tk scripts and the like is
to use the pythonw.exe from the 2.3 distribution. This include
Ha! That's what I was looking for! The builtin apply function! The only way
I could send the *args to the function was through a list, and function
calls see a list as one argument. The apply argument doesn't! Thanks Bob.
Jacob Schmidt
> At 12:39 PM 12/8/2004, Bob Gailer wrote:
> >At 11:27 AM 12/
Hey, I made some changes to my address book, with help from Oh darn,
well whoever you are, I haven't forgotten the help you gave me in changing
my if/if/if/if/if/else things into mapping objects Anyway, if anybody
wants a look, here it is.
P.S. I made some changes to the file reading part t
Finding the all the roots of a complex number shouldn't be too difficult. I
tend to do it on paper sometimes. Maybe I can write a script to do it for me
instead. I stongly caution you though. The methods that I show below are
unstable and should be verified by a math web site as it has been quite
You know, instead of that long or thing you've set up, you could do this.
if select in [ 'l', 'v', 'V' ]:
> [quote]
> if select == '1' or select == 'v' or select == 'V':
> if file_in_disk in os.listdir('/home/jerimed'): #
change???
> fhandle = open(file_in_disk, 'r
If you mean the "Internet Connection Firewall" thingy that you access from
the network connection options, then Nope, that's not the problem, because
it's disabled.
Thanks for your help,
Jacob
>
> Seeing this comment reminded me of some conversations I've seen in
> comp.lang.python recently. App
Hey, could you give an example?
Thanks,
Jacob
>
> apply() is deprecated; it has been replaced by 'extended call syntax'.
Instead of
>apply(fn, args, kwds)
> you can now write
>fn(*args, **kwds)
>
> Kent
> ___
> Tutor maillist - [EMAIL PROTECTED
Thank you!
Wait, though.
How do I do this?
def differentnoofvars(*args,**kwargs): ## By the way, is it **kwargs or
**kwds?
print kwargs
another(kwargs)
def another(**kwargs):
for x,y in kwagrs.items():
print "%s = %s" % (x,y)
a = ['a=2','f=3','t=[1,2,3]'] ## A list of kwa
Sorry about that last message. Kent just posted and answered my question
with his example.
Thank you all!
Jacob
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> > Sent: Friday, December 17, 2004 3:54 PM
>
Hello!
> >target_dir = 'D:\\backup'
> >target = target_dir +"Zipnametoreplacestrftimeformatstring"+ '.zip'
>
> Just noticed this -
>
> target_dir("D:\\backup") + "Zipnametoreplacestrftimeformatstring"+ '.zip'
>
> = D:\\backupZipnametoreplacestrftimeformatstring.zip
>
> No wonder it doesn't work.
>
> Thing is, for people like me, you generally either don't know that a
> question is a dumb one until someone tells you the answer, (the 'of
> course' moment), or until 5 minutes after you emailed
> your query, you find the answer you were looking for...
Amen! My life's story!
Also, to Kumar.
T
Gee,
I think I'm going to burst out in tears.
Mike Hansen gave the solution to the very problem I'm having, yet, when I
used the console version and deleted the custom color theme, it stopped
giving me error messages, but it still won't start up without the console.
I'm am still stunted of my pyth
Thanks for the explanation!
Jacob Schmidt
> Jacob S. wrote:
> > Thank you!
> >
> > Wait, though.
> >
> > How do I do this?
> >
> > def differentnoofvars(*args,**kwargs): ## By the way, is it **kwargs or
> > **kwds?
>
> Call it what you li
Also, just as interesting, yet probably less reliable:
a = list(a)
a[-3:] = 'bak'
a = "".join(a)
OR
a = a.rstrip('pct')
a = a+'bak'
OR
a = a.rstrip('pct')+'bak' ## Which is essentially the same thing
OR
a = a[:-3]+'bak'
ETC.
HTH,
Jacob
> x=os.path.splitext(a)[0]+'.bak'
>
> Ah, jolly good
> > I was wondering were can I find some Vpython graphics program codes that
are readily available.
I have 2 that I am proud of.
A simple function grapher
Usage:
>0.125*x**2
Graphs y = 1/8*x**2
>y = 1/x
Graphs y = 1/x
>clear
Clears display window
>r = t**2
Graphs polar function r = t**2
>
I probably wouldn't be any help on projects, but I would probably learn
stuff from it.
I'm okay with it.
Jacob Schmidt
> >> I just got in contact with Nick Parlante of the Nifty
> >> Assignments project; he's been collecting material on fun
> >> projects:
> >>
> >> http://nifty.stanford.edu/
>
> >
Hey, now.
I know that some of us are newbies to python, but that doesn't mean that
we're all newbies to math concepts. (Even advanced ones.) Having said that,
I will shut my fat mouth now because it will be my luck that the math is
beyond what I can handle. I wouldn't mind seeing the code. Even if
Am I wrong, or is that what the module sets is for? I don't remember if
python 2.3 has it, but python2.4 has it available.
>>> import sets
>>> s = sets.Set
>>> a = s([1,2,3])
>>> a
Set([1, 2, 3])
>>> a.update([1,1,2,2,3,3,4,4,5,5])
>>> a
Set([1, 2, 3, 4, 5])
>>>
HTH,
Jacob Schmidt
> > def combin
Would this work for you?
a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff','CGATATGCCGGCTA']
for index,thing in enumerate(a):
if "Name=" in thing:
del a[index]
I know, that it might be slow, but I thought that maybe it would hold its
own because it doesn't have to import the re modu
Okay, here's the code.
I am completely open to suggestions as this is my first dabbling in Tk.
Please look over it when you have time.
I have a couple of questions.
1) How do I change the title of the window?
2) Why does a window pop up saying something like error, the memory could
not be "read".
Duh, whack myself on the head a few times.
Thanks,
Jacob
> Max Noel wrote:
> >
> > On Dec 19, 2004, at 06:16, Jacob S. wrote:
> >
> >> Would this work for you?
> >>
> >> a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff
That's interesting, I hadn't thought of that!
Jacob
> Jacob S. wrote:
>
> > Would this work for you?
> >
> > a = ['Name = stuff','CGTATAGCTAGCTA','Name = stuff','CGATATGCCGGCTA']
> > for index,thing in enumerate(a
Ah, hah!
Okay, everyone! It took two things.
1) Delete .idlerc directory
2) Uninstall and reinstall python2.4
Why I had to do step two is beyond me, but I've got it settled now!
Thank you,
Jacob Schmidt
>
> "Jacob S." <[EMAIL PROTECTED]>
>
> > Gee,
> &g
Hi,
A little while ago, someone posted a message about an error and
something about modifying the windows registry key HKEY_CURRENT_USER\Control
Panel\Desktop so that the value Wallpaper was changed periodically. I wonder
if anyone could tell me how to do that? I tried something, and it didn't
Hi!
I just wondered why you included the time.localtime(time.time()) in the
defining of today.
Doesn't the default time.gmtime() work okay?
def gettoday():
import time
today = time.strftime('%Y%m%d%H')
return today
Jacob Schmidt
> Rumor has it that Ertl, John may have mentioned thes
> The only thing that's missing is that this script can't handle paths
> like ~/dir/junkthis
I believe you're looking for os.path.expanduser("~/dir/junkthis")
BTW, trashcan IS a module level variable because it's defined at the module
level. Why it says it's local is beyond me.
HTH,
Jacob Schmid
Hi,
[Blah,blah,blah,text cut]
>
> #! /usr/bin/python
> import string, re
First, I like to use string methods instead of importing the string module,
so let's get rid of that.
> dict1={}
> dict2={}
> inputFile1 = open("rough.txt", "rb")
> inputFile2 = open("polished.txt", "rb")
> for row in input
I hate to sound weird...
But who are you all, what are you're ages, what do you do, marriage status,
etc?
You obviously don't have to answer, I'm just curious who I'm boldly sending
emails to.
Jacob Schmidt
P.S.
I'm a student. 14 years. Play the piano better than I write scripts. Single.
etc.
_
> Btw I'm single as well so if your sister looks like Salma Hayek please
> send her my gorgeous picture.
giggle,giggle,giggle...
I don't know who Salma Hayek is or what she looks like, but I can almost
assure you that my sister doesn't look like her.
My sister is 29 as well, but I think she's had
> Season's Greetings Jacob and all the circus.
> Not to be nosy, Jacob, but is that 14 years old (or 14 yrs a student)?
> Married at 14 might be a little wierd!
14 years old. I should have put " single (obviously) ", or something like
that.
However, where I live--Portland, IN--the high school kid
And this, right here, is why I like the grid method. ; )
I can easily place everything into a grid that I lay out before hand. I'm
used to coordinate systems.
I just don't have a firm grasp on the way pack works.
Jacob Schmidt
> First, thanks for the responses on my questions on using Tkinter fo
I'm definitely interested.
Jacob S.
> On 06.05.2004 21:06, Alan Gauld wrote:
> > THis is a problem in all programming languages on Windows because
> > basically Windows treats documents to be printed as graphics, so
> > you have to convert your document into something
don't know, so I learn
> enough to answer the questions
> - OK I admit it, it makes me feel smart :-)
That describes my experience on the tutor list exactly!
> If you really want to know more about me see my web site
> http://www.kentsjohnson.com
>
> Kent
>
> Jacob S.
Hi,
A little while back somebody suggested doctesting, I think it was. Well,
anyway, it was the testing that took testing material from the doc strings
of functions in the format of an interpreter and the desired result (example
below). Could anyone help by pointing me to structured documentat
Hello.
I believe it was Danny Yoo who told me about mapping functions a while
back on the list...
It goes along these lines...
funct = {'Add Virt':addvirt,'Remove Virt':remvirt,'More
Stuff':more,"Extras":extra}
def addvirt():
pass
def remvirt():
pass
def more():
pass
def extra():
Nobody explicitly mentioned that you're trying to make a pattern from an
integer and not a string, which, I believe is required. Also, Rich needs to
make the % formatting "%d"%x instead of "%s"%x because he showed that x
is an integer not a string.
There's my two bits.
Jacob Schmidt
> Hi Gro
> Actually %s formatting is very flexible and forgiving, it outputs str(x)
whatever x is. For example:
> >>> for x in ['string', 10, True, [1,2,3] ]:
> ... print '%s' %x
> ...
> string
> 10
> True
> [1, 2, 3]
>
> Kent
That's cool! I didn't know that. I guess I'm crazy... : )
(We already
Hi.
Okay, so I look at the documentation at it says (in my words):
"First Class - DocTest -- Make a test object with such and such attributes
that you can test.
Second Class - i don't remember the name - Make Jacob look stupid with big
words
Third Class - DocTestSuite - Convert a doctest obje
e a complete example of testing a module with a main function. Or you
can use the code in my last
> post.
>
> Kent
>
> Jacob S. wrote:
> > Hi.
> >
> > Okay, so I look at the documentation at it says (in my words):
> >
> > "First Class - DocTest -
;
>
> exec "import %s" % modtotest
> doctest.testmod(eval(modtotest))
> raw_input()
> #
>
>
> Thanks,
> Jacob Schmidt
>
>
> > What docs are you looking at?? The module docs at
> http://docs.python.org/lib/module-doctest.html
> [Bill]
> I've seen list comprehensions, but I didn't understand how they worked.
> Since I understand how my function works, it's not so hard to figure out
> what your doing with this list comp. I guess the brackets ([]) signify a
list.
> Then the for loop is placed on the right-hand side and the
Unfortunately as I overly enjoy
writing scripts, I tend to spoil the recipients of the
tutor.
IF you do not wish to have a
complete answer, read someone else's email and not mine.
### Start
code###
import random
participants = 10ask =
[raw_input('What is the participan
## Spoken by Ara ##
Pardon to the non-german speaking (or readers) on the list.
Guten Tag. Mein Deutsch ist nicht so gut (ich habe keinen Deutsche in sieben
Jahren geschreiben). Mann kann Python Tutorials auf Deutsch heir
http://www.freenetpages.co.uk/hp/alan.gauld/german/index.htm
und
http://hkn.
> It should work as you describe it.
> Can you just clarify how you are doing this?
> Are you setting sys.path in the same program you
> are trying to run? Or is it set in a Python startup script?
>
> How do you run a.py? Are you importing it into an existing
> Python session(with sys.path set or a
> line of white space. Could it be you have an unterminated
> string (missing close quotes) at the end of your program?
>
> Alan G
I would like to add maybe a missing or extra parenthesis?
I have trouble with that alot.
Jacob
___
Tutor maillist - Tut
> Shouldn't that be os.path.walk()?
It says in the documentation (it might be the newer ones?):
"Note: The newer os.walk() generator supplies similar functionality and can
be easier to use."
-- 6.2 os.path -- Common pathname manipulations
And, yet, the os.walk() function states (condensed):
>Hello I can't seem to get the IDLE to start up in my windows XP by clicking
on the desktop icon. To start it I have to >drop a .py file on the icon. Any
ideas?
Danny just answered that, I believe... so next!
>Also I can't seem to get xp to recognize .py files belonging to python.
Right now the
I wondered when someone would ask something like this.
eval() is good and it can be done using it.
I wrote a -- IMHO -- really great functiongraphing program using vpython.
If you would like to see it, just reply and say so.
Pros and cons of calculating all first:
pro - easier to read code
con -
The subject line says it all... Okay I'll add some.
I'm am bored and people are not asking enough questions/answering them to
keep my mind busy. Is there any other mailing list that I can subscribe to
like this one that lets anyone ask and answer questions?
Thanks in advance,
Jacob Schmidt
_
well. Perhaps for the future I will try 3d graphs, since VPython supports
3d.
Hah! There's something I don't remember Tkinter Canvas being able to do.
Jacob
> Jacob S. wrote:
>
> >eval() is good and it can be done using it.
> >I wrote a -- IMHO -- really great functi
> *sigh* I have no net at home at moment, which is very frustrating when
> I want to d/l documentation & editors. For the mo, it's all Notepad.
> Ick.
Call me stupid or whatever, but how do you send and receive mail to this
list?
Maybe someone on the list could send you Eclipse as an attachment ma
Here's the code. If you have time, look it over and give me suggestions for
improvement!
(big toothy grin)
### Start of Calculator.py ###
from __future__ import division
from Tkinter import *
class Application(Frame):
def ctb(self):
if self.shouldblank:
self.distext.set(''
btract,row=4,column=4)
> self.makeButton(text='x',command=self.multiply,row=3,column=4)
> self.makeButton(text='/',command=self.divide,row=2,column=4)
> self.makeButton(text='ON/C',command=self.clear,row=1,column=4)
>
(text='6',command=lambda:
self.adddigit('6'),row=3,column=3)
> self.makeButton(text='7',command=lambda:
self.adddigit('7'),row=2,column=1)
> self.makeButton(text='8',command=lambda:
self.adddigit('8'),row=2,column=2
=1,column=4)
self.makeButton(text='MRC',command=self.memrecall,row=1,column=1)
self.makeButton(text="M-",command=self.memminus,row=1,column=2)
self.makeButton(text="M+",command=self.memplus,row=1,column=3)
def __init__(self, master=None):
Ugggh, the code I sent looks ugly when it came back. Why does Outlook
Express wait until you receive mail to wrap the
text? Isn't there an on/off switch for the stupid wrapping that sucks and
starts working at the wrong time?
___
Tutor maillist - Tutor
> Ah, right you are. I should know better than to post untested code, it's
usually buggy!
>
> I think you need to do the same thing for add(), subtract(), multiply()
and divide(). For some
> reason I don't understand, for me add works from the keyboard and multiply
doesn't!?
The same thing happene
ing the calculator I bought, right? Yeah, I love loopholes.
Anyway, I don't think it will matter because this is too trivial.
(Sound of hands rubbing together in anticipation of making such a big
thing.)
I'll post some code as soon as it's stable.
Jacob Schmidt
> Jacob S. wr
I think I speak for a few of us in the fact that we don't know if that's
close to the correct approach due to the fact that you haven't given us a
full line to look at. Is col[17] the last column? If so, take the code I
just sent and change the line to:
if line.startwith('25\t') and line.endswith(
coll is a string, 25 is an integer.
However, I would do it this way.
file1 = open('psl.txt','r')
for line in file1:
if line.startwith('25'):
line = line.split('\t')
print "\t".join(line[0],line[1],line[17])
file1.close()
This has the added advantage that if you have a big fil
> > Great! I took the improvements you gave me an added support for keys (So
you
> > can type in 1.25+2= instead of having to type the buttons.) As always, I
> > encourage improvements to my code. Maybe that will be my disclaimer... I
> > have always liked and wanted to adopt Liam's.
>
> Here's a f
Would this do the trick?
stringtime = '12:34' ## This is the column with the time 12:34 is an
example
time = stringtime.split(":")
time = [int(x) for x in time]
time.reverse()
seconds = time[0]+time[1]
try:
seconds += time[2]
except IndexError:
pass
print seconds
I'm almost sure there
I don't think so. (correct me if I'm wrong) The datetime module is for
making date and time instances that you can add and subtract to get
timedelta objects. Other things involved of course, but I don't think it has
anything to do with parsing and
pretty printing columns of times. I'm not sure, don
> The old mx.datetime module (on which Python's datetime module is based, I
> presume) had a strptime() function which would basically do the reverse
(you
> specify a format string and it would attempt to parse the date string you
give
> it). Unfortunately, Python's datetime module doesn't have su
Forgot to mention -- screwed up before. In my proposed try/except block,
etc. I forgot to do unit conversion.
Jacob
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Danny Yoo solved the problem, but I would like to suggest something.
target = '*' + str(living_species[counter]) + '*'
replacement = '(' + target + ',*' + str(current_species) + '*)'
change these lines to
target = "*%s*" % (living_species[counter])
replacement = "(%s*%s*)" % (target,current_spe
Don't forget the string method join()!
print "".join(['\n','siday_q',key,'.wav'])
It works too ;-) (though I like the string formatting better for this.)
Jacob
>
>
> when i print:
>
> print '\n','siday_q', key, '.wav'# event
>
>
> i get:
>
> siday_q 515 .wav
>
>
> how can you elimin
> Problem:
> How do i capture every alternative element in list a:
Use Jeff Shannon's approach to get keys and vals.
> >>> keys = [] # create a list of all keys i.e a,b,c)
> >>> vals = [] # create a list of all values i.e
>#appele,boy,cat etc.
>
> >>> dict = {}
>
> >>> dict =
I assume that both you and Liam are using previous-er versions of python?
Now files are iterators by line and you can do this.
openFile = open("probe_pairs.txt","r")
indexesToRemove = []
for line in openFile:
if line.startswith("Name="):
line = '' ## Ooops, this won't work because it
I'm not too sure about this...
Couldn't you make that a package?
Rename Backup.py to __init__.py
Put all of the modules in a folder named Backup
in your sys.path - Question: Does it have to be
in site-packages?
Well, there's my two bits,
Jacob
> During the recent discussion on jython, a poster
>
Kent's suggestions are great, but I wanted to add two.
> Hello list.
>
> I'd really appreciate any comments, particulary regarding style
> corrections. I'm a newbie...
>
> Thanks!
> Ismael
>
>
> import random
> import tkMessageBox
> from Tkinter import *
>
> class GUI:
> def __init__(sel
> > It would be a god excercise to extract all the p[ipe code into
> > a separate class and the GUI methods call those class methods
> > to get the work done. THis would allow for a fairly easy port
> > to a different GUI or even the creation of a command line
> > version, so you could do:
Actuall
I seem to always be the one to suggest this, but --
"String methods are better than using the string module because the string
module has been ?deprecated? or will be soon. I think that is the word here.
So, do this instead."
insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
insideipg
Kent's suggestions are always my favorites, along with others,
c. --nevermind
To get the full path in your list-- change Kent's to this
import os
filelist = []
for root,directories,filenames in os.walk("Aircraft"):
for filename in filenames:
if filename.endswith("-set.xml"):
t it works because it seems to me if it can split
the whole input, it can certainly split just one split deep!!! Anyway...
Jacob
On Mon, 17 Jan 2005 21:38:37 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
I seem to always be the one to suggest this, but --
"String methods are better than us
Hi everyone, sent this on to the list as told to.
cc to eri to verify my sending to list...
;-) Jacob
dear jacob,
sorry to send this to you but if you may, kindly send to tutor list as im
no longer subscribed. my problem is in the update dict portion: it just
doesnt update regardless how many cont
Hi all,
I'm having a problem that is ticking me off. (to put it lightly)
Why does decimal do this -- I thought that getcontext().prec was number of
decimal places?
import decimal
decimal.getcontext().prec = 2
a = decimal.Decimal(2)
b = decimal.Decimal(3)
100*a/b
Decimal("67")
print 100*a/b
67
Okay, so how do I get decimal to set precision of *significant digits*?
Why have a decimal.getcontext().prec if it doesn't provide a useful result?
The number of digits in a number is irrelevant to that numbers value.
It just doesn't make sense to me.
I tried quantize the other day and it didn't wo
Just one question...
Why are you off the list?
I see no point.
If you want to stop getting the mail, you can change the options of your
list account online...
That's the only reason I see...
Let's see -- reasons
1. Cost -- No, it's free
2. Security -- If you were subscribed to it once, it's too l
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
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
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
Hi all.
Long time no see. (About five days, right?)
Anyway, I know the first thing that some of you are going to say is using
eval(). I don't want a whole
guilt trip on security risks and all that. I do not want to share the code
with anyone else while it's on my
computer, and I sure don't hav
Thanks everyone!
Kent started the suggestion of making a code object, but everyone else seems
to have worked their way to it.
Beautiful! I only have to call exec once, and it cuts down time
considerably.
Here is the new code.
Jacob Schmidt
Please remind me if I've forgotten anything.
### Start #
col2_set = sets.Set(col2)
how can I get a uniq elements that repeated several
times:
for item in range(len(list)):
for k in range(len(list)):
if item == k:
if list[item] != k[list]:
print item
First off, this would never work. You are iterating over the s
Try this
def findfile(thefile,
toplevel="C:\\windows",findcount=-1,subdirectories=True,returnlist=False):
results = []
t = 0
if subdirectories:
for root,dirs,files in os.walk(toplevel):
for x in files:
fullname = os.path.join(root,x)
if x.lo
Its not so much a criterion that they *should* be used that way,
its just that its what they do. A list comprehension creates a list!
Thats why they are called *list* comprehensions. :-)
See, I'd always figured that the reason it was called a list
comprehension was because the list comprehension o
You're my best friend. Everyone else looves camelCase, and I hate it too. It
doesn't make sense. It doesn't fit English.
It doesn't fit Spanish. It doesn't fit any other language AFAIK, so why
should a human (who uses spoken language) to computer interpreter use a
naming convention that doesn't
I noticed that too, Liam.
b = input("Weather is really bad, still go out to jog? [y/n]") # Would
it kill you to have whitespace in a prompt?
should really be
b = raw_input("Weather is really bad, still go out to jog? [y/n]")
to get the effect he wants.
input() doesn't only take integers,
_go_funny_,
_and_code_hard_to_read_in_my_opinion.
_u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_
I got out of the habit of using them really fast.
Also, __ & _ tend to have special meaning in Python (which is bad
enough as it is), so I don't use them for that reason as well.
Liam Clarke
On Fri, 28 Jan 2005 22:5
1 - 100 of 199 matches
Mail list logo