Re: Newbie: Help Figger Out My Problem
On Tue, 28 Jun 2005 00:23:30 -0700, ChuckDubya wrote:
> ##Coin Flip: randomly flips 100 "coins" and prints results
> ##Original draft: june 27, 2005
> ##Chuck
>
> import random
> heads = 0
> tails = 0
> flips = 0
> while flips < 99:
> coin = random.randrange(0, 2)
> if coin == 0:
> heads = heads + 1
> else:
> tails = tails + 1
> flips = flips + 1
> if flips >= 99:
> print "Heads: " + heads
> print "Tails: " + tails
> print "Total: " + flips + "flips"
> raw_input("Press the enter key to exit.")
>
>
>
> When I save and run this "program", I get a DOS window that flashes at
> me and disappears. What's wrong with it?
Your programm gives an error. You are trying to concatenate strings with
integers.
http://docs.python.org/lib/typesseq-strings.html
import random
heads = 0
tails = 0
flips = 0
while flips < 99:
coin = random.randrange(0, 2)
if coin == 0:
heads = heads + 1
else:
tails = tails + 1
flips = flips + 1
if flips >= 99:
print "Heads: %s" % heads ## string formatting
print "Tails: %s" %tails ## string formatting
print "Total: %s flips" % flips ## string formatting
raw_input("Press the enter key to exit.")
hth Arjen
--
http://mail.python.org/mailman/listinfo/python-list
Re: Inheritance problem ?
On Wed, 24 Aug 2005 03:34:36 -0700, tooper wrote:
> Hello all,
>
> I'm trying to implement a common behavior for some object that can be
> read from a DB or (when out of network) from an XML extract of this DB.
> I've then wrote 2 classes, one reading from XML & the other from the
> DB, both inheritating from a common one where I want to implement
> several common methods.
> Doing this, I've come to some behaviour I can't explain to myself,
> which I've reproduced in the example bellow :
>
> -
>
> class myfather:
> def __repr__(self):
> return "\t a="+self.a+"\n\t b="+self.b
>
> class mychilda(myfather):
> def __init__(self,a):
> self.a= a
> def __getattr__(self,name):
> return "Undefined for mychilda"
>
> class mychildb(myfather):
> def __init__(self,b):
> self.b= b
> def __getattr__(self,name):
> return "Undefined for mychildb"
>
> a= mychilda("a")
> b= mychildb("b")
>
> print "a:\n"+str(a)
> print "b:\n"+str(b)
>
> -
>
> I was expecting to get :
>
> a:
>a= a
>b= Undefined for mychilda
> b:
>a= Undefined for mychildb
>b= b
>
> but I get the following error :
>
> File "/home/thierry/mytest.py", line 20, in ?
> print "a:\n"+str(a)
> TypeError: 'str' object is not callable
>
> Could someone explain me what I missed ?
>
> Thanks in advance !
try new style classes.
class myfather(object):
see http://users.rcn.com/python/download/Descriptor.htm
HTH Arjen
--
http://mail.python.org/mailman/listinfo/python-list
Re: Javadoc style python manual?
On Fri, 08 Sep 2006 01:11:06 -0700, xiong.xu.cn wrote: > Hi there, > > I'm new to python and I'm from the java world. > Though I love to learn python, I'm not very comfortable with the python > documentation. > Because when i read jdk doc, i can see the class hierachy, class > member, class methods etc in html docs. It's very easy for me to > understand the Java language. > But in python, i find it kind of inconvient. > > Any advice? > > Thx, > Xiong pydoc is something I know, it is included in the standard distibution -- http://mail.python.org/mailman/listinfo/python-list
Re: running commands with sudo & python
Hi there, I think you can do that with pexpect http://pexpect.sourceforge.net/ good luck On Thu, 28 Sep 2006 14:18:14 -0700, coldsoul4e wrote: > Hi! > I must execute a command with os.command(), but with root permissions. > Is there anyway to do that with python? > Thanks -- http://mail.python.org/mailman/listinfo/python-list
write html-headers (utf-8)
Hello all, I hope this is the correct newsgroup for this question. Does anybody know how I can write a html-header with python(cgi)? The problem is, I have a few html templates in which I have a header e.g: http://www.w3.org/TR/html4/strict.dtd";> In this template I write a few Mysql variables. Those variable often have german characters. This characters (Gösing in stead of Gösing). The german characters in the html template are shown correctly. If I change the character encoding with the browser to utf-8, all the characters are shown correctly. As you can see, I put in the header of the html template that the encoding is UTF-8, the browser still shows windows ISO-8859-15. Can I write the header with python so the browser uses the utf-8 encoding? My hosting providor uses fedora core 2, Python 2.2.3, MySQLdb. Mysql 3.23.58 I googled for hours, but I can't find the answer. I hope ypu can help me. Thanks in advance. Arjen -- http://mail.python.org/mailman/listinfo/python-list
Re: regarding cgi
I think you should give another header: Content-type: text/html regards Arjen On Tue, 14 Jun 2005 07:00:09 +0100, praba kar wrote: > Dear All, > > I have doubt regarding headers in cgi > programming. If I gives "Content-Type:text/plain" > then I try to print html contents. Is right or wrong > after giving content-type: text/plain? > > regards > Prabahar > > > > > ___ > Too much spam in your inbox? Yahoo! Mail gives you the best spam protection > for FREE! http://in.mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
How do I 'stat' online files?
I am working on a program that needs to stat files (gif, swf, xml, dirs, etc) from the web. I know how to stat a local file... import os tplStat = os.stat(path) but I can't figure out how to stat a file that resides on a web server. I am not sure if it makes a difference, but most (maybe all) of the files that I need to stat reside within the same domain that will generate the request. I am able to open the file by using import urllib f = urllib.urlopen(url) but for some reason I cannot stat the files. Any help will greatly be appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
