Re: [Tutor] Socket Programming issue

2011-06-21 Thread Alan Gauld


"aditya"  wrote

is that although the Vbscript writes the output to the file 
correctly but
when the client sends the contents of the file to the server via 
socket , it
sometimes prints all the lines of the file on the server and 
sometimes it
doesnt , i dont know whether the issue is with the client or the 
server ,


Use the return values from functions.


CLIENT.PY

import socket
import os
import sys
os.system("C:\Python26\ping.vbs")
host = "localhost"
port= 2
size = 1024

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))

f=open('output.txt','r')
while 1:
data = f.readline()


You could print the data here to check that you got something
meaningful from the file


if data: s.send(data)


The socket documentation specifically says:
-
socket.send(string[, flags])
 Send data to the socket. The socket must be connected to a remote 
socket. The optional flags argument has the same meaning as for recv() 
above. Returns the number of bytes sent. Applications are responsible 
for checking that all data has been sent; if only some of the data was 
transmitted, the application needs to attempt delivery of the 
remaining data.


--
Notice that it tells you how many bytes have been sent, and it
is your responsibility to check and retry if necessary.
I see no check nor any attempt to retry

That should tell you if the data is leaving the client at least.



SERVER.PY
import socket

host = ""
port = 2
size = 1024
backlog=5
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((host,port))
s.listen(backlog)

while 1:
client, addr =s.accept()
data=client.recv(size)
if data:
print data
else:
print  "client exit"


This implies you should always get something printed, do you?
When you say it sometimes prints the lines and sometimes
not, does it print the exit message instead?


s.close()


I'm not clear where this line sits since the mail has lost
its indentation. Is it inside the else or at the while level?

Just some things to c0onsider,

HTH


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket Programming issue

2011-06-21 Thread aditya
On Tue, Jun 21, 2011 at 12:45 PM, Alan Gauld wrote:

>
> "aditya"  wrote
>
>
>  is that although the Vbscript writes the output to the file correctly but
>> when the client sends the contents of the file to the server via socket ,
>> it
>> sometimes prints all the lines of the file on the server and sometimes it
>> doesnt , i dont know whether the issue is with the client or the server ,
>>
>
> Use the return values from functions.
>
>
>  CLIENT.PY
>>
>> import socket
>> import os
>> import sys
>> os.system("C:\Python26\ping.**vbs")
>> host = "localhost"
>> port= 2
>> size = 1024
>>
>> s=socket.socket(socket.AF_**INET, socket.SOCK_STREAM)
>> s.connect((host,port))
>>
>> f=open('output.txt','r')
>> while 1:
>> data = f.readline()
>>
>
> You could print the data here to check that you got something
> meaningful from the file
>
>
>  if data: s.send(data)
>>
>
> The socket documentation specifically says:
> --**---
> socket.send(string[, flags])
>  Send data to the socket. The socket must be connected to a remote socket.
> The optional flags argument has the same meaning as for recv() above.
> Returns the number of bytes sent. Applications are responsible for checking
> that all data has been sent; if only some of the data was transmitted, the
> application needs to attempt delivery of the remaining data.
>
> >Thanks Alan i will put in some conditional checks to check and reattempt
to send the data if it has not been sent or not. besides i am sending you
the client,server, and the output file to just go though it once . You can
run the script for yourself and see what happens.It actually prints only one
line of the ouput file and some times all the lines at the server end.

Besides can you help me with the checks which you insist me to put in
socket.send() ?







> --**
> Notice that it tells you how many bytes have been sent, and it
> is your responsibility to check and retry if necessary.
> I see no check nor any attempt to retry
>
> That should tell you if the data is leaving the client at least.
>
>
>
>  SERVER.PY
>> import socket
>>
>> host = ""
>> port = 2
>> size = 1024
>> backlog=5
>> s=socket.socket(socket.AF_**INET, socket.SOCK_STREAM)
>>
>> s.bind((host,port))
>> s.listen(backlog)
>>
>> while 1:
>> client, addr =s.accept()
>> data=client.recv(size)
>> if data:
>> print data
>> else:
>> print  "client exit"
>>
>
> This implies you should always get something printed, do you?
> When you say it sometimes prints the lines and sometimes
> not, does it print the exit message instead?
>
>  s.close()
>>
>
> I'm not clear where this line sits since the mail has lost
> its indentation. Is it inside the else or at the while level?
>
> Just some things to c0onsider,
>
> HTH
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>



-- 
Regards
Aditya
reply from 192.168.100.1
reply from 192.168.100.7


client.py
Description: Binary data


server.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 83

2011-06-21 Thread arun kumar
g
> to point out to the OP was that Google would've likely yielded many
> relevant
> results, including in all likelihood the top hit, notwithstanding Google's
> tailoring based on location and other factors.  (You're not seriously
> trying
> to suggest that Google would've yielded *no* useful results, or that the
> top
> link wouldn't have been at all relevant to his question, are you?)
>
> For reference, for me the top hit is http://www.xhtml2pdf.com/ which does
> indeed look like it might do the job (and is a pure python solution.)
>
> Another possibly quite relevant link is this one (about 20 lines of code):
>
> http://www.linux.com/learn/docs/ldp/284676-converting-html-to-pdf-using-python-and-qt
>
> Cheers
>
> Walter
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20110620/3aa076cd/attachment-0001.html
> >
>
> --
>
> Message: 4
> Date: Tue, 21 Jun 2011 00:29:27 +0200
> From: Michiel Overtoom 
> To: tutor@python.org
> Subject: Re: [Tutor] html files to pdf document
> Message-ID: <994b3638-cd1e-449d-86ae-29a2af041...@xs4all.nl>
> Content-Type: text/plain; charset=us-ascii
>
>
> On Jun 21, 2011, at 00:19, Walter Prins wrote:
>
> > For reference, for me the top hit is http://www.xhtml2pdf.com/ which
> does indeed look like it might do the job (and is a pure python solution.)
>
> I get five SERP pages with tons of Stackoverflow hits, but not one for
> www.xhtml2pdf.com!  I think this is what is known as an Internet Search
> Bubble.
>
>
> > Another possibly quite relevant link is this one (about 20 lines of
> code):
> http://www.linux.com/learn/docs/ldp/284676-converting-html-to-pdf-using-python-and-qt
>
> Thank you for posting the links.
>
> Greetings,
>
> --
> "If you don't know, the thing to do is not to get scared, but to learn." -
> Ayn Rand
>
> Hi Micheal,
>
Thanks for the suggestion but  my  desktop environment  is not qt. Its
gnome. And i'm looking for some pure python way. www.xhtml2pdf is buggy and
i had problems installing that library

Thanks

Arun Kumar

>
>
>
> --
>
> Message: 5
> Date: Tue, 21 Jun 2011 11:11:51 +0530
> From: aditya 
> To: tutor@python.org
> Subject: [Tutor] Socket Programming issue
> Message-ID: 
> Content-Type: text/plain; charset="iso-8859-1"
>
> This is a small client-server program in which i am using a Vbscript
> program
> to check for connectivity of 2 machines and write the output to a text file
> whether it connectes or not ,
>
>
> for example the contents of the file *output.txt* are
>
> 192.168.1.2 is connected
> 192.168.1.10 is not connected
>
>
> Now i am trying to send the contents of this file from a client through a
> socket to a server which is running on my main server .This is basically
> created to automate the checking of connectivity of the machines. The issue
> is that although the Vbscript writes the output to the file correctly but
> when the client sends the contents of the file to the server via socket ,
> it
> sometimes prints all the lines of the file on the server and sometimes it
> doesnt , i dont know whether the issue is with the client or the server ,
> Please Help..
>
>
> CLIENT.PY
>
> import socket
> import os
> import sys
> os.system("C:\Python26\ping.vbs")
> host = "localhost"
> port= 2
> size = 1024
>
> s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((host,port))
>
>
>
>
> f=open('output.txt','r')
> while 1:
> data = f.readline()
> if data: s.send(data)
>  else: break
>
>
>
> f.close()
>
> s.close()
>
>
>
> SERVER.PY
>
>
> import socket
>
> host = ""
> port = 2
> size = 1024
> backlog=5
> s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> s.bind((host,port))
> s.listen(backlog)
>
> while 1:
> client, addr =s.accept()
> data=client.recv(size)
> if data:
> print data
>
> else:
> print  "client exit"
>
> s.close()
>
>
>
>
>
>
>
>
>
> --
> Regards
> Aditya
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20110621/b2cd975c/attachment-0001.html
> >
>
> --
>
> Message: 6
> Date: Tue, 21 Jun 2011 08:15:55 +0100
> From: "Alan Gauld" 
> To: tutor@python.org
> Subject: Re: [Tutor] Socket Programming issu

[Tutor] Using class methods

2011-06-21 Thread David Merrick
I need help using Class methods in another class. I have a class called
Critter and I want to create two critters in a farm  Class Farm and use
Class Critter's methods

# A virtual pet to care for
class Critter(object):

"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom

# __ denotes private method
def __pass_time(self,farm):
self.hunger += 1
self.boredom += 1
self.__str__()

def __str__(self,farmlet):
print("Hunger is",self.hunger, "Boredom is " ,self.boredom)
print("Unhappines is ",self.hunger + self.boredom," and Mood is
",self.mood)



@property
def mood(self):
unhappiness = self.hunger + self.boredom
if unhappiness < 5:
m = "happy"
elif 5 <= unhappiness <= 10:
m = "okay"
elif 11 <= unhappiness <= 15:
m = "frustrated"
else:
m = "mad"
return m

def talk(self):
print("I'm", self.name, "and I feel", self.mood, "now.\n")
self.__pass_time()


def eat(self):
food = int(input("Enter how much food you want to feed your critter:
"))
print("Brruppp.  Thank you.")
self.hunger -= food
# hunger = 0 at iniatition
# self.hunger = self.boredom - food
if self.hunger < 0:
self.hunger = 0
self.__pass_time()


def play(self):
fun = int(input("Enter how much fun you want your critter to have:
"))
print("Wheee!")
self.boredom -= fun
# boredom = 0 at iniatition
# self.boredom = self.boredom - fun
if self.boredom < 0:
self.boredom = 0
self.__pass_time()

class Farm(Critter,hunger = 0,boredom = 0):
#A collection of Critters

def __init__(farmlet, name):
for critter in farmlet:
critter.name = name
critter.hunger = hunger
critter.boredom = boredom

def talk(self,farmlet):
  for critter in farmlet:
print(self,farmlet)

def __str__(farmlet):
for critter in farmlet:
  print("Hunger is",critter.hunger, "Boredom is " ,critter.boredom)
  print("Unhappines is ",critter.hunger + critter.boredom," and Mood
is ",critter.mood)

def eat(farmlet):
for critter in farmlet:
food = int(input("Enter how much food you want to feed your
critter: "))
print("Brruppp.  Thank you.")
farmlet.hunger -= food
# hunger = 0 at iniatition
# self.hunger = self.boredom - food
if farmlet.hunger < 0:
farmlet.hunger = 0
farmlet.__pass_time()

def main():
##crit_name = input("What do you want to name your critter?: ")
##crit = Critter(crit_name)
crit1 = Critter("Sweetie")
crit2 = Critter("Dave")
farmlet = [crit1,crit2]
farmlet.hunger = 0
farmlet.boredom = 0
farm = Farm.__str__(farmlet)


choice = None
while choice != "0":
print \
("""
Critter Caretaker

0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter
""")

choice = input("Choice: ")
print()

# exit
if choice == "0":
print("Good-bye.")

# listen to your critter
elif choice == "1":
farm = Farm.__str__(farmlet)

# feed your critter
elif choice == "2":
farm = Farm.eat(farmlet)

# play with your critter
elif choice == "3":
farm.play(farmlet)

# some unknown choice
else:
print("\nSorry, but", choice, "isn't a valid choice.")





main()
("\n\nPress the enter key to exit.")


-- 
Dave Merrick

merrick...@gmail.com

Ph   03 3423 121
Cell 027 3089 169
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using Class methods

2011-06-21 Thread David Merrick
I need help using Class methods in another class. I have a class called
Critter and I want to create two critters in a farm  Class Farm and use
Class Critter's methods

-- 
Dave Merrick

merrick...@gmail.com

Ph   03 3423 121
Cell 027 3089 169


critter_farm2.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using class methods

2011-06-21 Thread Andre Engels
On Tue, Jun 21, 2011 at 10:12 AM, David Merrick  wrote:
> I need help using Class methods in another class. I have a class called
> Critter and I want to create two critters in a farm  Class Farm and use
> Class Critter's methods

Could you please specify where your current code does not suffice -
where does it something different than you want, or where do you want
to do something (and why) that you don't know how to do?

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Class methods

2011-06-21 Thread col speed
and?

On 21 June 2011 14:38, David Merrick  wrote:

> I need help using Class methods in another class. I have a class called
> Critter and I want to create two critters in a farm  Class Farm and use
> Class Critter's methods
>
> --
> Dave Merrick
>
> merrick...@gmail.com
>
> Ph   03 3423 121
> Cell 027 3089 169
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using class methods

2011-06-21 Thread Christopher King
Well it depends what you mean. If you have a critter object and want
to invoke its method inside the farm, do somethinh like this.
class Farm_class(object):
  def feed(self, critter):
critter.eat(self.food)

or if you want to use a method of the Critter class within the farm do

class Farm_class(object):
  def count(self):
print Critter_class.count()

On Tuesday, June 21, 2011, Andre Engels  wrote:
> On Tue, Jun 21, 2011 at 10:12 AM, David Merrick  wrote:
>> I need help using Class methods in another class. I have a class called
>> Critter and I want to create two critters in a farm  Class Farm and use
>> Class Critter's methods
>
> Could you please specify where your current code does not suffice -
> where does it something different than you want, or where do you want
> to do something (and why) that you don't know how to do?
>
> --
> André Engels, andreeng...@gmail.com
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Class methods

2011-06-21 Thread Alan Gauld


"David Merrick"  wrote

I need help using Class methods in another class. I have a class 
called
Critter and I want to create two critters in a farm  Class Farm and 
use

Class Critter's methods


Ok, You seem to be a bit confused by OOP, and
your code is using all sorts of features you probably
shouldn't be messing with yet.

Let's start with your main() method:

def main():
   crit1 = Critter("Sweetie")
   crit2 = Critter("Dave")
   farmlet = [crit1,crit2]

So far so good.

   farmlet.hunger = 0
   farmlet.boredom = 0

But here you are trying to access hunger and boredom
attributes of a list(farmlet) which doesn't have those
attributes. They are supposed to be part of your Farm
class. But you haven't got a Farm yet so you can't access
its attributes.

   farm = Farm.__str__(farmlet)

Now you assign the string representation of a Farm
to farm, but again you have no Farm object. And its
highly unusual to pass attributes to a __str__ method!
In fact its likely to cause serious problems if you ever
try to print the Farm!

So what about those attributes? Now we come to the
next problem, let's look at the class definition:

class Farm(Critter,hunger = 0,boredom = 0):

I have no idea where you got that syntax, but its wrong.
The parentheses in a class definition contain the list of
super classes from which you are inheriting.
A Farm is not a type of Critter, it has a collection of them.
And you cannot define attributes there, you need
to do that in the class body (for class level atrtributes),
or in the init method (for instance level attributes).

of critters...

   def __init__(farmlet, name):

A method needs to take the instance placeholder
variable - usually called self - as its first attribute.

If we add a self this implies that you need to create
a Farm with:

f = Farm(aFarmlet, aName)

But you never actually creaate a Farm object in your code...

   for critter in farmlet:
   critter.name = name
   critter.hunger = hunger
   critter.boredom = boredom

This bit would be OK except all the critters would have
the same name, hunger and boredom, which seems
unlikely? Especially since you gave them different
names when you created them(see above).

There are plenty other anomolies I could highlight but
as I say, I think you need to go back to first principles
and try again. This time forget about using properties,
and don't create any __xxx__ methods yet,
(except __init__!) - they just confuse things at this stage.

I would suggest you strip it right back to just defining
the two classes and their init methods to initialise the
data, nothing else.

Your basic logic is then to create some critters - which you
do already. Then create a Farm, passing the list of
critters into it. Then print out the farm's list to check
they are in there. Once you have done that add the
__str__ methods to aid printing. Once that works you
can start to think about addig the game logic and
supporting methods. But get the basics right first.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html files to pdf document

2011-06-21 Thread Walter Prins
On 20 June 2011 23:29, Michiel Overtoom  wrote:

>
> On Jun 21, 2011, at 00:19, Walter Prins wrote:
>
> > For reference, for me the top hit is http://www.xhtml2pdf.com/ which
> does indeed look like it might do the job (and is a pure python solution.)
>
> I get five SERP pages with tons of Stackoverflow hits, but not one for
> www.xhtml2pdf.com!  I think this is what is known as an Internet Search
> Bubble.
>

I also get the SERP pages if I include the quotes in the search.  Try the
search without the quotes.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html files to pdf document

2011-06-21 Thread Walter Prins
On 20 June 2011 23:29, Michiel Overtoom  wrote:

>
> On Jun 21, 2011, at 00:19, Walter Prins wrote:
>
> > For reference, for me the top hit is http://www.xhtml2pdf.com/ which
> does indeed look like it might do the job (and is a pure python solution.)
>
> I get five SERP pages with tons of Stackoverflow hits, but not one for
> www.xhtml2pdf.com!  I think this is what is known as an Internet Search
> Bubble.
>
>
Sorry, I mean to say, I also get SERP pages with as you put it tons of
Stackoverflow hits (and not www.xhtml2pdf.com) but this is because the
phrase as quoted does not appear on www.xxhtml2pdf.com obviously.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using class methods

2011-06-21 Thread Alan Gauld


"Christopher King"  wrote


class Farm_class(object):

...
or if you want to use a method of the Critter class within the farm 
do


class Farm_class(object):


But please do NOT add '_class' to the end of your class names!
The fact that it has a capital letter at the front combined with 
context

should be enough of a clue. Otherwise we'll all wind up doing things
like:

x_int = 2
y_int = 4
answer_string = str(x_int+y_int)

Eek, please, no! :-)

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 83

2011-06-21 Thread Alan Gauld

PLEASE PAY ATTENTION TO THE INSTRUCTIONS:


When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


AND please edit the contents so we don't need
to scroll through the whole digest to find your
comments!

Thanks for the suggestion but  my  desktop environment  is not qt. 
Its
gnome. And i'm looking for some pure python way. www.xhtml2pdf is 
buggy and

i had problems installing that library


Then you have some choices:

1) Fix the xhtml2pdf bugs for everyone's benefit
2) Use the code as a template for your own solution.
3) Spend more time on Google to find another solution.
4) Switch to qt or integrate qt with your desktop.
5) Figure out how to do it from scratch

Once you have decided your best approach come back
with any specific issues.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 83

2011-06-21 Thread Walter Prins
Hi Arun,

On 21 June 2011 08:56, arun kumar  wrote:

> yes i did a Google search but  did find anything useful. The xhtml2pdf is
> buggy in i'm unable to install it. Also mailed the community of  xhtml2pdf
> but didn't receive any reply from  them.
>

OK, firstly I'm no expect on xhtml2pdf, but not being able to install it
does not neccesarily mean that it's buggy...  It might (I suspect) be
something to do with your environment or with what you're doing.  Exactly
what errors did you get?

Out of curiosity, I just installed it on my Ubuntu box, by issuing:

sudo pip install xhtml2pdf

It apparently installed successfully.  (You would only be able to follow
this command if a) you're using Ubuntu, b) you have "pip" installed in your
Python environment.  If you don't know what "pip" is or why it's useful then
either post back and ask, or better yet, first do your own research and then
post if you still have questions and don't understand.)

Thanks for the suggestion but  my  desktop environment  is not qt. Its
> gnome.
>

QT is not a desktop environment, it's a cross application framework, primary
feature of which is its platform independent widget set.  Therefore your
desktop environment is actually irrelevant w.r.t. whether or not you use QT
in your solution.  In other words: You can install QT and run QT
applications on your Gnome desktop.  (Or on pretty much any other platform
where QT is available.)

On Debian based desktops using Gnome (like Ubuntu), the following command
(untested) should pull in QT4 and all the dependencies, together with the
Python wrappers, to allow you to try out the QT PDF suggestion.

apt-get install python-qt4

As an aside, it (QT4) was already installed on my Ubuntu installation, I
don't know if that's because at some point I installed an app that required
it or whether it's because it was installed by default.

Regards,

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 83

2011-06-21 Thread Walter Prins
Hi again Arun,

On 21 June 2011 19:59, Walter Prins  wrote:

> It apparently installed successfully.  (You would only be able to follow
> this command if a) you're using Ubuntu, b) you have "pip" installed in your
> Python environment.  If you don't know what "pip" is or why it's useful then
> either post back and ask, or better yet, first do your own research and then
> post if you still have questions and don't understand.)
>

Out of curiosity I just did a quick followup experiment with xhtml2pdf after
installing it:

1) I read the documentation page here:
http://www.xhtml2pdf.com/doc/pisa-en.html
2) Then I saved the page to my desktop as "pisa Documentation.html" (the
default filename)
3) Then I issued (as suggested in the documentation) the command:
 xhtml2pdf -s "pisa Documentation.html"
4) xhtml2pdf then spat out some messages and generated "pisa
Documentation.pdf"

The result is (I think) pretty good.   I must note that I've not encountered
any real problems so far either installing it or using it, so I must
conclude that whatever installation issues you ran into was due to something
specific to your current platform, or to something you've done, and not due
to bugs in xhtml2pdf as you suggested.  (In fact the results are so good
that I'm planning on playing around with this in Python a bit more myself...
might come in very handy for generating reports and suchlike at some point
no doubt...)

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 86

2011-06-21 Thread David Merrick
I have created a Critter object and a Farm object which is two critters. I
want to use Critters methods in the Farm object as it just 2 critters in a
list

crit1 = Critter("Sweetie")
crit2 = Critter("Dave")
farmlet = [crit1,crit2]

# Critter  Caretaker
> # A virtual pet to care for
> class Critter(object):
>
> """A virtual pet"""
> def __init__(self, name, hunger = 0, boredom = 0):
> self.name = name
> self.hunger = hunger
> self.boredom = boredom
>
> # __ denotes private method
> def __pass_time(self,farm):
> self.hunger += 1
> self.boredom += 1
> self.__str__()
>
> def __str__(self,farmlet):
> print("Hunger is",self.hunger, "Boredom is " ,self.boredom)
> print("Unhappines is ",self.hunger + self.boredom," and Mood is
> ",self.mood)
>
>
>
> @property
> def mood(self):
> unhappiness = self.hunger + self.boredom
> if unhappiness < 5:
> m = "happy"
> elif 5 <= unhappiness <= 10:
> m = "okay"
> elif 11 <= unhappiness <= 15:
> m = "frustrated"
> else:
> m = "mad"
> return m
>
> def talk(self):
> print("I'm", self.name, "and I feel", self.mood, "now.\n")
> self.__pass_time()
>
>
> def eat(self):
> food = int(input("Enter how much food you want to feed your
> critter: "))
> print("Brruppp.  Thank you.")
> self.hunger -= food
> # hunger = 0 at iniatition
> # self.hunger = self.boredom - food
> if self.hunger < 0:
> self.hunger = 0
> self.__pass_time()
>
>
> def play(self):
> fun = int(input("Enter how much fun you want your critter to have:
> "))
> print("Wheee!")
> self.boredom -= fun
> # boredom = 0 at iniatition
> # self.boredom = self.boredom - fun
> if self.boredom < 0:
> self.boredom = 0
> self.__pass_time()
>
> class Farm(Critter,hunger = 0,boredom = 0):
> #A collection of Critters
>
> def __init__(farmlet, name):
> for critter in farmlet:
> critter.name = name
> critter.hunger = hunger
> critter.boredom = boredom
>
> def talk(self,farmlet):
>   for critter in farmlet:
> print(self,farmlet)
>
> def __str__(farmlet):
> for critter in farmlet:
>   print("Hunger is",critter.hunger, "Boredom is " ,critter.boredom)
>   print("Unhappines is ",critter.hunger + critter.boredom," and
> Mood is ",critter.mood)
>
> def eat(farmlet):
> for critter in farmlet:
> food = int(input("Enter how much food you want to feed your
> critter: "))
> print("Brruppp.  Thank you.")
> farmlet.hunger -= food
> # hunger = 0 at iniatition
> # self.hunger = self.boredom - food
> if farmlet.hunger < 0:
> farmlet.hunger = 0
> farmlet.__pass_time()
>
> def main():
> ##crit_name = input("What do you want to name your critter?: ")
> ##crit = Critter(crit_name)
> crit1 = Critter("Sweetie")
> crit2 = Critter("Dave")
> farmlet = [crit1,crit2]
> farmlet.hunger = 0
> farmlet.boredom = 0
> farm = Farm.__str__(farmlet)
>
>
> choice = None
> while choice != "0":
> print \
> ("""
> Critter Caretaker
>
> 0 - Quit
> 1 - Listen to your critter
> 2 - Feed your critter
> 3 - Play with your critter
> """)
>
> choice = input("Choice: ")
> print()
>
> # exit
> if choice == "0":
> print("Good-bye.")
>
> # listen to your critter
> elif choice == "1":
> farm = Farm.__str__(farmlet)
>
> # feed your critter
> elif choice == "2":
> farm = Farm.eat(farmlet)
>
> # play with your critter
> elif choice == "3":
> farm.play(farmlet)
>
> # some unknown choice
> else:
> print("\nSorry, but", choice, "isn't a valid choice.")
>
>
>
>
>
> main()
> ("\n\nPress the enter key to exit.")
>



>
>
> Well it depends what you mean. If you have a critter object and want
> to invoke its method inside the farm, do somethinh like this.
> class Farm_class(object):
>  def feed(self, critter):
>critter.eat(self.food)
>
> or if you want to use a method of the Critter class within the farm do
>
> class Farm_class(object):
>  def count(self):
>print Critter_class.count()
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 88, Issue 86

2011-06-21 Thread Alan Gauld


"David Merrick"  wrote

I have created a Critter object and a Farm object which is two 
critters. I
want to use Critters methods in the Farm object as it just 2 
critters in a

list

crit1 = Critter("Sweetie")
crit2 = Critter("Dave")
farmlet = [crit1,crit2]



This creates two critters but it does not create a Farm object,
it only creates a list of two critters. (That might be all you need!
Maybe you don't need a Farm class)

So to call the talk() method of crit1 via the farmlet list:

farmlet[0].talk()

Or for all the critters in the farmlet:

for critter in farmlet:
critter.talk()

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket Programming issue

2011-06-21 Thread Mark Tolonen


"aditya"  wrote in message 
news:BANLkTikS+gzm=89thczpbwksd+wufec...@mail.gmail.com...
This is a small client-server program in which i am using a Vbscript 
program
to check for connectivity of 2 machines and write the output to a text 
file

whether it connectes or not ,


for example the contents of the file *output.txt* are

192.168.1.2 is connected
192.168.1.10 is not connected


Now i am trying to send the contents of this file from a client through a
socket to a server which is running on my main server .This is basically
created to automate the checking of connectivity of the machines. The 
issue

is that although the Vbscript writes the output to the file correctly but
when the client sends the contents of the file to the server via socket , 
it

sometimes prints all the lines of the file on the server and sometimes it
doesnt , i dont know whether the issue is with the client or the server ,
Please Help..


CLIENT.PY

import socket
import os
import sys
os.system("C:\Python26\ping.vbs")
host = "localhost"
port= 2
size = 1024

s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))




f=open('output.txt','r')
while 1:
data = f.readline()
if data: s.send(data)
else: break




Use "s.sendall(data)" instead of send to correct the error Alan pointed out.







f.close()

s.close()



SERVER.PY


import socket

host = ""
port = 2
size = 1024
backlog=5
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((host,port))
s.listen(backlog)




s.accept() should be before the while loop, then loop on recv until the 
client closes the connection.  Since TCP is a streaming protocol, recv() 
could receive less than a line or more than one line at once, but with the 
accept inside the loop the script will pause waiting for a different client 
to connect, and won't continue reading the data from the original client.


-Mark





while 1:
client, addr =s.accept()
data=client.recv(size)
if data:
print data

else:
print  "client exit"

s.close()









--
Regards
Aditya








___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Class methods

2011-06-21 Thread David Merrick
# Critter Caretaker
# A virtual pet to care for

class Critter(object):

"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom

# __ denotes private method
def __pass_time(self):
self.hunger += 1
self.boredom += 1
self.__str__()

def __str__(self):
print("Hunger is",self.hunger, "Boredom is " ,self.boredom)
print("Unhappines is ",self.hunger + self.boredom," and Mood is
",self.mood)



@property
def mood(self):
unhappiness = self.hunger + self.boredom
if unhappiness < 5:
m = "happy"
elif 5 <= unhappiness <= 10:
m = "okay"
elif 11 <= unhappiness <= 15:
m = "frustrated"
else:
m = "mad"
return m

def talk(self):
print("I'm", self.name, "and I feel", self.mood, "now.\n")
self.__pass_time()


def eat(self):
food = int(input("Enter how much food you want to feed your critter:
"))
print("Brruppp.  Thank you.")
self.hunger -= food
# hunger = 0 at iniatition
# self.hunger = self.boredom - food
if self.hunger < 0:
self.hunger = 0
self.__pass_time()


def play(self):
fun = int(input("Enter how much fun you want your critter to have:
"))
print("Wheee!")
self.boredom -= fun
# boredom = 0 at iniatition
# self.boredom = self.boredom - fun
if self.boredom < 0:
self.boredom = 0
self.__pass_time()


class Farm(Critter):
def __init__(self,farmlet):
   Critter.__init__(self,farmlet)
   self.farmlet = farmlet

def talk(self,farmlet):
for critter in farmlet:
print("Hello")
Critter.talk(farmlet)

def main():
crit1 = Critter("Sweetie")
crit2 = Critter("Dave")
farmlet = [crit1,crit2]
f = Farm(farmlet)

choice = None
while choice != "0":
print \
("""
Critter Caretaker

0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter
""")

choice = input("Choice: ")
print()

# exit
if choice == "0":
print("Good-bye.")

# listen to your critter
elif choice == "1":
f.talk(farmlet)

# feed your critter
elif choice == "2":
f.eat(farmlet)

# play with your critter
elif choice == "3":
f.play(farmlet)

# some unknown choice
else:
print("\nSorry, but", choice, "isn't a valid choice.")

main()
("\n\nPress the enter key to exit.")

*OUTPUT*

 Critter Caretaker

0 - Quit
1 - Listen to your critter
2 - Feed your critter
3 - Play with your critter

Choice: 1

Hello
Traceback (most recent call last):
  File "D:/David/Python/programs/critter_farm3.py", line 115, in 
main()
  File "D:/David/Python/programs/critter_farm3.py", line 101, in main
f.talk(farmlet)
  File "D:/David/Python/programs/critter_farm3.py", line 72, in talk
Critter.talk(farmlet)
  File "D:/David/Python/programs/critter_farm3.py", line 38, in talk
print("I'm", self.name, "and I feel", self.mood, "now.\n")
AttributeError: 'list' object has no attribute 'name'

I am trying to access Crit1 and Crit2 namr in farmlet
-- 
Dave Merrick

merrick...@gmail.com

Ph   03 3423 121
Cell 027 3089 169
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sftp get single file

2011-06-21 Thread Johan Geldenhuys
Hi all,
This topic is old, but I have a similar issue and I know everybody will say I 
should use piramiko, but it is not that simple.

The device I have to run my python scripts on is a simple, small, scaled down 
version of Suse linux and I can't install other packages like piramiko.
All the files I need to use that is not part of Python 2.7 must be included in 
my package.

With the above in mind, what can I use to open SFTP to a server and transfer a 
file?

Thanks

Johan


-Original Message-
From: tutor-bounces+johan=accesstel.com...@python.org 
[mailto:tutor-bounces+johan=accesstel.com...@python.org] On Behalf Of Sander 
Sweers
Sent: Saturday, 18 July 2009 1:43 AM
To: Matt Herzog
Cc: Python List
Subject: Re: [Tutor] sftp get single file

2009/7/17 Matt Herzog :
> Hello All.
>
> I need to use paramiko to sftp get a single file from a remote server.
> The remote file's base name will be today's date (%Y%m%d) dot tab.
> I need help joining the today with the .tab extension. Do I need globbing?
>
> example: 20090716.tab
>
> #!/usr/bin/env python
> import paramiko
> import glob
> import os
> import time
> hostname = 'sftp.booboo.com'
> port = 22
> username = 'booboo'
> password = '07N4219?'
> # glob_pattern='*.tab'
> today = time.strftime("%Y%m%d")
> remotepath = today.tab
> localpath = '/home/data/text'
>
> if __name__ == "__main__":
>t = paramiko.Transport((hostname, port))
>t.connect(username=username, password=password)
>sftp = paramiko.SFTPClient.from_transport(t)
>sftp.get(remotepath, localpath)
>t.close()
> --

You don't need glob if you know in advance what the filename is. Print
example below.

---
import time

today = time.localtime()
datestr = time.strftime("%Y%m%d",today)
ext = ".tab"

print datestr + ext
---

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

Checked by AVG - www.avg.com 
Version: 8.5.387 / Virus Database: 270.13.17/2242 - Release Date: 07/16/09 
18:00:00

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor