Hi,
I couldn't get idea how to make the next thing
>>> n=4 #split into so long parts
>>> l = (1,2,3,4,5,1,2,3,4,5,1,2,3,4,5) #this is the tuple to split
>>> [l[i:i+n] for i in range(0,len(l),n)]
[(1, 2, 3, 4), (5, 1, 2, 3), (4, 5, 1, 2), (3, 4, 5)]
But I have to make it like this
[(1, 2, 3, 4),
So far this is what I have come up with doing some research.
import urllib
for line in urllib.urlopen('http://mywebsit.com/folder/folder/test.asp'):
if '400 Bad Request' in line:
text_file = open("mysite.log", "a")
text_file.writelines(line)
text_file.writelines("\n")
text_file.close()
Hi,
I just started learning Python and would like to try writing a monitoring script.
What I would like to do is use Telnet to send a GET via port 80 to a status page in a directory to verify my site is up.
Psuedo code:
Connect = telnet website.com 80
Send = GET /folder/folder/test.asp HTTP/1.
> Just to be able to talk about things, let's give a name to the global
> namespace as: "G".
>
> Whenever we call a function, we build a new environment that's chained up
> to the one we're in at the time of function construction. This
> corresponds to what people's ideas of the "stack frame" is.
> The original solution does use a closure. The problem is that variables
> are not bound into a closure until the scope of the variable exits. That
> is why using a separate factory function works - the closure is bound
> when the factory function exits which happens each time through the
> loop.
> Are they class attributes - shared by all instances of the class or are
> they instance attributes - unique values in each instance?
all instances of the class share these attributes.
> So you have a list of all the instances of the class and modifying values.
> Since you do it on a per insta
Christian Wyglendowski wrote:
>>-Original Message-
>>From: [EMAIL PROTECTED]
>> If I have this code:
>> Obviously, the lambda is using "value" at the end of the loop (4),
>>rather than what I want, "value" during the loop (0,1,2,3).
>
> Right. I think the issue is that your lambda ca
> I have a class with attributes
Are they class attributes - shared by all instances of the class or are
they instance attributes - unique values in each instance?
> I am now going back through my object list of that
> class
So you have a list of all the instances of the class and modifying val
Eric Walker wrote:
> ahh, you just blew smoke in my face. :)
>
> I have a class with attributes. These attributes eventually have the value of
> some lines in a file. I am now going back through my object list of that
> class and assigning values to the attributes depending on another variable
On Wed, 16 Nov 2005, Bernard Lebel wrote:
> Let say I have a list of lists. Each individual lists have a bunch of
> elements. Now I would like to either get or set the first element of
> each individual list. I could do a loop and/or list comprehension, but I
> was wondering if it was possible w
> But as soon as I introduce the [0], in an attempt to access the first
> element of each sublist, I get the first sublist in its entirety:
>
aList[:][0]
> [1, 1, 1]
aList[:] is the shorthand way of taking a copy of aList thus
aList[:][0]
is the same as saying aList[0] except you get a new
def doLambda(val):
print "value 2:", val
commands = []
for value in range(5):
print "value 1:", value
commands.append(lambda:doLambda(value))
Close but not quite. Try:
commands.append(lambda v=value:doLambda(v))
value is a local variable in doLambda
Alan Gauld schrieb:
> Thanks, I may use that as one of the example programs if
> you don't mind?
I took the liberty of refactoring Johan's example a bit, to make it more
reusable. See attached file.
Chris
"""Wrapper object for external commands, that allows to kill them after later..
::Author
ahh, you just blew smoke in my face. :)
I have a class with attributes. These attributes eventually have the value of
some lines in a file. I am now going back through my object list of that
class and assigning values to the attributes depending on another variable
that will change and be the s
>
> def doLambda(val):
>print "value 2:", val
>
> commands = []
> for value in range(5):
>print "value 1:", value
>commands.append(lambda:doLambda(value))
>
> for c in commands:
>c()
Hi Fred,
Ah, this one of those unfrequently asked questions.
> markersExp = ['big','boss','two','three']
> for mark in markersExp:
> print y.mark
>
> Now I have an list of class objects that are in an outerloop. y is how I
> access it. The attributes names of the class objects match whats in
> markersExp.
Do you have to use string versions of the cl
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Fred Lionetti
> Sent: Wednesday, November 16, 2005 2:32 PM
> To: tutor@python.org
> Subject: [Tutor] lambda in a loop
>
> Hi everyone,
Hello,
> If I have this code:
>
> ---
On 17/11/05, Alan Gauld <[EMAIL PROTECTED]> wrote:
> At a guess you forgot to pack() the menu? Thats usually whats wrong
> when widgets fail to appear as expected! :-)
You don't pack() menus --- you attach them to a Tk() or a Toplevel()
by calling .config() with the menu= option (like in Michael's
Hi Bernard,
You can do this with Numeric (http://numeric.scipy.org/)
import Numeric
aList = [ [1,1,1], [2,2,2,], [3,3,3] ]
bList = Numeric.array(aList, "i")
print bList[:,0]
displays->
[1 2 3]
you can convert the array back to a list if you want like this:
bList.tolist()
so...
result = Numeri
Thanks. It works.
Thanks for simplifying it in list comprehension.
Srini
--- Liam Clarke-Hutchinson
<[EMAIL PROTECTED]> wrote:
> Does this work? (I can't check)
>
> listX = ['933\t957', '955\t979', '969\t993',
> '1025\t1049', '1052\t1076',
> '1098\t1122', '1136\t1160', '1298\t1322',
> '1406
Does this work? (I can't check)
listX = ['933\t957', '955\t979', '969\t993', '1025\t1049', '1052\t1076',
'1098\t1122', '1136\t1160', '1298\t1322', '1406\t1430', '1422\t1446',
'1471\t1495']
listY = [ tuple(item.split("\t")) for item in listX]
tupleY = tuple(listY)
Liam Clarke-Hutchinson| Contact
Hello,
I am wondering if can do this:
Let say I have a list of lists. Each individual lists have a bunch of elements.
Now I would like to either get or set the first element of each
individual list. I could do a loop and/or list comprehension, but I
was wondering if it was possible with something
> version 2.3. I do get a root window, but it is totally blank
> without the desirable menubars such as File and Edit. What am I
> missing?
At a guess you forgot to pack() the menu? Thats usually whats wrong
when widgets fail to appear as expected! :-)
Alan G.
__
Thanks, I may use that as one of the example programs if
you don't mind?
Alan G.
- Original Message -
From: "Johan Geldenhuys" <[EMAIL PROTECTED]>
To: "Alan Gauld" <[EMAIL PROTECTED]>
Cc: "Python Tutor list"
Sent: Wednesday, November 16, 2005 8:12 AM
Subject: Re: [Tutor] new topic draf
Dear all,
Pardon me for asking a simple question. Sometimes
brain gets blank and compells me to seek help from
tutors.
I have a list :
>>>prcor
['933\t957', '955\t979', '969\t993', '1025\t1049',
'1052\t1076', '1098\t1122', '1136\t1160',
'1298\t1322', '1406\t1430', '1422\t1446',
'1471\t1495']
>
Hi everyone,
If I have this code:
def doLambda(val):
print "value 2:", val
commands = []
for value in range(5):
print "value 1:", value
commands.append(lambda:doLambda(value))
for c in commands:
c()
--
my output
Kent Johnson schrieb:
>>And somewhere docutils belongs on that list, but i don't know where. Maybe
>>source code documentation? But then you'd probably have to list epydoc,
>>gendoc,
>>etc. as well.
>
>
> I think this page will be more useful as a list of favorites or things that
> beginners mi
Eric Walker wrote:
> Hello,
> If I have some like the following:
>
> markersExp = ['big','boss','two','three']
> for mark in markersExp:
> print y.mark
>
> Now I have an list of class objects that are in an outerloop. y is how I
> access it. The attributes names of the class objects match w
Hello,
If I have some like the following:
markersExp = ['big','boss','two','three']
for mark in markersExp:
print y.mark
Now I have an list of class objects that are in an outerloop. y is how I
access it. The attributes names of the class objects match whats in
markersExp. Can I do that pr
Hi Michael,
Thank you very much for the help.
I tried the simpler code you provided, but unfortunatly I still
got a blank window without any trace of menubars.
Any other insights?
Thanks,
Joe
from Tkinter import *
root = Tk()
menubar = Menu(root)
menu = Menu(menubar, tearoff=0)
menu
[EMAIL PROTECTED] wrote:
> What I don't understand is
>>>import Tix
>>>
>>>def raise_exception():
>>> print 1/0
>>>
>>>if __name__ == '__main__':
>>>root = Tix.Tk()
>>>root.title("Exception demo")
>>>
>>>Tix.Button(root, text = "Don't press", command =
>
> raise_exception).pack()
>
On Tue, Nov 15, 2005 at 09:10:33PM -0200, Ismael Garrido wrote:
> Hi
>
> Does anyone know if there's any module able to download rtsp?
> Failing that, any command line app that could do the job? (Already tried
> with mplayer, it didn't work)
$ mplayer rtsp://ravi.br-online.de:5050/ravi/alpha/cent
On Wed, 16 Nov 2005 10:55:24 +0100 (MET)
[EMAIL PROTECTED] wrote:
Hi Karsten,
> I thought the mainloop() function is something like
>
> def mainloop():
> e= get_event()
> if e:
> for w in widgets: w.handle(e)
>
> but apparently it is not.
>
> It's not bad that the Tkinter windows don't
On Tue, 15 Nov 2005 16:17:53 -0500
Double Six <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am testing the following Tkinter code (attached at the end of
> this message) by Fredrik Lundh on a Mac OS X 10.4.2 with Python
> version 2.3. I do get a root window, but it is totally blank
> without the desirab
On Wed, 2005-11-16 at 16:19 +0700, fade2blac wrote:
> Hi All,
> Is there any trick to either not echo or obscure password from raw_input()
> function?
>
Yes, try this:
import getpass
password = getpass.unix_getpass("Enter your password:")
print password
--
Jan Martinek
> --
> fade2blac
_
Hello Michael, hello list,
thanks for the info that pmw displays exceptions.
What I don't understand is
>> --- snip ---
>> import Tix
>>
>> def raise_exception():
>> print 1/0
>>
>> if __name__ == '__main__':
>> root = Tix.Tk()
>> root.title("Exception demo")
>>
>> Tix.Button
Hi All,
Is there any trick to either not echo or obscure password from raw_input()
function?
--
fade2blac
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Alan,
You may remember that I asked questions on killing a process, a while back,
Sice this is relatedto the tutorial that yu are writing, this was the
best solution that worked for me to killa process for a command that
keeps on running like eg. 'tcpdump'.
HTH
Johan
BTW, There will a be ma
38 matches
Mail list logo