> It gives following error:
> Traceback (most recent call last):
> File "C:\python\urllib.py", line 1, in -toplevel-
> import urllib
> File "C:\python\urllib.py", line 9, in -toplevel-
> page = urllib.urlopen(go_url).read()
> AttributeError: 'module' object has no attribute 'urlopen'
Hi Devan
> I would like to create an executable program that when ran it will
> search my hard drive for certain folders that contain different files.
> Once the program finds these folders, I would like the program to zip
> each of the folders up and then e-mail each of the folders to a certain
> e-mai
>> Do you have any questions so far about this? Some kind of model like
>> this is necessary to understand the situation you're seeing now, so
>> please feel free to ask if any part of this is confusing.
>>
> But in the following example, a change in a spread to both b and c:
a=[[1,2,3], [4
> I am learning Python 2.4 with Tkinter. I have a series of radio buttons
> that I want to bind to their own individual listbox in order to narrow
> down a selection process.
Hi Joe,
Ok, are you familiar with callbacks? According to:
http://www.pythonware.com/library/tkinter/introduction/x6
>> def adder1(*args):
>> print 'adder1',
>> if type(args[0]) == type(0):
>> sum = 0
>> else:
>> sum = args[0][:0]
>> for arg in args:
>> sum = sum + arg
>> return sum
This function looks overly enamored with Python slicing. *grin* Unless
I'm m
> Thanks for the great email.I am beginning to see the light on event
> binding, callbacks and functions. I have attached my program to show my
> efforts so far. I think I need a some help in application.
Hi Joe,
I haven't seen your message about this on Tutor yet; have you reposted
your que
> One of my problems in conecptualizing this is that I thought a linked
> queue was just a linked list. Is a linked queue a linked list? There
> seems to be a subtle difference...
Hi Chris,
I think you mean to ask:
Is a "queue" a linked list?
Here's another particular possible queue c
>> This works on a different principle than the linked list queue, but it
>> does the same stuff. The main idea is that a "queue" can be anything,
>> as long as it supports three operations:
>>
>> * isEmpty
>> * insert
>> * remove
>>
> <>
>
> Isn't there a fourth operation needed?
>def navigated(self):
>if (self.state == 'NF') and
> (self.store.units[int(self.id)].isfuzzy()):
>return True
>if (self.state == 'PF') and
> (self.store.units[int(self.id)].isfuzzy()):
>return True
>if (self.state == 'NT') and
> (self.store.unit
> If there were really such a thing as nested scopes/namespaces, we would
> have a function that would give us access to them, similar to the way
> that locals() and globals() give us access to the local and global
> namespace.
It would be _convenient_ to have such a function for inspection, bu
On Tue, 1 Aug 2006, Christopher Spears wrote:
> I've been working through a tutorial:
> http://www.ibiblio.org/obp/thinkCSpy/index.htm. Lately, I have been
> learning about abstract data types (linked lists, stacks, queues, trees,
> etc.). While I do enjoy the challenge of creating these obj
Hi everyone,
Can someone help with Michael's question? Unfortunately, I can't answer
it at the moment.
Here it is below. (I've stripped off the image attachment.)
-- Forwarded message --
Date: Fri, 4 Aug 2006 09:32:48 -0700 (PDT)
From: Michael Cochez <[EMAIL PROTECTED]>
To: [
On Sat, 5 Aug 2006, anil maran wrote:
> http://localhost/newtodo?category=
>
> can one of you guys explain what this is
Hi Anil,
Are you taking some kind of internet web-development class? You seem to
be asking a lot of web-development questions. In the absence of context,
I'm not sure wha
On Sun, 6 Aug 2006, anil maran wrote:
>text = """From: the bugman <[EMAIL PROTECTED]>
> To: the bugfixer <[EMAIL PROTECTED]>
> Subject: bug: %s: %s (%s)
> Content-Type: multipart/mixed; boundary="here"
[text example cut]
Hi Anil,
Anil, take a look at:
http://www.python.org/d
-- Forwarded message --
Date: Mon, 7 Aug 2006 00:28:50 -0700 (PDT)
From: anil maran <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] help regarding forms...
dear danny yoo
thanks a lot for replying
can you explain post methods and actions
-- Forwarded message --
Date: Mon, 7 Aug 2006 00:33:08 -0700 (PDT)
From: anil maran <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] can you explain string replacement syntax and comma
separated statements
Dear danny yoo
The help page
> can you explain post methods and actions i wasnt able to find out how it
> works
Hi Anil,
Please do not email me directly. I don't have much time these days to
help on Tutor. It is better to send replies back to the Tutor list, so
that others there can continue helping you. Also, apologie
> The help page doesnt take about multiline string replacement and this
> example doesnt work for me
Hi Anil,
Please be more specific and as informative as you can; we can't look over
your shoulder, and the only information we see is what you send us.
When you say, "This example doesn't work
> this list is setup to send to the poster by default. I made the
> mistake of doing such a thing earlier myself.
Hi Terrence,
Most email clients have a separate "Reply to All" or "Reply to group"
command that's suitable for mailing lists. Check to see if your mail
client has this feature.
>
On Mon, 7 Aug 2006, David Wilson wrote:
> can you explain functions in python to me and give me some examples
Hi David,
Have you looked into a Python tutorial yet?
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
Most of the tutorials there talk about functions. If you could g
On Wed, 9 Aug 2006, Kermit Rose wrote:
> I've written tenative code for the incr routine.
>
> Now to test and possibly debug it.
Just as a note: it's usually a much better idea to write your test cases
first, even before writing any code. It'll give you a better idea of what
you want your f
On Wed, 9 Aug 2006, linda.s wrote:
> Is that possible to open two Tkinter from one python shell?
It is possible to open more Tkinter "toplevel" windows. Is this what you
are asking for? See:
http://www.pythonware.com/library/tkinter/introduction/toplevel.htm
If we build a new Topleve
On Tue, 8 Aug 2006, Tom Wilson wrote:
> could someone explain to me how the "import" function works?
Hi Tom,
Take a look at:
http://www.python.org/doc/tut/node8.html
and see if that helps; if not, come back and please feel free to ask more
questions about it. In a short summary: impor
On Wed, 9 Aug 2006, anil maran wrote:
> What is the best way to construct an email in python and also attach a
> html file
Hi Anil,
This is a repeat of one of your previous questions; you just sent this
question out yesterday:
http://mail.python.org/pipermail/tutor/2006-August/048452.
> I had the program generate the test cases for me, and then inspected
> them to verify that they were what I desired.
Hi Kermit,
Ah. Try not to do that next time.
It's way too easy to be convinced that some test is working by just
copying the output of the code and looking for reasonable ou
> Is there a way to show the ascii values of the string - kind of hexedit
> for a string
Try running repr() on the string: it will show an external
programmer-friendly representation that should be easier to read. For
example:
##
>>> msg = 'hello\000world'
>>> print re
Can someone help Amil? My hands won't allow me to type too long. Thanks!
-- Forwarded message --
Date: Wed, 9 Aug 2006 17:09:19 -0700 (PDT)
From: anil maran <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] html file - construct att
On Thu, 10 Aug 2006, anil maran wrote:
> how do u find out original encoding
Read:
http://www.joelonsoftware.com/articles/Unicode.html
In short: there's no good, reliable way to guess the encoding. But there
should be no need to guess: a proper document will have the encoding
explici
>> 2) Since this is an introductory class, I am tempted to leave out
>> "optional" topics like argument matching modes, walk, map, filter,
>> reduce, apply. Do you think these are required for any Python
>> programmer?
>>
> Since many of there will disappear in Python 3 it might be OK to omit
>
On Sun, 13 Aug 2006, anil maran wrote:
> when someone clicks it i need to maintain read status for it
Hi Anil,
You've giving some "use case" information, which is useful. Can you also
give us some definitions? Are you saying that an rss entry is some data
with an associated 'read' status?
> It kinda depends what your thread is doing, and what technique you are
> using to keep it alive, but one possibility is to do something like:
>
> class Worker(threading.Thread):
>def run(self):
>self.running = True
>while(self.running):
># do stuff
>
>def st
>> i want to get the favicon.ico from the URL when a blog is added to
>> the aggregator
>
> I have no idea what this means.
Anil is referring to an icon image file that's often associated with web
sites:
http://en.wikipedia.org/wiki/Favicon
The Python Imaging Library (PIL) should be able
> #def strongfac(z,w):
[function body cut]
Ok, let's go through this step by step.
* What is the intent of strongfac?
* What are the inputs? What is 'z', and what is 'w'?
* What are the outputs? What is the return value of strongfac?
Same questions for fermat(). What are th
> hello is there a way if a condition is not met to restart the whole
> program? for example if and if statement returns true then re start the
> whole program?
Question before we go on: why are you trying to do this?
It's possible to do this, but it sounds so unusual that I want to know
more
-- Forwarded message --
Date: Thu, 17 Aug 2006 09:44:40 -0400
From: Amadeo Bellotti <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] (no subject)
Mr. Yoo im working on a program to write a sudoku puzzle and if something is
wrong with the las
> Mr. Yoo im working on a program to write a sudoku puzzle and if
> something is wrong with the last row i need to re make the whole puzzle
> over again.
Hi Amadeo,
In the future, please use the "Reply to All" feature of your email client,
so that we can keep the conversation on the mailing li
>> > Mr. Yoo im working on a program to write a sudoku puzzle and if
>> > something is wrong with the last row i need to re make the whole puzzle
>> > over again.
>> Here's a separate question that's related to the first: can you write a
>> function that asks the user to enter a word, and contin
> Suggest an alternative way of transmitting code.
Hi Kermit,
Try sending the code as a file attachment. It's large enough that we want
to make sure it goes through without being messed up, but small enough
that it can still be posted to the list.
Alternatively, post the code on the web somew
> To try to find factors of z, using w.
>
>
> * What are the inputs? What is 'z', and what is 'w'?
>
> **
>
> z is the number to be factores.
>
> w is a "witness", a number that may help find the factors of z.
[My apologies in advance; this message is a bit long.]
Hi Kermit,
Ok, goo
> thank you Mr. Johnson this is my first program so its a little sloppy. I'm
> using gedit ill check out the other editors that u have thank you
More fundamentally, spend some time to learn about functions; they'll
address much of the original concerns you had. See any of the tutorials
on:
utor"@python.org
Subject: Making it easier to discuss programs
From" Danny Yoo
/*Date:*/ 08/17/06 12:16:16
To: Kermit Rose
/*Cc:*/ Luke Paireepinart <mailto:[EMAIL PROTECTED]>; tutor@python.org
<mailto:tutor@python.org>
/*Subject:*/ Re: [Tutor] All of Kermit's E-Mails
>
# face = [x,y,0]
>>> [some code cut]
# face[0] = x
# face[1] = y
# face[2] = 0
>
> I agree. I reasoned as follows.
>
> The root cause is that Python is not returning the correct value of a list.
>
> So before I return the list, I will remind Python what's in the list.
Hi Kermi
On Thu, 17 Aug 2006, josip wrote:
> Hi, I want to solve thi question, but I don't know how
[homework question cut]
This is homework; our policy is not to give much help on this, as it's
your work to do. Do you have any specific questions? Otherwise, all I
can do here is point you toward i
On Thu, 17 Aug 2006, Alan Gauld wrote:
>> i m trying to build a webapplication, i need to cache db records as it
>> has become very slow the sql queries and retrival can you guys helpe me
>> out in designing cache structures/ hash tables for these cases
I second Alan's suggestion: talk to you
> I'm not so sure Danny, figuring out how to draw the letters in the
> banner is not obvious after having read a hello-world program example.
> There are some tricky-ish aspects to this one.
Hi Alan,
It's simpler than that: the homework states that the message is hardcoded
to show either josip
> to be able to retrieve informations from man pages, specially existing
> options and their help strings. Do you know a good way to handle this? I
> could parse directly the troff sources (is there already a parser for that?)
Hi Tiago,
Someone else has done this already. *grin* Check out ESR's
> i did it.
Cool; I'm glad to see that you could do it.
[code cut]
Yes, it's mostly an exercise for you to get comfortable using multiple
statements. Personally, I think your instructor should have made the
first assignment something dealing with expressions rather than print
statements, bu
> def handler(event):
> if buttonpressed == 1 :
> /#if the mousebutton is pressed and moved, circles should
> appear, but they do not/
> can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r,
> fill="orange")
> lab.config(text='buttonpressed=' + str(bu
On Thu, 24 Aug 2006, mike viceano wrote:
> hello i need a little help with a common multiple module i am haveing
> problems with the best i can get it is to show the least common multiple i
> think the problem is eather the and command ot the if command
[question cut]
Mike, you asked this ques
On Thu, 31 Aug 2006, �yvind wrote:
I have a database where I have some IP-ranges. Then I have some logs
over IPs from customers and need to connect the two.
So, for example:
Range 1:
123.132.122.4-123.132.122.255
Hello,
You might want to consider using tuple comparison. For example:
##
>> I just got into high school, and the network and all the computers
>> aren't secure at all...I'm trying to make a program that password
>> protects the computer after an inactivity time, but there are some
>> specific things I can't find how I'm supposed to do it.
>
> Windoze has this feature
>> random.seed() sets the starting number for the generator. Setting the
>> seed to a known value can be important if you want the same sequence of
>> pseudorandom numbers to be generated each time you test/run your
>> program.
>>
> I still can not understand. can you show me an example?
Hi Lin
> So, what if one has to map a string of 15 character nucleotide to a
> jumbo string of characters of length in millions.
Hi Srinivas,
If you're doing research into this, I strongly recommend you take a look
at Dan Gusfield's excellent textbook "Algorithms on Strings, Trees, and
Sequences":
On Tue, 5 Sep 2006, John Fouhy wrote:
>> When i'm executing it i get this error (runtime)
>>
>> Traceback (most recent call last):
>> File "C:\python\boa\backup\backupwin.py", line 135, in OnStartaButton
>>config = open("backup.conf", "r")
>> TypeError: an integer is required
I agree with
>> I have to store and retrieve text files from a database table and the
>> size of each file is about 500k. Can someone give me an idea on how to
>> do this?
>>
>> Thanks,
>> Patricia
> http://dustman.net/andy/python/python-and-mysql
> Provides some background for the MySQLdb module. This shou
Hi Dick,
I'm looking at the last part of the main() function:
#
def main():
while True:
...
again()
if again:
break
#
This looks a little suspicious. What does the again() function do, and is
it supposed to return a v
>> I'm looking at the last part of the main() function:
>>
>> #
>> def main():
>> while True:
>> ...
>> again()
>> if again:
>> break
>> #
>>
>> This looks a little suspicious. What does the again() function do, and
>>
>> some more people are looking for a mnemonic-language which should
>> optimized cross-compile to something with multiplatform-capability like
>> Java. Please let me know, if I am entirely wrong.
>
> I'm not really sure what you are asking. Many people find Python to be
> useful and enjoyable fo
> terribly slow. Doclifter itself take around a second to parse the troff
> file, but my few lines of code take 25 seconds to parse the resultant
> xml. I've pasted the code at http://pastebin.ca/166941 and I'd like to
> hear from you how I could possibly optimize it.
Hi Tiago,
Before we go an
> Gee, Danny, it's hard to disagree with you when you quote me in support
> of your argument, but...the characters() method is probably called only
> once or twice per tag, and the string is reinitialized for each tag. So
> this seems unlikely to be the culprit.
Ah, didn't see those; that'll
> Does python have foreach loops? I don't see any mention of them in the
> docs. Am I going to have to use Perl (gasp!) if I want my beloved
> foreach loop?
Can you show an example of a Perl foreach loop? Perhaps someone can help
translate it into idiomatic Python.
Good luck!
On Wed, 13 Sep 2006, anil maran wrote:
>
> i was trying to display some text it is in utf-8 in postgres and when it
> is displayed in firefox and ie, it gets displayed as some symols with
> 4numbers in a box or so even for ' apostrophe please tell me how to
> display this properly i try title
> I came across the following and wondered if anyone had followed up on this
[old message follows:]
>> I just ran into the following link; it's a tutorial on writing
>> adventure games (circa 1983):
>>
>>http://www.atariarchives.org/adventure
>>
>> Would anyone be interested in "porting" t
On Tue, 19 Sep 2006, [EMAIL PROTECTED] wrote:
> so, how register(?) all imported modules to convert all unicodes to
> str() with a coder, for eg. encode('cp1251')
Hi Emilia,
Unfortunately, this isn't so clean: changing the systemwide
default encoding may cause things to break. See:
ht
>query1 = """SELECT ABC FROM %s limit %s,%s"""\
> % (self.tableid,self.rangeid1,self.rangeid2)
Just as a note: please don't do this! *grin*
Don't build query strings up like this: this is very prone to an SQL
injection attack. See:
http://mail.python.org/pipe
> Was talking to my partner about this. He's a perl programmer, and he
> told me that (if I understood him correctly) that the programmer is
> required by perl to use the 'prepare' function in the perl DBI prior to
> sending a select statement.
Hi Tim,
Yes. That being said, Perl's prepare() s
On Mon, 25 Sep 2006, max . wrote:
> hello i cant understand how to open text files with python
> i have tried tutorials and evrything i just cant get pleas help
Hi Max,
Which tutorials are you trying? Have you looked at:
http://www.freenetpages.co.uk/hp/alan.gauld/
There's a whole sect
> my_file = open('c:\\path\to\file\file.txt', 'r')
> my_file.readlines()
> my_file.close()
>
> Really, it's so simple it's hard to come up with directions.
Hi John,
In that case, we have to figure out why Max is getting stuck: it's not
obvious at all at what step he's getting confused. Let's co
-- Forwarded message --
Date: Mon, 25 Sep 2006 16:46:02 -0600
From: max . <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] opening files
ok srry i will give a bit more info
i am working on a new mac mini :))
im still pretty new to python so
> im still pretty new to python so allmost all my programs are math stuff
> and i would like to start writing more complex programs i know a bit
> about functions and strings
Hi Max,
Just to clarify: you can do a lot with Python even without using files.
Take a look at Alan Gauld's tutorial, f
> I'm wondering if there isn't a way to get at what seems to be the
> list of unique elements set() seems to produce.
Here you go:
#
>>> list(set(['e', 'q', 'r', 't', 'w', 'y']))
['e', 'q', 'r', 't', 'w', 'y']
###
> What I am looking for is a book thats:
>
> 1) simple, and fun enough so that he can learn from it without my
> continous assistence. (Of course, I can answer questions, but the idea
> is that I don't want to walk him through all of it.)
>
> 2) doesn't look like it is teaching programming -- it sh
> I am searching for monte carlo and two- person game, also monte carlo
> statistical ampling distribution. Thanks.
Hi William,
Ok... so what do you need help in?
If you're asking how to do research on those subjects, we're probably not
the best people to ask. This group is dedicated to helpi
> for example, I want to mutate part of a list, of course, I can achieve
> this by passing the pair list and (begin, end) as parameters. but in
> some case, this manner is quite tedious and in efficient
I'm not sure what you mean by "inefficient". What do you think a
"pointer" is, if not wha
>> I feel
>> 7/3 should give -2
>>
>> since integer divison returns floor
>
> The floor is the next lowest integer to the float.
> floor(-3.1) will be -4
> floor(3.) will be 3
Hi Joseph,
If it helps, draw out the floor function out on a piece of graph paper.
^
I am stuck.. Please help me with implementing two dimensional array
in Python.
Hi Asrarahmed,
What do you need a two-dimensional array for? This is a serious question:
what's your application? What are you trying to represent, and why?
As a glib possible answer: you can use a di
> You really aren't doing much so there's not a lot to optimize that I can
> see. You could try asking on comp.lang.python, lots of people there are
> good at optimization.
** spoiler space: don't read ahead here unless you've attempted this
problem already, or if you don't want to be spoiled
> >>> for x in xrange(2**31):
> pass
>
> Traceback (most recent call last):
> File "", line 1, in
> for x in xrange(2**31):
> OverflowError: long int too large to convert to int
Hi Dick,
Hmmm... I'd consider this a misfeature in the implementation. Apparently
xrange (and range) mus
> 1) More tutors so more chance of one finding an explanation you
> understand
Another advantage that can't be overstated is that of checks-and-balances:
if any one of the tutors here gives erroneous advice, the other tutors
here will provide error-correction. (I've had this happen for mysel
>> Date: Thu, 12 Oct 2006 01:46:44 -0700 (PDT)
>> From: anil maran <[EMAIL PROTECTED]>
>> Subject: do you know how to do this
>> To: Alan Gauld <[EMAIL PROTECTED]>
>>
>> The user, password and group are stored in a session on disk using
>> flup.middleware.session. You can change this to fit your n
On Thu, 12 Oct 2006, Michael Shulman wrote:
> I'd like to make a scrolling background for a game I'm working on. I
> was thinking, since it's all in orthographic view, that a horizontal
> cylinder which rotates with a texture would simulate this very well.
I have to admit I'm clueless about p
> Here is the problem:
>
> I get 'float' object not callable error.
Hi Kristinn,
Ah. Ok. The problem is a notational one. You're reusing notation that
you've learned from your math classes, that is, that:
a b
informally represents the multiplication of numbers 'a' and 'b'.
Furthermor
On Thu, 12 Oct 2006, Amadeo Bellotti wrote:
> I am currently interseted in learning tkinter and what beeter way then
> with a project so im making a python IDE and i was wondering if there
> were any good tutorials that are out there for tkinter and a book or 2
> would be nice thank you
Joh
> a login page that takes a username and password, checks it against a
> database, and then sets a cookie of (hash(secret,user, time),user,time).
Hi Anil,
Ok, separate the concerns about where the inputs are coming from. It will
seem weird, but just for the moment, forget completely about the
>
> while not done:
>str = raw_input("Enter login name:\t to quit type 'q': ")
>if str == 'q':
> done = 1
>else:
> str = str + '\n'
> fd.write(str)
Hi Asrarahmed,
What's 'fd'? Where is it defined?
(I have a guess, but I'd rather that you show where fd is being defi
>> What makes you think so?
>>
>> >>> s = 'l'
>> >>> s += '\n'
>> >>> s
>> 'l\n'
>> >>>
>>
>> Seems to work '\n' is just a character like any other.
>
> The issue was to have a newline or return character after every string,
> Here it is just iterpreted as \n alphabet., but not as a return
> fname = raw_input("Enter the file name to write data to:\t")
>
> fd = open(fname,'a+')
> print fd
> done = 0
Ok, good, that helps a lot: that's exactly what we need to diagnose the
problem. There appears to be something funky that happens with
append-plus mode. This problem has come up befor
>> Yes, you are right; the code isnt working for 'abcdba';
>> So what should I do to rectify it.
>
> Try walking through the code by hand so you understand why it is
> failing. Then maybe you can figure out how to fix it. It's important to
> learn to find and fix errors yourself.
Hi Asrar,
On
> Is there a way to say :
> for filename in zfile.namelist() contains '.txt, .exe':
Hi Chris,
Yes. It sounds like you want to filter zfile.namelist() and restrict the
entries to those with particular extensions. Try a "list comprehension"
to filter for those interesting filenames:
for fil
On Mon, 16 Oct 2006, Chris Hengge wrote:
> Have you even read my code to see if you find it cryptic? I'm starting
> to beleive people just read the one comment on possibly using better
> naming conventions and assumed I had picked completely irrelivent names.
Hi Chris,
Sometimes one of us (o
> I am trying to write to a file, but I am getting this errror.
>
> IOError: (0, 'Error')
>
> Can someone explain what is it and whats the solution??
Hi Asrarahmed,
Did you read my response from the last few days?
http://mail.python.org/pipermail/tutor/2006-October/049958.html
Did you find
> I remove those lines, but I was trying to use
> for line in contents:
> result = re.search("something", line)
> print result
'result' here is going to either be None, as you've seen, or a "match"
object. We have several options available to use once we have a
match. Take a look at a fe
-- Forwarded message --
Date: Mon, 16 Oct 2006 14:19:53 -0700 (PDT)
From: anil maran <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: followup on python cookies/sessions
Dear Danny
My login code looks like this for session and cookie i dont know ho
On Mon, 16 Oct 2006, kumar s wrote:
> I have a simple question to ask tutors:
>
> list A :
>
> a = [10,15,18,20,25,30,40]
Hi Kumar,
If you're concerned about correctness, I'd recommend that you try thinking
about the problem inductively. An inductive definition for what you're
asking is st
On Wed, 18 Oct 2006, kumar s wrote:
> I am not sure if I got your opinion about the way I solved.
Hi Kumar,
I was replying to your question:
http://mail.python.org/pipermail/tutor/2006-October/050064.html
in which you showed a program that had problems. I'm assuming that you
haven't f
On Thu, 19 Oct 2006, Asrarahmed Kadri wrote:
> I want to extract the last line of the text file. Any idea ???
Hi Asrarahmed,
Ok, so what part do you get stuck on when you try to do this? That is,
what sort of things do you already know how to do with files?
__
> first count the number of lines in the file by using a loop. Use a
> second loop and when teh counter reaches the num_of_lines values: take
> the line.
>
> Is there any other way to do it??
Yes, there's a way to do it in one pass: you can keep track of the very
last line you've read from the
>> file('filename.txt').readlines()[-1]
> Not to hijack the thread, but what stops you from just putting a
> file.close() after your example line?
Which file should file.close() close? The problem is that we don't have a
handle on the particular file we want to close off.
___
> This works as well
>
> file('filename.txt').readlines()[-1]
>
> Some will say that this is no good because the file is still open.
> However I've been told that when the object is cleaned the file is
> closed so it should be fine.
It matters in an implementation like Jython, which depends on t
>> >> file('filename.txt').readlines()[-1]
>>
>> > Not to hijack the thread, but what stops you from just putting a
>> > file.close() after your example line?
>>
>> Which file should file.close() close? The problem is that we don't
>> have a handle on the particular file we want to close off
1101 - 1200 of 2125 matches
Mail list logo