Showing results 1 to 40 of 299
Search took 0.04 seconds; generated 1 minute(s) ago.
Posts Made By: Gribouillis
Forum: Python 2 Days Ago
Replies: 3
Views: 61
Posted By Gribouillis
Re: UnboundLocalError

The local namespace of a method doesnt see the namespace of the class. Inside a method, you can only access the variables from the local namespace and the variables defined at module level. So your...
Forum: Python 2 Days Ago
Replies: 6
Views: 119
Posted By Gribouillis
Re: Regular expressions

It's because the items in root.getchildren are not strings but Element objects. You could replace the end of your program with

root= tree.getroot()
text = root.getchildren()
expr =...
Forum: Python 3 Days Ago
Replies: 30
Views: 1,070
Posted By Gribouillis
Re: Python and Linux

answer = raw_input('What is your id?')
Forum: Python 3 Days Ago
Replies: 6
Views: 119
Posted By Gribouillis
Re: Regular expressions

Well, in the regular expression language, the string "<Element ([^\s]+)" means the character < followed by the character E ... followed by t followed by a single space followed by a group (...)...
Forum: Python 3 Days Ago
Replies: 6
Views: 119
Posted By Gribouillis
Re: Regular expressions

Here is a way

import re

data = """
<Element Generation at d66238>
<Element Vitals at d662b0>
<Element Network at d66670>
<Element Hardware at d66eb8>
<Element Memory at d6ac88>
Forum: Python 4 Days Ago
Replies: 0
Views: 100
Posted By Gribouillis
Downloading thread code.

The following program is able to download the python programs contained in a thread of the python forum. Just start the program, it will prompt you for the thread number and create a directory with...
Forum: Python 8 Days Ago
Replies: 17
Views: 364
Posted By Gribouillis
Re: Computer picks a random word and player has to guess it.

For a french version of the game, this site http://www.pallier.org/ressources/dicofr/dicofr.html gives a text file of 336531 french words :)
Forum: Python 9 Days Ago
Replies: 17
Views: 364
Posted By Gribouillis
Re: Computer picks a random word and player has to guess it.

Here is a random word generator for this dictionary file

from os.path import getsize
from random import randint

dic_path ="DictionaryE.txt"
file_size =getsize (dic_path )
file_in =open (dic_path...
Forum: Python 10 Days Ago
Replies: 9
Views: 271
Posted By Gribouillis
Re: wxTreeCtrl - Load Tree structure from file

Sorry, there is a syntax error in the code above. You should replace

@staticmethod readCtrl(ctrl):

by

@staticmethod
def readCtrl(ctrl):

However, since the code is untested, it's most...
Forum: Python 10 Days Ago
Replies: 2
Views: 151
Posted By Gribouillis
Re: Python Counterpart?

I would say the pickle or shelve modules :) ... I found this with google, which might be interesting http://www.evilchuck.com/2008/02/tell-python-to-shove-it.html
Forum: Python 10 Days Ago
Replies: 9
Views: 271
Posted By Gribouillis
Re: wxTreeCtrl - Load Tree structure from file

I would suggest something like this, with the pickle module (completely untested)


import pickle

class Tree(object):
# a tree class, with a single root (a Node object)
def __init__(self):
...
Forum: Python 10 Days Ago
Replies: 4
Views: 209
Posted By Gribouillis
Re: Reading XML data

I suggest a generator

def find_text(element):
if element.text is None:
for subelement in element:
for txt in find_text(subelement):
yield txt
else:
...
Forum: Python 10 Days Ago
Replies: 2
Views: 107
Posted By Gribouillis
Re: Python Newbie is frustrated

Here is how you could do this

import random
result = 0
while True: # means forever
roll = random.randint(1, 10)
result += roll
if roll != 10:
break
print result
Forum: Python 12 Days Ago
Replies: 1
Views: 185
Posted By Gribouillis
Re: Parsing in Python

A nice module is ply which has the functionality of the lex and yacc tools but with a pure python implementation. It might not be the fastest parser in python, but I think it's a very good starting...
Forum: Python 13 Days Ago
Replies: 3
Views: 160
Posted By Gribouillis
Re: executing scripts via command line

The syntax error is somewhere in your script. Can you post the script (or attach it) ?
Forum: Python 25 Days Ago
Replies: 2
Views: 132
Posted By Gribouillis
Re: List Index Question

this way

mylist = ["whatever"] * 100
Forum: Python 28 Days Ago
Replies: 30
Views: 1,070
Posted By Gribouillis
Re: Python and Linux

Assuming theOutput is a string, you could write

if theOutput == "10.0.0.2":
print("correct")
else:
print("incorrect")
Forum: Python 28 Days Ago
Replies: 1
Views: 107
Posted By Gribouillis
Re: help!

There is a full course on biopython from the Pasteur institute which includes reading Fasta format http://www.pasteur.fr/recherche/unites/sis/formation/python/ch11s03.html#exa_seq_string
I think you...
Forum: Python 29 Days Ago
Replies: 40
Views: 829
Posted By Gribouillis
Re: Text games are frustrating!

I cleaned up your code a while. Here is a code that runs. Compare the details with your version to understand how it works.

#!/usr/bin/env python

import random

class monster(object):
def...
Forum: Python 29 Days Ago
Replies: 40
Views: 829
Posted By Gribouillis
Re: Text games are frustrating!

Also, your methods getAttribute info in troll and orc return None instead of what they should return. You shoud write

def getAttributeInfo(self):
return monster.getAttributeInfo(self)
Forum: Python 29 Days Ago
Replies: 40
Views: 829
Posted By Gribouillis
Re: Text games are frustrating!

You must not call sword.getAttributeInfo2() because sword is a class and getAttributeInfo2 is an instance method. It applies to an instance (an object). Here, your sword object is self.weapon, so you...
Forum: Python 29 Days Ago
Replies: 30
Views: 1,070
Posted By Gribouillis
Re: Python and Linux

Instead of printing the repr of the string you can write

print("> theOutput was")
print (theOutput)

the % is a string formatting operation.
Forum: Python 29 Days Ago
Replies: 30
Views: 1,070
Posted By Gribouillis
Re: Python and Linux

Here is a complete example:

# FILE fooo.py
import sys
s = sys.stdin.read()
print s.upper()
raise Exception

# FILE bar.py
import subprocess as SP
Forum: Python 29 Days Ago
Replies: 30
Views: 1,070
Posted By Gribouillis
Re: Python and Linux

communicate reads data from the subprocess stdout and stderr. It returns a pair of strings, so output = p2.communicate()[0] means wait until the child process is done and read the output which it...
Forum: Python 29 Days Ago
Replies: 40
Views: 829
Posted By Gribouillis
Re: Text games are frustrating!

If you want to test code, I gave an example of how you could do this with doctest, here http://www.daniweb.com/forums/thread146672.html
Programming with tests is a very efficient method.
Forum: Python 30 Days Ago
Replies: 40
Views: 829
Posted By Gribouillis
Re: Text games are frustrating!

An alternative to changing the method's name is this

class Troll(Monster):
def getAttributesInfo(self):
Monster.getAttributesInfo(self)

It's a standard way of overloading a method in...
Forum: Python 30 Days Ago
Replies: 9
Views: 222
Posted By Gribouillis
Re: Opening a file

You say it doesn't open, but in that case there must be an exception traceback. What is the exception traceback ?
Forum: Python 31 Days Ago
Replies: 7
Views: 369
Posted By Gribouillis
Re: compare string from file

Here is a way

def createData2():
L = [line.strip() for line in open("data.txt")]
L = [line for line in L if line]
data2 = open("data2.txt", "w")
data2.write(" ".join(L))
...
Forum: Python 31 Days Ago
Replies: 6
Views: 434
Posted By Gribouillis
Re: Read number of pages in PDF files

I installed the program pdftk (on my linux distribution, it was a package). I think you can be interested in this little script

import os
from os.path import join as pjoin, expanduser
import...
Forum: Python 32 Days Ago
Replies: 10
Views: 378
Posted By Gribouillis
Re: must be called with orc instance as first argument (got nothing instead)!

If your method is written as def getAttributesInfo(self):, there is no error in the call new_monster.getAttributesInfo(). Also I remarked that you define your classes as class X():. The correct way...
Forum: Python 32 Days Ago
Replies: 10
Views: 378
Posted By Gribouillis
Re: must be called with orc instance as first argument (got nothing instead)!

you should call the method with the instance new_monster and not with the class (orc or troll)

def main():
monster_attacking = random.randrange(1,2)
if monster_attacking == 1:
...
Forum: Python 34 Days Ago
Replies: 4
Views: 197
Posted By Gribouillis
Re: Why Isn't This Working?

I would suggest lists like this

cnt_img = 15
E_Path = [os.path.join("data", "E%d.gif" % k) for k in xrange(cnt_img)]
E = [pygame.image.load(E_Path[k]) for k in xrange(cnt_img)]

Then you can use...
Forum: Python 34 Days Ago
Replies: 6
Views: 250
Posted By Gribouillis
Re: File I/O Problem: Incomplete or Missing Content During Writeline

Try this

for line ...
if other_date ...
...
more_logs = open(..., "w")
try:
new_log_data ...
for line_data ...
...
Forum: Python 34 Days Ago
Replies: 7
Views: 222
Posted By Gribouillis
Re: Superscribe and subscribe

Your question is not at all obvious. Where are you trying to write a superscript ? in a terminal ? a Tkinter canvas ? a printer ? a pdf document ? This is the main problem.
Forum: Python Oct 30th, 2008
Replies: 8
Views: 259
Posted By Gribouillis
Re: C to Python Translation anyone?

A word to word translation would go like this

def traverse(p):
if not p:
return
traverse(p.lokid)
if p.splitchar:
traverse(p.eqkid)
else:
print(p.eqkid)
Forum: Python Oct 30th, 2008
Replies: 2
Views: 120
Posted By Gribouillis
Re: Quick Question....

socket is a standard class in the socket module. You should use it if you want to create a socket. However it often happens that one writes functions to create new objects. These functions call the...
Forum: Python Oct 30th, 2008
Replies: 4
Views: 184
Posted By Gribouillis
Re: Strange list.append() results

The effect of list(dice) is the same as dice[:]: it returns a copy of the list. It's important to understand that python methods manipulate references to python objects. When you write dice =...
Forum: Python Oct 29th, 2008
Replies: 4
Views: 184
Posted By Gribouillis
Re: Strange list.append() results

There is nothing strange, the shuffle happens in place, so rolls contains 3 references to the same list. You should write rolls.append(list(dice)) if you want to keep the intermediary states of the...
Forum: Python Oct 29th, 2008
Replies: 4
Views: 243
Posted By Gribouillis
Re: Batch Processing

An easy way of communication is the pyro module. pyro stands for Python Remote Objects, it allows a process to register a python object in a name server and other processes to obtain proxies for the...
Forum: Python Oct 29th, 2008
Replies: 4
Views: 171
Posted By Gribouillis
Showing results 1 to 40 of 299

 
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:50 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC