Re: [Tutor] question about socket status

2008-07-24 Thread Monika Jisswel
if networking code is inside of the kernel then its from the kernel that you
can get network information & nowhere else.
(http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html)

I would just add that to see what netstat does simply use "strace netstat"
it will probably tell you the interesting files it reads when run.


2008/7/23 arsyed <[EMAIL PROTECTED]>:

> On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine <[EMAIL PROTECTED]>
> wrote:
> > Hello,
> >
> > I am new to programming with python and sockets.
> >
> > I would like to determine the status of a socket as it  is returned when
> you
> > do 'netstat –a | grep '.  I would like  to know if the socket
> state
> > is ESTABLISHED, LISTEN , CLOSE_WAIT, etc.
> >
> > Is there a way to get this information through a socket call?
> >
> > I've tried using socket.getperrname() function, but that only tells if
> there
> > is a connection.
> >
> > Is there a way to get more information on the state of the socket
> > connection?
> >
>
>
> If you're on linux, you could try poking around /proc/net. See, for
> example:
>
> http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
>
> But I think invoking netstat and parsing the output from python might
> work well enough.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread Andreas Kostyrka
On Wednesday 23 July 2008 22:04:57 Alan Gauld wrote:
> ""Simón A. Ruiz"" <[EMAIL PROTECTED]> wrote
>
> > If what you expected was something like:
> >
> > Hello World!
> > Here are ten numbers from 0 to 9
> > 0 1 2 3 4 5 6 7 8 9 Goodbye World!
> >
> > Then you want that final print statement to not be included in your
> > for loop block; i.e., unindent it:
>
> And if you wanted the Goodbye on a separate line add a
> newline character('\n') in front of the text:
>
> for i in range(10):
>  print i,
> print "\nGoodbye World!"
>
> You now have at least 3 options to pick from :-)

One another *g*

print " ".join(str(x) for x in range(10))
print "Goodbye World!"

Which has the "benefit" of not printing a space after the 9.

explanations:

str(x) converts the integers to strings.
str(x) for x in range(10) is basically a generator that 
generates "0", "1", ..., "9"

" ".join(expr) joins the strings given by expr by " ".

It's basically a very useful idiom when you need to generate
seperators without outputing the seperator at the end.

In other languages, you often have a loop like this:

for elem in list:
print elem
if is_not_last_element:
print seperator

That is most often best solved in Python by using the " ".join(values) idiom.

Andreas


signature.asc
Description: This is a digitally signed message part.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Online class/education for Python?

2008-07-24 Thread Danyelle Gragsone
>
>
> You should be able to use the 1st edition of PPftAB to learn Python.
> Pre-2.2 might have caused some minor problems, but 2.2 is okay.
>
> If you run into any problems, just post your problem code to the list,
> with your platform info (GNU/Linux, Mac OS X, MS-Windows...) and
> the version of Python you are using.
>
> One thing I found that might be useful to you when you get close to
> the end of the book: the version of LiveWires Dawson uses has been
> customized, and needs to be installed for the Pizza Panic game, and
> the Asteroid games to work properly. I already had LiveWires installed,
> and didn't think I needed to re-install his version. However, I couldn't
> get those games to work until I installed the version of LiveWires that
> he includes on the CD in the back of the book.
>
> Hopefully helpful?
>
>
Yes very much so!.  I will keep that in mind when i get to the end.
*hopefully* I get to the end.  I am  also going for my A+  so my schedule
with work and my volunteering  at the fire house is tight!

Thanks!
Danyelle
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Check for file in different dirs

2008-07-24 Thread Timo
I want to check for a file in 3 directories. If the file is found in 1 
of the dirs then do something, if the file was found in 2 or 3 dirs, 
then do something else. I know the paths and filename. How can this be done?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Check for file in different dirs

2008-07-24 Thread bob gailer

Timo wrote:
I want to check for a file in 3 directories. If the file is found in 1 
of the dirs then do something, if the file was found in 2 or 3 dirs, 
then do something else. I know the paths and filename. How can this be 
done?


We like to give a hand and prefer not to write programs.

So I suggest you write as much of the program as you can, then show it 
to us and tell us where you are stuck. I assume you have enough Python 
knowledge to get a start. If you are new to Python then at least present 
a program design.


Take a look at the os.path module and its exists function. That is what 
you use to see if a file exists.


--
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Check for file in different dirs

2008-07-24 Thread Alan Gauld

"Timo" <[EMAIL PROTECTED]> wrote

I want to check for a file in 3 directories. If the file is found in 
1 of the dirs then do something, if the file was found in 2 or 3 
dirs, then do something else. I know the paths and filename. How can 
this be done?


Lots of ways but one is to write a predicate function that checks if
a file is in a directory:

def inDirectory(fname, dirname):
# your code here returns 1 = True/0 = False

count = inDirectory(fname, dir1) + inDirectory(fname,dir2) + 
inDirectory(fname,dir3)

if count == 1:  # do something
elif 2 <= count <= 3: # do another
else: # file not found

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Assistance!

2008-07-24 Thread yla116
Hi, this is my first time come to this website to ask about python question.
I'm totally don't know how to do my last assignment.It is distance education
class, and my taxt book DOES NOT show exactly information for me to do this
assignment.
There is my assignment,
http://cmpt165.cs.sfu.ca/~ggbaker/examples/chequebook.html

I feel so helpless when I doing this assignment

Could you teach how to start and end this assignmet?

I try to write something about password but I still don't have any idea.

Here is some codes which I try to write
 import pickle
filename = "cheques.data"

# print HTTP/HTML header stuff
print """Content-type: text/html

http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>

Chequebook


Chequebook"""

# print HTML body using form data
password = int(form["password"].value)
x = int(form["steps"].value)
if x="165":
 show all data
else:
print "wrong password"

import chequelib
data = chequelib.read()
data[0][0] = 0,data[0][1] = 250.0, data[0][2] = "blance"
data[1][0] = 1,data[1][1] = -12.34,data[1][2] = "chips & gum"
data[2][0] = 2,data[2][1] =-345.12,data[2][2] = "dentist" 

These data I follow 
http://www.cs.sfu.ca/CC/165/ggbaker/assign-1/files/cheques.data

Please, help me to do this assignment.

Thank you 

Lucia LEE
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assistance!

2008-07-24 Thread Danny Yoo
On Thu, Jul 24, 2008 at 12:54 PM,  <[EMAIL PROTECTED]> wrote:
> Hi, this is my first time come to this website to ask about python question.
> I'm totally don't know how to do my last assignment.It is distance education
> class, and my taxt book DOES NOT show exactly information for me to do this
> assignment.

[assignment cut]

This is out of bounds of the the academic honesty policy of your institution.

http://www.sfu.ca/policies/teaching/t10-02.htm
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Assistance!

2008-07-24 Thread Alan Gauld

<[EMAIL PROTECTED]> wrote

I'm totally don't know how to do my last assignment.It is distance 
education


We don't do homeworks but we can offer suggestions and advice.
However you will need to solve the problem yourself.


There is my assignment,
http://cmpt165.cs.sfu.ca/~ggbaker/examples/chequebook.html


I'm not sure how that's supposed to work. The data I got didn't seem
to add up correctly!


I feel so helpless when I doing this assignment
Could you teach how to start and end this assignmet?

I try to write something about password but I still don't have any 
idea.


So what did you write about the password?
I don't see any of it below. What happened? What did you
expect to happen?

Also how are you running these programs? Are you using a web
server or a command line console? Do you have to produce web
page output or can you use the command window (which is much
easier)


Here is some codes which I try to write


The code implies that you are using a web environment but you
do not import the cgi module which is normally required to process
HTML forms.

Can you describe what you think you are being asked to do?
And ideally how you were planning on going about it?
Also how much background do you have in programming?
In Python? And which OS etc are you using?

Lots of questions but we need to know that stuff before we
can give you sensible answers.

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newbie

2008-07-24 Thread Sam Last Name
mmmkay its me again
Iv'e been learning alot and have found so much joy in making programs that 
solve equations using the input function.
I need Help on this though.
Im trying to make a program where it solves the quadratic formula when you put 
in the variables. 
Here wats i got so far. :) and also, is there a function for square root? 

a  =  input("What is the variable a?")
b  =  input("What is the variable b?")
c  =  input("What is the variable c?")
# this is where i need help :(
print -b + /sqrt (b*b - 4*a*c)/(2*a) 
# this of course doesn't work i believe because i don't have the square root 
function and don know how to make one

Feedback appreciated :)


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread John Fouhy
On 25/07/2008, Sam Last Name <[EMAIL PROTECTED]> wrote:
> Here wats i got so far. :) and also, is there a function for square root?

Have a look at the math module.

(you can also do fractional exponentiation.. remember, sqrt(x) is the
same as x**0.5)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread John Fouhy
On 25/07/2008, Sam Last Name <[EMAIL PROTECTED]> wrote:
>
> Okay thanks still didnt get it working but one step closer. Take a look at
> this
>
>
> a = input("What is the variable a?")
> b = input("What is the variable b?")
> c = input("What is the variable c?")
> print -b + [((b*b - 4*a*c)**0.5)/(2*a)]
> # my new equation thanks to you :)
>
>
> i run the script and here is error message there are 2 messages. i will post
> both.
>
> What is the variable a?2
> What is the variable b?2
> What is the variable c?2
>
> Traceback (most recent call last):
>   File "C:\Python\Script2.py", line 4, in 
> print -b + [((b*b - 4*a*c)**0.5)/(2*a)]
> ValueError: negative number cannot be raised to a fractional power

This is normal; if you want to handle complex numbers you will need to
do a lot more work..

> # i changed the numbers so it would be postive number when squarerooting and
> it worked but then this error popped up :(
>
>
> What is the variable a?2
> What is the variable b?14
> What is the variable c?5
>
> Traceback (most recent call last):
>   File "C:\Python\Script2.py", line 4, in 
> print -b + [((b*b - 4*a*c)**0.5)/(2*a)]
> TypeError: unsupported operand type(s) for +: 'int' and 'list'
>
> # I"m bewildered to what that means. ty for feed back :) this is so i can do
> alegbra2 easily haha.

Different types of brackets mean different things in python.  You
can't just use square brackets instead of round brackets to make it
easier to read :-)  In this case, square brackets indicates a list and
python is complaining that it doesn't know how to add an integer (-b)
to a list ([..]).  I recommend reading through the tutorial on
python.org.

PS.  Please use the reply-all when using this mailing list so other
people can follow the conversation if they wish to.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tutor Newbie

2008-07-24 Thread Sam Last Name
Hey guys, need some info on "programs" :) 


Heres a Very simple Script that works with basically any numbers.


width = input("What is the Width?")
length = input("What is the Length?")
area = width*length
print area
 # my question is what would it take (programs, extra stuff in script, ect..) 
to make this a nice looking usable desktop program?



  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread jar_head

> --
> 
> Message: 9
> Date: Thu, 24 Jul 2008 18:47:32 -0700 (PDT)
> From: Sam Last Name <[EMAIL PROTECTED]>
> Subject: [Tutor]  Newbie
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="us-ascii"
> 
> mmmkay its me again
> Iv'e been learning alot and have found so much joy in making programs that 
> solve equations using the input function.
> I need Help on this though.
> Im trying to make a program where it solves the quadratic formula when you 
> put in the variables. 
> Here wats i got so far. :) and also, is there a function for square root? 
> 
> a  =  input("What is the variable a?")
> b  =  input("What is the variable b?")
> c  =  input("What is the variable c?")
> # this is where i need help :(
> print -b + /sqrt (b*b - 4*a*c)/(2*a) 
> # this of course doesn't work i believe because i don't have the square root 
> function and don know how to make one
> 
> Feedback appreciated :)
> 

You're going to need to use your parenthesis differently.  You might have a 
problem with the grouping if you leave it as it is.  It'd be better written as 
this:

print (-b + /sqrt ((b*b) - (4*a*c))/(2*a))

I don't know the function for square root either, but I'm sure one of the 
others will answer that for you.

-Jay

> 
>   
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> <http://mail.python.org/pipermail/tutor/attachments/20080724/b02787c9/attachment.htm>
> 
> --
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> End of Tutor Digest, Vol 53, Issue 87
> *

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread Steve Willoughby
To answer the specific question about square roots below, Python's 
square root function is in the math module.  You can either include this 
module and invoke it like this:


import math
.
.
.
y = math.sqrt(x)

-or- if you want the sqrt() function brought into your main namespace, 
you can do it like this:


from math import sqrt
.
.
.
y = sqrt(x)

Either way, y will now have the value of the square root of x.

HTH
HAND


[EMAIL PROTECTED] wrote:

--

Message: 9
Date: Thu, 24 Jul 2008 18:47:32 -0700 (PDT)
From: Sam Last Name <[EMAIL PROTECTED]>
Subject: [Tutor]  Newbie
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"

mmmkay its me again
Iv'e been learning alot and have found so much joy in making programs that 
solve equations using the input function.
I need Help on this though.
Im trying to make a program where it solves the quadratic formula when you put in the variables. 
Here wats i got so far. :) and also, is there a function for square root? 


a  =  input("What is the variable a?")
b  =  input("What is the variable b?")
c  =  input("What is the variable c?")
# this is where i need help :(
print -b + /sqrt (b*b - 4*a*c)/(2*a) 
# this of course doesn't work i believe because i don't have the square root function and don know how to make one


Feedback appreciated :)



You're going to need to use your parenthesis differently.  You might have a 
problem with the grouping if you leave it as it is.  It'd be better written as 
this:

print (-b + /sqrt ((b*b) - (4*a*c))/(2*a))

I don't know the function for square root either, but I'm sure one of the 
others will answer that for you.

-Jay

  
-- next part --

An HTML attachment was scrubbed...
URL: 
<http://mail.python.org/pipermail/tutor/attachments/20080724/b02787c9/attachment.htm>

--

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 53, Issue 87
*


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie

2008-07-24 Thread Kent Johnson
On Thu, Jul 24, 2008 at 10:17 PM, John Fouhy <[EMAIL PROTECTED]> wrote:
> On 25/07/2008, Sam Last Name <[EMAIL PROTECTED]> wrote:
>>
>> Traceback (most recent call last):
>>   File "C:\Python\Script2.py", line 4, in 
>> print -b + [((b*b - 4*a*c)**0.5)/(2*a)]
>> ValueError: negative number cannot be raised to a fractional power
>
> This is normal; if you want to handle complex numbers you will need to
> do a lot more work..

The sqrt() function in the cmath module will compute complex square roots.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor